def transform_vol(invol, xfm, space_defining): invol = bg.unzip_file(invol) # in case zipped xfm = bg.unzip_file(xfm) # in case zipped space_defining = bg.unzip_file(space_defining) # in case zipped pp.apply_transform_onefile(xfm, invol) pp.reslice(space_defining, invol) rinvol = pp.prefix_filename(invol, prefix='r') bg.remove_files([invol]) bg.zip_files([space_defining]) return rinvol
def transform_vol(invol, xfm, space_defining): invol = bg.unzip_file(invol)# in case zipped xfm = bg.unzip_file(xfm)# in case zipped space_defining = bg.unzip_file(space_defining)# in case zipped pp.apply_transform_onefile(xfm, invol) pp.reslice(space_defining, invol) rinvol = pp.prefix_filename(invol, prefix='r') bg.remove_files([invol]) bg.zip_files([space_defining]) return rinvol
### XXXXXXXXXXXXXXXXX ## set_up_dir outdirs = pp.set_up_dir(root, subid, tracer) ## set up MRI brainmask = os.path.join(outdirs["anatomydir"][0], "brainmask.nii") fsmri = pp.find_single_file(os.path.join(mridir, subid, "mri/brainmask.mgz")) if os.path.isfile(brainmask): logging.warning("%s has existing anatomy," "skipping" % (brainmask)) elif fsmri is None: logging.error("%s NO MRI: %s" % (subid, fsmri)) else: fsmri = bg.copy_file(fsmri, outdirs["anatomydir"][0]) brainmask = bg.convert(fsmri, brainmask) bg.remove_files([fsmri]) # copy aseg+aparc aparcnii = os.path.join(outdirs["anatomydir"][0], "%s_aparc_aseg.nii.gz" % subid) aparc = pp.find_single_file(os.path.join(mridir, subid, "mri/aparc+aseg.mgz")) if os.path.isfile(aparcnii): logging.warning("%s has existing anatomy," "skipping" % (aparcnii)) elif aparc is None: logging.error("%s NO APARC ASEG: %s" % (subid, aparc)) else: aparc = bg.copy_file(aparc, outdirs["anatomydir"][0]) aparcnii = bg.convert(aparc, aparcnii) bg.remove_files([aparc]) # make pons refdir, _ = outdirs["refdir"] brainstem = os.path.join(refdir, "brainstem.nii.gz")
outdirs = pp.set_up_dir(root, subid, tracer) ## set up MRI brainmask = os.path.join(outdirs['anatomydir'][0], 'brainmask.nii') fsmri = pp.find_single_file( os.path.join(mridir, subid, 'mri/brainmask.mgz')) if os.path.isfile(brainmask): logging.warning('%s has existing anatomy,'\ 'skipping'%(brainmask)) elif fsmri is None: logging.error('NO MRI: %s' % (fsmri)) else: fsmri = bg.copy_file(fsmri, outdirs['anatomydir'][0]) brainmask = bg.convert(fsmri, brainmask) bg.remove_files([fsmri]) # copy aseg+aparc aparcnii = os.path.join(outdirs['anatomydir'][0], '%s_aparc_aseg.nii.gz' % subid) aparc = pp.find_single_file( os.path.join(mridir, subid, 'mri/aparc+aseg.mgz')) if os.path.isfile(aparcnii): logging.warning('%s has existing anatomy,'\ 'skipping'%(aparcnii)) elif aparc is None: logging.error('NO APARC ASEG: %s' % aparc) else: aparc = bg.copy_file(aparc, outdirs['anatomydir'][0]) aparcnii = bg.convert(aparc, aparcnii) bg.remove_files([aparc])
## set up MRI brainmask = os.path.join(outdirs['anatomydir'][0], 'brainmask.nii') fsmri = pp.find_single_file(os.path.join(mridir, subid, 'mri/brainmask.mgz')) if os.path.isfile(brainmask): logging.warning('%s has existing anatomy,'\ 'skipping'%(brainmask)) elif fsmri is None: logging.error('%s NO MRI: %s'%(subid,fsmri)) else: fsmri = bg.copy_file(fsmri, outdirs['anatomydir'][0]) brainmask = bg.convert(fsmri, brainmask) bg.remove_files([fsmri]) # copy aseg+aparc aparcnii = os.path.join(outdirs['anatomydir'][0], '%s_aparc_aseg.nii.gz'%subid) aparc = pp.find_single_file(os.path.join(mridir, subid, 'mri/aparc+aseg.mgz')) if os.path.isfile(aparcnii): logging.warning('%s has existing anatomy,'\ 'skipping'%(aparcnii)) elif aparc is None: logging.error('%s NO APARC ASEG: %s'%(subid, aparc)) else: aparc = bg.copy_file(aparc, outdirs['anatomydir'][0]) aparcnii = bg.convert(aparc, aparcnii)
outdirs = pp.set_up_dir(root, subid, tracer) ## set up MRI brainmask = os.path.join(outdirs['anatomydir'][0], 'brainmask.nii') fsmri = pp.find_single_file( os.path.join(mridir, subid, 'mri/brainmask.mgz')) if os.path.isfile(brainmask): logging.warning('%s has existing anatomy,'\ 'skipping'%(brainmask)) elif fsmri is None: logging.error('%s NO MRI: %s' % (subid, fsmri)) else: fsmri = bg.copy_file(fsmri, outdirs['anatomydir'][0]) brainmask = bg.convert(fsmri, brainmask) bg.remove_files([fsmri]) # copy aseg+aparc aparcnii = os.path.join(outdirs['anatomydir'][0], '%s_aparc_aseg.nii.gz' % subid) aparc = pp.find_single_file( os.path.join(mridir, subid, 'mri/aparc+aseg.mgz')) if os.path.isfile(aparcnii): logging.warning('%s has existing anatomy,'\ 'skipping'%(aparcnii)) elif aparc is None: logging.error('%s NO APARC ASEG: %s' % (subid, aparc)) else: aparc = bg.copy_file(aparc, outdirs['anatomydir'][0]) aparcnii = bg.convert(aparc, aparcnii) bg.remove_files([aparc])
crg_out = pp.simple_coregister(mean_img, sum1_5, newnifti[:5]) if crg_out.runtime.returncode is not 0: logging.error('Failed to coreg 1-5 to mean for %s' % subid) continue # grab all realigned files allrealigned = crg_out.outputs.coregistered_files + \ rlgnout.outputs.realigned_files # make new mean files(s) based on fully realigned files # 1. first 20 mins for coreg (frames 1-23) # 2. 40-60 mins for possible SUVR (frames 28-31) mean_20min = pp.make_mean_20min(allrealigned) mean_40_60min = pp.make_mean_40_60(allrealigned) # clean up # remove copied unrealigned frames bg.remove_files(newnifti) # QA # make 4d for QA qadir, exists = qa.make_qa_dir(realigndir, name='data_QA') data4d = qa.make_4d_nibabel(allrealigned, outdir=qadir) #snrimg = qa.gen_sig2noise_img(data4d,qadir) #artout = qa.run_artdetect(data4d,tmpparameterfile) #qa.screen_data_dirnme(data4d, qadir) qa.plot_movement(tmpparameterfile, subid) qa.calc_robust_median_diff(data4d) qa.screen_pet(data4d) # Coregister cerebellum, brainmask and aparc_aseg to pet space # logging.info('Coreg %s' % (subid))
crg_out = pp.simple_coregister(mean_img, sum1_5, newnifti[:5]) if crg_out.runtime.returncode is not 0: logging.error('Failed to coreg 1-5 to mean for %s' % subid) continue # grab all realigned files allrealigned = crg_out.outputs.coregistered_files + \ rlgnout.outputs.realigned_files # make new mean files(s) based on fully realigned files # 1. first 20 mins for coreg (frames 1-23) # 2. 40-60 mins for possible SUVR (frames 28-31) mean_20min = pp.make_mean_20min(allrealigned) mean_40_60min = pp.make_mean_40_60(allrealigned) # clean up # remove copied unrealigned frames bg.remove_files(newnifti) # QA # make 4d for QA qadir, exists = qa.make_qa_dir(realigndir, name='data_QA') data4d = qa.make_4d_nibabel(allrealigned, outdir=qadir) #snrimg = qa.gen_sig2noise_img(data4d,qadir) #artout = qa.run_artdetect(data4d,tmpparameterfile) #qa.screen_data_dirnme(data4d, qadir) qa.plot_movement(tmpparameterfile, subid) qa.calc_robust_median_diff(data4d) qa.screen_pet(data4d) # Coregister cerebellum, brainmask and aparc_aseg to pet space #
if not hasqa: logging.info("qa %s" % subid) qa.plot_movement(tmpparameterfile, subid) # get rid of NAN in files no_nanfiles = pp.clean_nan(tmprealigned) # make 4d volume to visualize movement img4d = qa.make_4d_nibabel(no_nanfiles) bg.zip_files(tmprealigned) # save qa image # qa.save_qa_img(img4d) qa.plot_movement(tmpparameterfile, subid) qa.calc_robust_median_diff(img4d) qa.screen_pet(img4d) # remove tmpfiles bg.remove_files(no_nanfiles) bg.remove_files(newnifti) # coreg pons to pet # find PONS pons_searchstr = "%s/ref_region/pons_tu.nii*" % tracerdir pons = pp.find_single_file(pons_searchstr) if "gz" in pons: pons = bg.unzip_file(pons) if pons is None: logging.warning("no pons_tu found for %s" % (subid)) continue # find MRI searchstring = "%s/anatomy/brainmask.nii" % sub mri = pp.find_single_file(searchstring) if mri is None:
if not hasqa: logging.info('qa %s' % subid) qa.plot_movement(tmpparameterfile, subid) # get rid of NAN in files no_nanfiles = pp.clean_nan(tmprealigned) #make 4d volume to visualize movement img4d = qa.make_4d_nibabel(no_nanfiles) bg.zip_files(tmprealigned) #save qa image #qa.save_qa_img(img4d) qa.plot_movement(tmpparameterfile, subid) qa.calc_robust_median_diff(img4d) qa.screen_pet(img4d) #remove tmpfiles bg.remove_files(no_nanfiles) bg.remove_files(newnifti) # coreg pons to pet # find PONS pons_searchstr = '%s/ref_region/pons_tu.nii*' % tracerdir pons = pp.find_single_file(pons_searchstr) if 'gz' in pons: pons = bg.unzip_file(pons) if pons is None: logging.warning('no pons_tu found for %s' % (subid)) continue # find MRI searchstring = '%s/anatomy/brainmask.nii' % sub mri = pp.find_single_file(searchstring) if mri is None: