本文整理汇总了Python中dax.XnatUtils.makedir方法的典型用法代码示例。如果您正苦于以下问题:Python XnatUtils.makedir方法的具体用法?Python XnatUtils.makedir怎么用?Python XnatUtils.makedir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dax.XnatUtils
的用法示例。
在下文中一共展示了XnatUtils.makedir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def run(self):
"""Method running the process for the spider on the inputs data."""
output_dir = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
osirix_dir = XnatUtils.makedir(os.path.join(self.jobdir, 'OsiriX'))
self.time_writer('Dicom folder: %s' % os.path.dirname(self.inputs[0]))
mat_lines = DEFAULT_ADC_TEMPLATE.format(
matlab_code=self.matlab_code,
input_path=os.path.dirname(self.inputs[0]),
output=output_dir,
pdf_name=self.pdf_final)
matlab_script = os.path.join(output_dir, 'run_matlab_verdict.m')
with open(matlab_script, "w") as f:
f.writelines(mat_lines)
self.run_matlab(matlab_script, verbose=True)
# Zip outputs:
# dcm_files = glob.glob(os.path.join(output_dir, '*', '*.dcm'))
dcm_files = get_dicom_list(output_dir)
for dicom in dcm_files:
shutil.copy(dicom, osirix_dir)
self.time_writer('Zipping OsiriX resource ...')
# Zip the DICOMs output:
initdir = os.getcwd()
# Zip all the files in the directory
zip_name = os.path.join(osirix_dir, 'osirix.zip')
os.chdir(osirix_dir)
os.system('zip -r %s * > /dev/null' % zip_name)
# return to the initial directory:
os.chdir(initdir)
示例2: finish
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def finish(self):
"""Method to copy the results in dax.RESULTS_DIR."""
out_dir = os.path.join(self.jobdir, 'outputs')
# Organise the outputs:
ala_dir = XnatUtils.makedir(os.path.join(out_dir, 'REG_ALA'))
aff_dir = XnatUtils.makedir(os.path.join(out_dir, 'AFF'))
reg_dir = XnatUtils.makedir(os.path.join(out_dir, 'REG_F3D'))
cpp_dir = XnatUtils.makedir(os.path.join(out_dir, 'CPP'))
# Copy files:
for scan_id, res_dict in self.sources.items():
for folder in ['REG_ALA', 'REG_F3D', 'AFF', 'CPP']:
old_path = glob.glob(os.path.join(out_dir, scan_id,
folder, '*'))[0]
new_path = os.path.join(out_dir, folder)
shutil.copy(old_path, new_path)
# Zipping all the dicoms in the OSIRIX folder and keep the zip
zip_osirix = os.path.join(out_dir, 'OSIRIX', 'osirix.zip')
results_dict = {'PDF': self.pdf_final,
'REG_ALA': ala_dir,
'AFF': aff_dir,
'REG_F3D': reg_dir,
'CPP': cpp_dir,
'OSIRIX': zip_osirix}
# Upload data:
self.upload_dict(results_dict)
self.end()
示例3: run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def run(self):
"""Method running the process for the spider on the inputs data."""
output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
osirix_folder = XnatUtils.makedir(os.path.join(output_folder,
'OsiriX'))
for nb_acq in range(1, self.nb_acquisition+1):
folder = os.path.join(output_folder, str(nb_acq))
os.makedirs(folder)
mat_lines = DEFAULT_VERDICT_TEMPLATE.format(
matlab_code=self.matlab_code,
input_path=os.path.dirname(self.inputs[nb_acq]),
subject=self.xnat_subject,
filename=os.path.basename(self.inputs[nb_acq]),
output=folder,
project=self.xnat_project,
camino=self.camino,
spams=self.spams,
scheme_filename=self.scheme_filename,
model=self.model)
matlab_script = os.path.join(output_folder,
'run_verdict_map%d.m' % nb_acq)
with open(matlab_script, "w") as f:
f.writelines(mat_lines)
self.run_matlab(matlab_script, verbose=True)
# Generate Dicom for OsiriX
outdir = os.path.join(output_folder, str(nb_acq), 'AMICO',
self.model)
# Load dicom headers
if not os.path.isfile(self.inputs['dcm']):
err = "DICOM File %s not found."
raise Exception(err % self.inputs['dcm'])
sour_obj = dicom.read_file(self.inputs['dcm'])
# Convert all niftis to dicoms
convert_niftis_2_dicoms(
outdir,
sour_obj,
osirix_folder,
nb_acq)
# Subtract the Cobj to the maps:
subtract_obj_to_map(outdir, sour_obj, osirix_folder, nb_acq)
# Make pdf:
self.make_pdf()
# Zip the DICOMs output:
initdir = os.getcwd()
# Zip all the files in the directory
zip_name = os.path.join(self.jobdir, 'outputs', 'OsiriX', 'osirix.zip')
os.chdir(os.path.join(self.jobdir, 'outputs', 'OsiriX'))
os.system('zip -r %s * > /dev/null' % zip_name)
# return to the initial directory:
os.chdir(initdir)
# Gzip nii:
XnatUtils.gzip_nii(outdir)
示例4: run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def run(self):
"""Method running the process for the spider on the inputs data."""
output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
osirix_folder = XnatUtils.makedir(os.path.join(output_folder,
'OsiriX'))
for nb_acq in range(1, self.nb_acquisition+1):
folder = os.path.join(output_folder, str(nb_acq))
os.makedirs(folder)
mat_lines = DEFAULT_VERDICT_TEMPLATE.format(
matlab_code=self.matlab_code,
input_path=self.inputs[nb_acq],
output=folder,
scheme_filename=self.scheme_filename,
camino=self.camino)
matlab_script = os.path.join(output_folder,
'run_matlab_adc_%d.m' % nb_acq)
with open(matlab_script, "w") as f:
f.writelines(mat_lines)
self.run_matlab(matlab_script, verbose=True)
# Generate Dicom for OsiriX
res_nii = os.path.join(folder, 'FIT_ADC.nii')
out_nii = os.path.join(folder,
'%s_FIT_ADC_%d.nii' % (self.xnat_session,
nb_acq))
shutil.move(res_nii, out_nii)
# Load dicom headers
if not os.path.isfile(self.inputs['dcm']):
err = "DICOM File %s not found."
raise Exception(err % self.inputs['dcm'])
sour_obj = dicom.read_file(self.inputs['dcm'])
# Convert all niftis to dicoms
convert_nifti_2_dicoms(
out_nii,
sour_obj,
osirix_folder,
nb_acq,
self.xnat_project,
self.xnat_subject,
self.xnat_session)
# Gzip nii:
XnatUtils.gzip_nii(folder)
# Make pdf:
self.make_pdf()
# Zip the DICOMs output:
initdir = os.getcwd()
# Zip all the files in the directory
zip_name = os.path.join(self.jobdir, 'outputs', 'OsiriX', 'osirix.zip')
os.chdir(os.path.join(self.jobdir, 'outputs', 'OsiriX'))
os.system('zip -r %s * > /dev/null' % zip_name)
# return to the initial directory:
os.chdir(initdir)
示例5: pre_run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def pre_run(self):
"""Method to download data from XNAT.
:param argument_parse: argument parser object return by parse_args()
"""
# Make directory
input_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'inputs'),
subdir=False)
# Download scans:
self.time_writer('Connection to XNAT')
xnat = XnatUtils.get_interface(host=self.host,
user=self.user,
pwd=self.pwd)
# Download NIFTIs
index = 1
for scan_id in self.scans_id:
scan_info = {}
scan_dir = XnatUtils.makedir(os.path.join(input_folder, scan_id),
subdir=False)
self.time_writer('Downloading scan ID %s ...' % scan_id)
scan = XnatUtils.select_obj(xnat,
self.xnat_project,
self.xnat_subject,
self.xnat_session,
scan_id)
snii_obj = scan.resource('NIFTI')
scan_info['4D'] = XnatUtils.download_file_from_obj(scan_dir,
snii_obj)
# Download DICOMs
sdcm_obj = scan.resource('DICOM')
self.time_writer('Downloading DICOM for scan ID %s ...'
% scan_id)
scan_info['dicom'] = XnatUtils.download_file_from_obj(scan_dir,
sdcm_obj)
scan_info['type'] = scan.attrs.get('type')
scan_info['ID'] = scan_id
if 'b3000' in scan_info['type'].lower() and \
len([o for o in self.acquisitions.get(index, list())
if 'b3000' in o['type'].lower()]) > 0:
index += 1
if index in self.acquisitions:
self.acquisitions[index].append(scan_info)
else:
self.acquisitions[index] = [scan_info]
xnat.disconnect()
self.time_writer('Disconnection of XNAT')
示例6: register_nifti
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def register_nifti(self, source_info, target_info, output_folder,
acquisition_number):
"""Register the nifti source to the target.
:param source_info: dictionary information of source image
:param target_info: dictionary information of target image
:param output_folder: path to the output folder
:param acquisition_number: index of the acquisition
:return: path to the 4D nifti register
"""
# Variables:
ala_dir = XnatUtils.makedir(os.path.join(output_folder, 'REG_ALA'))
reg_dir = XnatUtils.makedir(os.path.join(output_folder, 'REG_RES'))
b1tob0 = os.path.join(ala_dir, 'b1tob0.txt')
volume_niis = {0: source_info['3D'][0]}
# Step 2:
# Register each scan b0 to the previous one
# (e.g: b3000 <- b2000)
cmd = REG_ALADIN_CMD.format(exe_path=self.reg_aladin_exe,
ref=target_info['3D'][0],
flo=source_info['3D'][0],
res=source_info['3D'][0],
aff=b1tob0,
args=self.args_reg_aladin)
self.run_system_cmd(cmd)
# Step 3:
# Propagate the transformation to the rest of the volume:
for index, volume in enumerate(source_info['3D']):
if index != 0:
vol_nii = os.path.join(reg_dir, 'volume_%s_reg.nii' % index)
cmd = REG_ALADIN_CMD.format(exe_path=self.reg_resample_exe,
ref=target_info['3D'][0],
flo=volume,
res=vol_nii,
aff=b1tob0,
args=self.args_reg_resample)
self.run_system_cmd(cmd)
volume_niis[index] = vol_nii
# Step 4:
# Put back the nifti together as one volume
final_nii = os.path.join(output_folder, '%s_%s_%d_reg.nii'
% (source_info['ID'],
source_info['type'],
acquisition_number))
join_nifti_3Ds_4D(volume_niis, final_nii)
return final_nii
示例7: make_pdf
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def make_pdf(self):
"""Method to make the PDF for the spider.
:return: None
"""
output_folder = os.path.join(self.jobdir, 'outputs')
pdfs_dir = XnatUtils.makedir(os.path.join(output_folder, 'pdfs'))
fpages = list()
# Run matlab function
for nb_acq in range(1, self.nb_acquisition + 1):
pdf_page = os.path.join(output_folder, str(nb_acq),
'VerdictMapAcq%d.pdf' % nb_acq)
mat_lines = DEFAULT_PDF_MAKER.format(
matlab_code=self.matlab_code,
maps_folder=os.path.join(output_folder, str(nb_acq),
'AMICO', self.model),
subject=self.xnat_subject,
output_folder=pdfs_dir,
acq=nb_acq)
matlab_script = os.path.join(output_folder,
'run_pdf_page_%d.m' % nb_acq)
with open(matlab_script, "w") as f:
f.writelines(mat_lines)
XnatUtils.run_matlab(matlab_script, verbose=True)
# Get all PDFs:
pdf_pages = XnatUtils.find_files(pdfs_dir, '.pdf')
# Merge all pdfs into one:
self.merge_pdf_pages(pdf_pages, pdf_page)
fpages.append(pdf_page)
if len(fpages) > 1:
self.merge_pdf_pages(fpages, self.pdf_final)
else:
shutil.move(fpages[0], self.pdf_final)
示例8: generate_big_nifti
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def generate_big_nifti(self):
"""Generate big nifti with all VERDICT acquisition files."""
for i in range(1, len(self.acquisitions.keys()) + 1):
f_img = nib.load(self.acquisitions[i][0]['4D'])
f_img_data = f_img.get_data()
data = np.zeros(
shape=(f_img_data.shape[0],
f_img_data.shape[1],
f_img_data.shape[2],
f_img_data.shape[3]*len(self.acquisitions[i])))
sorted_list = sorted(self.acquisitions[i],
key=lambda k: int(k['ID']))
for index, scan_info in enumerate(sorted_list):
# Open niftis with nibabel
f_img = nib.load(scan_info['reg'])
f_img_data = f_img.get_data()
for vol in range(0, f_img_data.shape[3]):
# Draw
vol_index = index*f_img_data.shape[3] + vol
data[:, :, :, vol_index] = f_img_data[:, :, :, vol]
nii_5d = nib.Nifti1Image(data, affine=f_img.affine)
acq_dir = XnatUtils.makedir(os.path.join(self.jobdir,
'outputs',
'ACQ%d' % i))
filename = '%s_acquisition%d.nii' % (self.xnat_session, i)
nii_file = os.path.join(acq_dir, filename)
nib.save(nii_5d, nii_file)
# gzip the nifti:
XnatUtils.gzip_file(nii_file)
示例9: pre_run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def pre_run(self, argument_parse):
"""Method to download data from XNAT.
:param argument_parse: argument parser object return by parse_args()
"""
resource = 'DICOM' # resource to download from the scan on XNAT
input_dir = XnatUtils.makedir(os.path.join(self.jobdir, 'inputs'))
self.inputs.extend(self.download(self.xnat_scan, resource, input_dir))
if len(self.inputs) == 1 and self.inputs[0].endswith('.zip'):
self.time_writer('Unzipping the dicoms...')
os.system('unzip -d %s -j %s > /dev/null'
% (os.path.join(input_dir, resource), self.inputs[0]))
os.remove(self.inputs[0])
self.inputs = get_dicom_list(input_dir)
示例10: __init__
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def __init__(self, spider_path, jobdir, xnat_project, xnat_subject, xnat_session,
xnat_host=None, xnat_user=None, xnat_pass=None, suffix="", subdir=True):
"""
Entry point for the Base class for spider
:param spider_path: spider file path
:param jobdir: directory for temporary files
:param xnat_project: project ID on XNAT
:param xnat_subject: subject label on XNAT
:param xnat_session: experiment label on XNAT
:param xnat_host: host for XNAT if not set in environment variables
:param xnat_user: user for XNAT if not set in environment variables
:param xnat_pass: password for XNAT if not set in environment variables
:param suffix: suffix to the assessor creation
:param subdir: create a subdir Temp in the jobdir if the directory isn't empty
"""
# Spider path:
self.spider_path = spider_path
# directory for temporary files + create it
self.jobdir = XnatUtils.makedir(os.path.abspath(jobdir), subdir=subdir)
# to copy results at the end
self.spider_handler = None
# Xnat info:
self.xnat_project = xnat_project
self.xnat_subject = xnat_subject
self.xnat_session = xnat_session
# Xnat connection settings:
self.host = self.get_default_value("host", "XNAT_HOST", xnat_host)
self.user = self.get_default_value("user", "XNAT_USER", xnat_user)
self.pwd = self.get_pwd(xnat_pass, xnat_user)
# Suffix
if not suffix:
self.suffix = ""
else:
# Set the suffix_proc remove any special characters and replace by '_'
self.suffix = re.sub('[^a-zA-Z0-9]', '_', suffix)
# Replace multiple underscores by one
self.suffix = re.sub('_+', '_', self.suffix)
# Remove underscore if at the end of suffix
if self.suffix[-1] == '_': self.suffix = self.suffix[:-1]
# Add an underscore at the beginning if not present
if self.suffix[0] != '_': self.suffix = '_'+self.suffix
# print time writer:
self.time_writer = TimedWriter()
# Export the variable:
os.environ['XNAT_HOST'] = self.host
os.environ['XNAT_USER'] = self.user
os.environ['XNAT_PASS'] = self.pwd
示例11: zip_resources
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def zip_resources(xnat, args):
"""
Loop through the project scans to zip files.
:param xnat: interface from dax related to pyxnat
:param args: arguments from parse_args
"""
# set a directory where the files are download
directory = os.path.abspath(XnatUtils.makedir(args.directory))
list_scans = XnatUtils.list_project_scans(xnat, args.project)
print("INFO: Filtering list of scans to keep scans with resources.")
if not args.force:
for resource in args.resources.split(','):
list_scans = filter(lambda x: resource in x['resources'],
list_scans)
# if sessions, filter:
if args.sessions:
list_scans = filter(
lambda x: x['session_label'] in args.sessions.split(','),
list_scans)
# filtering last sessions:
list_scans = sorted(list_scans, key=lambda k: k['session_label'])
if args.lastsess:
list_scans = remove_sessions_processed(list_scans, args.lastsess)
number_scans = len(list_scans)
print("INFO: Converting the %s scans found." % (number_scans))
for index, scan in enumerate(list_scans):
message = ' * {ind}/{tot} -- Session: {sess} -- Scan: {scan}'
print(message.format(ind=index + 1,
tot=number_scans,
sess=scan['session_label'],
scan=scan['ID']))
scan_obj = XnatUtils.get_full_object(xnat, scan)
if scan_obj.exists():
for resource in args.resources.split(','):
zip_resource(scan_obj.resource(resource), directory,
resource, args.no_delete, args.no_big)
示例12: run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def run(self, openmp_core=1):
"""Method running the process for the spider on the inputs data."""
output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'),
subdir=False)
# Sort the DICOM T2 to convert the registered modalities NIFTI to DICOM
dcm_obj_sorted = dict()
for dcm_file in self.target['dcm']:
# Load dicom headers
if not os.path.isfile(dcm_file):
err = "DICOM File %s not found after download."
raise Exception(err % dcm_file)
t2_dcm_obj = dicom.read_file(dcm_file)
dcm_obj_sorted[t2_dcm_obj[0x00200032].value[2]] = t2_dcm_obj
dcm_obj_sorted_list = [dcm_obj_sorted[key] for key in
sorted(dcm_obj_sorted)]
# REG ALADIN:
for scan_id, res_dict in self.sources.items():
# Organise folders for ouput
sc_dir = os.path.join(output_folder, scan_id)
reg_folder = XnatUtils.makedir(sc_dir, subdir=False)
ala_dir = os.path.join(reg_folder, 'REG_ALA')
aff_dir = os.path.join(reg_folder, 'AFF')
reg_dir = os.path.join(reg_folder, 'REG_F3D')
cpp_dir = os.path.join(reg_folder, 'CPP')
ala_folder = XnatUtils.makedir(ala_dir, subdir=False)
aff_folder = XnatUtils.makedir(aff_dir, subdir=False)
f3d_folder = XnatUtils.makedir(reg_dir, subdir=False)
cpp_folder = XnatUtils.makedir(cpp_dir, subdir=False)
self.time_writer("reg_aladin with ref %s and flo %s" %
(self.target['nii'], res_dict['nii']))
aladin_output = os.path.join(ala_folder, "%s_2_%s_reg_aladin.nii" %
(scan_id, ARGS.target_id))
affine_fpath = os.path.join(aff_folder,
"%s_2_%s_affine_transformation.txt" %
(scan_id, ARGS.target_id))
cmd = REG_ALADIN_CMD.format(exe_path=self.reg_aladin_exe,
ref=self.target['nii'],
flo=res_dict['nii'],
res=aladin_output,
aff=affine_fpath,
omp=openmp_core,
args=ARGS.args_reg_aladin)
self.run_system_cmd(cmd)
# Check that the affine file exists:
if not os.path.exists(affine_fpath):
err = 'Reg_aladin failed. File %s not found.'
raise Exception(err % affine_fpath)
# REG_F3D
self.time_writer("reg_f3d with ref %s and flo %s and aff %s" %
(self.target['nii'],
res_dict['nii'],
affine_fpath))
f3d_output = os.path.join(f3d_folder, "%s_2_%s_reg_f3d.nii" %
(scan_id, ARGS.target_id))
f3d_cpp = os.path.join(cpp_folder, "%s_2_%s_reg_f3d_cpp.nii" %
(scan_id, ARGS.target_id))
cmd = REG_F3D_CMD.format(exe_path=self.reg_f3d_exe,
ref=self.target['nii'],
flo=res_dict['nii'],
res=f3d_output,
cpp=f3d_cpp,
aff=affine_fpath,
omp=openmp_core,
args=ARGS.args_regf3d)
self.run_system_cmd(cmd)
XnatUtils.gzip_nii(ala_folder)
XnatUtils.gzip_nii(f3d_folder)
XnatUtils.gzip_nii(cpp_folder)
self.outputs[scan_id] = [{'label': 'reg_aladin_results',
'image': aladin_output+'.gz'},
{'label': 'reg_f3d_results',
'image': f3d_output+'.gz'}]
# Generate DICOM version of the reg_f3d results:
convert_nifti_2_dicoms(f3d_output+'.gz', dcm_obj_sorted_list,
self.sources[scan_id]['dcm'],
os.path.join(output_folder, 'OSIRIX'),
label=("%s_reg_f3d" % scan_id))
# Make PDF
self.make_pdf()
# Zip the DICOMs output:
initdir = os.getcwd()
# Zip all the files in the directory
zip_name = os.path.join(self.jobdir, 'outputs', 'OSIRIX', 'osirix.zip')
os.chdir(os.path.join(self.jobdir, 'outputs', 'OSIRIX'))
os.system('zip -r %s * > /dev/null' % zip_name)
# return to the initial directory:
os.chdir(initdir)
示例13: pre_run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def pre_run(self):
"""Method to download data from XNAT.
:param argument_parse: argument parser object return by parse_args()
"""
# Make directory
input_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'inputs'),
subdir=False)
# Target
target_folder = XnatUtils.makedir(os.path.join(input_folder,
ARGS.target_id),
subdir=False)
target_dcm = XnatUtils.makedir(os.path.join(target_folder, 'DICOM'),
subdir=False)
self.time_writer('Connection to XNAT')
xnat = XnatUtils.get_interface(host=self.host,
user=self.user,
pwd=self.pwd)
self.time_writer('Downloading target %s ...' % ARGS.target_id)
target_scan = XnatUtils.select_obj(xnat,
ARGS.proj_label,
ARGS.subj_label,
ARGS.sess_label,
ARGS.target_id)
tnii_obj = target_scan.resource('NIFTI')
self.target['nii'] = XnatUtils.download_file_from_obj(target_folder,
tnii_obj)
tdcm_obj = target_scan.resource('DICOM')
self.target['dcm'] = XnatUtils.download_files_from_obj(target_dcm,
tdcm_obj)
self.target['type'] = target_scan.attrs.get('type')
self.target['ID'] = ARGS.target_id
# Sources
sources_list = XnatUtils.get_input_list(ARGS.sources_id, list())
self.time_writer('Downloading sources %s ...' % sources_list)
for scan_id in sources_list:
# Make directories
spath = os.path.join(input_folder, scan_id)
source_folder = XnatUtils.makedir(spath, subdir=False)
dpath = os.path.join(source_folder, 'DICOM')
source_dcm = XnatUtils.makedir(dpath, subdir=False)
source_scan = XnatUtils.select_obj(xnat,
ARGS.proj_label,
ARGS.subj_label,
ARGS.sess_label,
scan_id)
snii_obj = source_scan.resource('NIFTI')
nii_list = XnatUtils.download_file_from_obj(source_folder,
snii_obj)
sdcm_obj = source_scan.resource('DICOM')
dcm_list = XnatUtils.download_file_from_obj(source_dcm, sdcm_obj)
self.sources[scan_id] = dict()
self.sources[scan_id]['nii'] = nii_list
self.sources[scan_id]['dcm'] = dcm_list
self.sources[scan_id]['type'] = source_scan.attrs.get('type')
self.sources[scan_id]['ID'] = scan_id
xnat.disconnect()
self.time_writer('Disconnection of XNAT')
示例14: parse_args
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
% executable)
if __name__ == '__main__':
OPTIONS = parse_args()
print 'Converting DICOM to NIFTI for Project:\t%s' % OPTIONS.project
print 'Time: ', str(datetime.now())
# Check executables
DCM2NII_EXE = OPTIONS.dcm2nii
DCMDJPEG_EXE = OPTIONS.dcmdjpeg
version_exe(DCM2NII_EXE)
version_exe(DCMDJPEG_EXE)
# set a directory where the files are download
OPTIONS.directory = XnatUtils.makedir(OPTIONS.directory)
# Connection to Xnat
try:
if OPTIONS.username:
msg = """password for user <%s>:""" % OPTIONS.username
pwd = getpass.getpass(prompt=msg)
else:
pwd = None
XNAT = XnatUtils.get_interface(host=OPTIONS.host,
user=OPTIONS.username,
pwd=pwd)
convert_DICOM()
finally:
XNAT.disconnect()
示例15: run
# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import makedir [as 别名]
def run(self):
"""Method running the process for the spider on the inputs data."""
output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
osirix_folder = XnatUtils.makedir(os.path.join(output_folder,
'OsiriX'))
for i in range(1, len(self.acquisitions.keys()) + 1):
for index, scan_info in enumerate(self.acquisitions[i]):
# Step 1:
# Transform the 4D Nifti into 3D images for registration:
self.time_writer('Splitting nifti %s ...' % scan_info['ID'])
self.acquisitions[i][index]['3D'] = split_nifti_4D_3Ds(
scan_info['4D'])
if 'b3000' not in scan_info['type'].lower():
outdir = XnatUtils.makedir(os.path.join(output_folder,
scan_info['ID']))
# Step 2-3-4 see register nifti
self.time_writer('Registration nifti ...')
nii_reg = self.register_nifti(
self.acquisitions[i][index],
self.acquisitions[i][index-1],
outdir, i)
self.acquisitions[i][index]['reg'] = nii_reg
# Generate DICOM version of the reg_f3d results:
convert_nifti_2_dicom(
nii_reg,
self.acquisitions[i][index-1]['dicom'],
self.acquisitions[i][index]['dicom'],
osirix_folder,
scan_info['type'],
label=("%s_%s_reg"
% (scan_info['ID'],
scan_info['type'].replace(' ', '_'))))
else:
ori_nii = self.acquisitions[i][index]['4D']
self.acquisitions[i][index]['reg'] = ori_nii
# Convert the original NIFTI from b3000 to dicom:
convert_nifti_2_dicom(
ori_nii,
self.acquisitions[i][index]['dicom'],
self.acquisitions[i][index]['dicom'],
osirix_folder,
scan_info['type'],
label=("%s_%s_reg"
% (scan_info['ID'],
scan_info['type'].replace(' ', '_'))))
# Generate big niftis
self.generate_big_nifti()
# Make PDF
self.make_pdf()
# Zip the DICOMs output:
initdir = os.getcwd()
# Zip all the files in the directory
zip_name = os.path.join(self.jobdir, 'outputs', 'OsiriX', 'osirix.zip')
os.chdir(os.path.join(self.jobdir, 'outputs', 'OsiriX'))
os.system('zip -r %s * > /dev/null' % zip_name)
# return to the initial directory:
os.chdir(initdir)