本文整理汇总了Python中dax.XnatUtils.upload_files_to_obj方法的典型用法代码示例。如果您正苦于以下问题:Python XnatUtils.upload_files_to_obj方法的具体用法?Python XnatUtils.upload_files_to_obj怎么用?Python XnatUtils.upload_files_to_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dax.XnatUtils
的用法示例。
在下文中一共展示了XnatUtils.upload_files_to_obj方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_converted_images
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_files_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:
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_files_to_obj [as 别名]
if ASSESSOR:
li_assessors = [XnatUtils.select_assessor(xnat, ASSESSOR)]
sys.stdout.write('Renaming resources %s to %s for assessor %s'
% (OLD_RESOURCE, NEW_RESOURCE, ASSESSOR))
else:
li_assessors = XnatUtils.list_project_assessors(xnat, PROJECT)
sys.stdout.write('Renaming resources %s to %s for assessor type %s\n'
% (OLD_RESOURCE, NEW_RESOURCE, ASSESSOR_TYPE))
for assessor in li_assessors:
sys.stdout.write(' - assessor: %s ...\n' % assessor['label'])
assessors = XnatUtils.get_full_object(xnat, assessor)
old_res = assessors.resource(OLD_RESOURCE)
files = None
if old_res.exists():
files = XnatUtils.download_files_from_obj(TMP_DIR, old_res)
if files:
new_res = assessors.resource(NEW_RESOURCE)
XnatUtils.upload_files_to_obj(files, new_res)
if new_res.exists():
old_res.delete()
sys.stdout.write(' renamed.\n')
for f in files:
os.remove(f)
print "DONE -- See y'all"
except Exception as e:
print 'error: %s' % e
finally:
xnat.disconnect()
示例3: upload_converted_images
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import upload_files_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"