本文整理汇总了Python中dax.XnatUtils.upload_file_to_obj方法的典型用法代码示例。如果您正苦于以下问题:Python XnatUtils.upload_file_to_obj方法的具体用法?Python XnatUtils.upload_file_to_obj怎么用?Python XnatUtils.upload_file_to_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dax.XnatUtils
的用法示例。
在下文中一共展示了XnatUtils.upload_file_to_obj方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_converted_images
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_file_to_obj [as 别名]
def upload_converted_images(self, dcm_dir, scan_obj, scan_info):
"""upload the images after checking them."""
# Local variables
nifti_list = []
bval_fpath = ''
bvec_fpath = ''
# G et the bvec/bval files and NIFTI from the folder:
for fpath in glob.glob(os.path.join(dcm_dir, '*')):
if os.path.isfile(fpath):
if fpath.lower().endswith('.bval'):
bval_fpath = fpath
if fpath.lower().endswith('.bvec'):
bvec_fpath = fpath
if fpath.lower().endswith('.nii.gz'):
nifti_list.append(fpath)
if fpath.lower().endswith('.nii'):
os.system('gzip ' + fpath)
nifti_list.append(fpath + '.gz')
# Check NIFTI:
good_to_upload = self.check_outputs(scan_info, nifti_list,
bval_fpath, bvec_fpath)
# Upload files:
if good_to_upload:
if os.path.isfile(bval_fpath) and os.path.isfile(bvec_fpath):
# BVAL/BVEC
XnatUtils.upload_file_to_obj(bval_fpath,
scan_obj.resource('BVAL'),
remove=True)
XnatUtils.upload_file_to_obj(bvec_fpath,
scan_obj.resource('BVEC'),
remove=True)
# keep the NII with the same name than the BVAL/BVEC
nifti_list = filter(lambda x: x[:-7] == bval_fpath[:-5],
nifti_list)
XnatUtils.upload_files_to_obj(nifti_list,
scan_obj.resource('NIFTI'),
remove=True)
else:
# NII
XnatUtils.upload_files_to_obj(nifti_list,
scan_obj.resource('NIFTI'),
remove=True)
# more than one NIFTI uploaded
if len(nifti_list) > 1:
LOGGER.warn('''dcm2nii -- %s -- more than one NIFTI upload'''
% scan_info['scan_id'])
self.log_warning_error('more than one NIFTI upload', scan_info)
示例2: upload_path
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_file_to_obj [as 别名]
def upload_path(resource_obj, resource_label, fpath, force=False,
delete=False, extract=False):
"""
Upload path to XNAT: either a file or folder
:param resource_obj: pyxnat resource obj
:param resource_label: label of the resource
:param force: force the upload if file exists
:param delete: delete the resource and all files before uploading
:param extract: extract the files if it's a zip
:return: None
"""
_format_f = ' - File %s: uploading file...'
_format_p = ' - Folder %s: uploading folder...'
isfile, fpath = is_file(fpath)
if isfile:
print(_format_f % (os.path.basename(fpath)))
XnatUtils.upload_file_to_obj(
fpath, resource_obj, remove=force, removeall=delete)
else:
print(_format_p % (os.path.basename(fpath)))
XnatUtils.upload_folder_to_obj(
fpath, resource_obj, resource_label,
remove=force, removeall=delete, extract=extract)
示例3: upload_converted_images
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_file_to_obj [as 别名]
def upload_converted_images(dicom_files, dcm_dir, scan_obj, need_to_zip):
"""Upload the images after checking them.
:param dicom_files: list of dicoms files to zip
:param dcm_dir: directory containing the dicoms
:param scan_obj: scan pyxnat object from XNAT
"""
# Local variables
nifti_list = []
bval_fpath = ''
bvec_fpath = ''
# Get the bvec/bval files and NIFTI from the folder:
for fpath in glob.glob(os.path.join(dcm_dir, '*')):
if os.path.isfile(fpath):
if fpath.lower().endswith('.bval'):
bval_fpath = fpath
if fpath.lower().endswith('.bvec'):
bvec_fpath = fpath
if fpath.lower().endswith('.nii.gz'):
nifti_list.append(fpath)
if fpath.lower().endswith('.nii'):
os.system('gzip '+fpath)
nifti_list.append(fpath+'.gz')
# Check NIFTI:
good_to_upload = check_outputs(nifti_list, bval_fpath, bvec_fpath)
# Upload files:
if good_to_upload:
if os.path.isfile(bval_fpath) and os.path.isfile(bvec_fpath):
# BVAL/BVEC
XnatUtils.upload_file_to_obj(bval_fpath,
scan_obj.resource('BVAL'),
remove=True)
XnatUtils.upload_file_to_obj(bvec_fpath,
scan_obj.resource('BVEC'),
remove=True)
# keep the NII with the same name than the BVAL/BVEC
nifti_list = filter(lambda x: x[:-7] == bval_fpath[:-5],
nifti_list)
XnatUtils.upload_files_to_obj(nifti_list,
scan_obj.resource('NIFTI'),
remove=True)
else:
# NII
XnatUtils.upload_files_to_obj(nifti_list,
scan_obj.resource('NIFTI'),
remove=True)
# ZIP the DICOM if more than one
if need_to_zip and OPTIONS.zip_dicoms:
# Remove the files created before zipping:
for nii_file in nifti_list:
os.remove(nii_file)
if os.path.isfile(bval_fpath) and os.path.isfile(bvec_fpath):
os.remove(bval_fpath)
os.remove(bvec_fpath)
print ' --> more than one dicom file, zipping dicoms.'
fzip = 'dicoms.zip'
initdir = os.getcwd()
# Zip all the files in the directory
os.chdir(dcm_dir)
os.system('zip -r %s * > /dev/null' % fzip)
# return to the initial directory:
os.chdir(initdir)
_fzip = os.path.join(dcm_dir, fzip)
# upload
if os.path.exists():
print ' --> uploading zip dicoms'
scan_obj.resource('DICOM').delete()
size_file = int(os.stat(_fzip).st_size) / (1024 * 1024)
if size_file >= LIMIT_SIZE:
msg = 'Big DICOM resource.'
print(msg)
scan_obj.resource('DICOM').put_zip(_fzip, overwrite=True,
extract=False)
# more than one NIFTI uploaded
if len(nifti_list) > 1:
print " - warning: more than one NIFTI upload"
示例4: filter
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_file_to_obj [as 别名]
print 'INFO: connection to xnat <%s>:' % (HOST)
XNAT = XnatUtils.get_interface(host=ARGS.host, user=ARGS.username,
pwd=PWD)
li_assessors = XnatUtils.list_project_assessors(XNAT, ARGS.project)
li_assessors = XnatUtils.filter_list_dicts_regex(
li_assessors, 'proctype',
['GIF_Parcellation_v2'])
li_assessors = XnatUtils.filter_list_dicts_regex(
li_assessors, 'procstatus',
['COMPLETE'])
li_assessors = filter(lambda x: 'WHOLEBRAIN' not in x['resources'],
li_assessors)
li_assessors = sorted(li_assessors, key=lambda k: k['session_label'])
start = False
for assessor in li_assessors:
if ARGS.session:
if assessor['session_label'] == ARGS.session:
start = True
else:
start = True
if start:
print '\n<-- Assessor: %s -->' % assessor['label']
assessor_obj = XnatUtils.get_full_object(XNAT, assessor)
brain = generate_bmask_whole(assessor_obj, assessor,
ARGS.tmpdir)
XnatUtils.upload_file_to_obj(
brain, assessor_obj.resource('WHOLEBRAIN'), removeall=True)
finally:
XNAT.disconnect()