Commit c31b5533 authored by Christoph Arthofer's avatar Christoph Arthofer
Browse files

updated clamping to automatically delete tmp files

parent 5b650129
......@@ -349,10 +349,10 @@ def clampImage(img_path, out_path):
"""
out_dir = os.path.split(out_path)[0]
mask_path = os.path.splitext(os.path.splitext(os.path.basename(out_path))[0])[0] + '_brain.nii.gz'
mask_path = os.path.join(out_dir, mask_path)
bet(img_path, mask_path, robust=True)
mask_name = os.path.splitext(os.path.splitext(os.path.basename(out_path))[0])[0] + '_brain.nii.gz'
with tempfile.TemporaryDirectory(dir=out_dir) as tmpdirname:
mask_path = os.path.join(tmpdirname, mask_name)
bet(img_path, mask_path, robust=True)
fast(mask_path, tmpdirname + '/fast', iter=0, N=True, g=True, v=False)
wm_intensity_mean = fslstats(mask_path).k(tmpdirname + '/fast_seg_2').M.run()
print('White matter mean intensity is: ', wm_intensity_mean)
......@@ -404,8 +404,8 @@ def averageImages(img_paths, out_path, mod='average', norm_bool=False):
img_nib = fslmaths(img_nib).inm(1000).run()
images.append(img_nib.get_fdata())
if n_exist > 0:
median_img = np.median(np.array(images),axis=-1)
median_nib = nib.Nifti1Image(median_img, affine=img_nib.affine, header=img_nib.header)
median_img = np.median(np.array(images),axis=0)
median_nib = nib.Nifti1Image(np.squeeze(median_img), affine=img_nib.affine, header=img_nib.header)
median_nib.to_filename(out_path)
assert n_exist == n_imgs, "Not all images available!"
......@@ -889,8 +889,7 @@ if __name__ == "__main__":
cmd = ' '.join(cmd) + '\n'
f.write(cmd)
# job_ids[2] = submitJob(tag+'_'+task_name, log_dir, script=script_path, queue=cpuq)
job_ids[2] = submitJob(script_path, tag + '_' + task_name, log_dir, queue=cpuq, wait_for=None,
array_task=True)
job_ids[2] = submitJob(script_path, tag + '_' + task_name, log_dir, queue=cpuq, wait_for=None, array_task=True)
print('submitted: ' + task_name)
......
......@@ -11,7 +11,8 @@ ext_txt=.txt
log (log_dir)
scripts (script_dir)
clamped_T1 (clamped_dir)
{sub_id}_T1_clamped{ext_nii} (T1_head_clamped)
{sub_id}
{sub_id}_T1_clamped{ext_nii} (T1_head_clamped)
affine_it1 (affine_it1_dir)
{sub_id} (affine_it1_subject_dir)
T1_to_{ref_id}{ext_mat} (T1_to_ref_mat)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment