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
Пример #3
0
        # make final mean image
        meanimg = pp.make_summed_image(tmprealigned)

        # move data back to main directory
        nifti_dir, _ = os.path.split(nifti[0])
        movedmean = bg.copy_file(meanimg, nifti_dir)

        # QA
        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:
Пример #4
0
        ## find sum
        globstr = os.path.join(s, "pib", "realign_QA", "mean20min*.nii")
        sum = pp.find_single_file(globstr)

        if brainmask is None or sum is None:
            logging.error("pet2mri sum: %s brainmask: %s" % (sum, brainmask))
            continue
        # move dvr and sum to coregdir, unzip if necessary
        cdvr = bg.copy_file(dvr, coregdir)
        csum = bg.copy_file(sum, coregdir)
        cdvr = bg.unzip_file(cdvr)
        csum = bg.unzip_file(csum)
        ## coreg pet 2 brainmask
        corg_out = pp.simple_coregister(str(brainmask), str(csum), other=str(cdvr))
        if not corg_out.runtime.returncode == 0:
            logging.error(corg_out.runtime.traceback)
            continue
        rdvr = corg_out.outputs.coregistered_files
        # copy dvr to freesurfer subjects petdir
        cdvr = bg.copy_file(rdvr, petdir)
        globstr = os.path.join(fsdir, "mri", "T1.mgz")
        t1 = pp.find_single_file(globstr)
        if t1 is None:
            logging.error("%s not found" % globstr)
            continue
        xfm = fst.fs_generate_dat(cdvr, t1, subid)
        outfiles = fst.pet_2_surf(cdvr, xfm, mridir)
        # zip files in coregdir
        allf = glob("%s/*" % coregdir)
        bg.zip_files(allf)
        # make final mean image
        meanimg = pp.make_summed_image(tmprealigned)

        # move data back to main directory
        nifti_dir, _ = os.path.split(nifti[0])
        movedmean = bg.copy_file(meanimg, nifti_dir)

        #QA
        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:
Пример #6
0
        sum = pp.find_single_file(globstr)

        if brainmask is None or sum is None:
            logging.error('pet2mri sum: %s brainmask: %s' % (sum, brainmask))
            continue
        # move dvr and sum to coregdir, unzip if necessary
        cdvr = bg.copy_file(dvr, coregdir)
        csum = bg.copy_file(sum, coregdir)
        cdvr = bg.unzip_file(cdvr)
        csum = bg.unzip_file(csum)
        ## coreg pet 2 brainmask
        corg_out = pp.simple_coregister(str(brainmask),
                                        str(csum),
                                        other=str(cdvr))
        if not corg_out.runtime.returncode == 0:
            logging.error(corg_out.runtime.traceback)
            continue
        rdvr = corg_out.outputs.coregistered_files
        # copy dvr to freesurfer subjects petdir
        cdvr = bg.copy_file(rdvr, petdir)
        globstr = os.path.join(fsdir, 'mri', 'T1.mgz')
        t1 = pp.find_single_file(globstr)
        if t1 is None:
            logging.error('%s not found' % globstr)
            continue
        xfm = fst.fs_generate_dat(cdvr, t1, subid)
        outfiles = fst.pet_2_surf(cdvr, xfm, mridir)
        # zip files in coregdir
        allf = glob('%s/*' % coregdir)
        bg.zip_files(allf)