예제 #1
0
        nifti = glob('%s/pib/%s_PIB*.nii' % (sub, subid))
        nifti.sort()
        if len(nifti) < 34:
            logging.error('%s only has %d frames, RUNBYHAND' %
                          (subid, len(nifti)))
            continue

        pth, _ = os.path.split(nifti[0])
        realigndir = os.path.join(pth, 'realign_QA')
        if os.path.isdir(realigndir):
            logging.error('%s exists, remove to rerun' % (realigndir))
            continue
        rlgnout, newnifti = pp.realigntoframe17(nifti)
        tmpparameterfile = rlgnout.outputs.realignment_parameters
        realigndir, _ = os.path.split(tmpparameterfile)
        sum1_5 = pp.make_summed_image(newnifti[:5], prefix='sum1_5_')
        mean_img = rlgnout.outputs.mean_image
        #coregister 1-5 to mean
        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)
예제 #2
0
            tmpparameterfile = bg.unzip_file(tmpparameterfile)
            tmprealigned = [bg.unzip_file(x) for x in tmprealigned]
            hasqa = True

        elif rlgnout.runtime.returncode is not 0:
            logging.warning("Failed to realign %s" % subid)
            continue
        else:
            tmprealigned = rlgnout.outputs.realigned_files
            tmpmean = rlgnout.outputs.mean_image
            tmpparameterfile = rlgnout.outputs.realignment_parameters

            logging.info("realigned %s" % subid)

        # 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
예제 #3
0
        nifti = glob('%s/pib/%s_PIB*.nii'%(sub, subid))
        nifti.sort()
        if len(nifti) < 34:
            logging.error('%s only has %d frames, RUNBYHAND'%(subid,
                                                              len(nifti)))
            continue

        pth, _ = os.path.split(nifti[0])
        realigndir = os.path.join(pth, 'realign_QA')
        if os.path.isdir(realigndir):
            logging.error('%s exists, remove to rerun'%(realigndir))
            continue
        rlgnout, newnifti = pp.realigntoframe17(nifti)
        tmpparameterfile = rlgnout.outputs.realignment_parameters
        realigndir, _ = os.path.split(tmpparameterfile)
        sum1_5 = pp.make_summed_image(newnifti[:5],
                                      prefix='sum1_5_')
        mean_img = rlgnout.outputs.mean_image
        #coregister 1-5 to mean
        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)
            tmpparameterfile = bg.unzip_file(tmpparameterfile)
            tmprealigned = [bg.unzip_file(x) for x in tmprealigned]
            hasqa = True

        elif rlgnout.runtime.returncode is not 0:
            logging.warning('Failed to realign %s' % subid)
            continue
        else:
            tmprealigned = rlgnout.outputs.realigned_files
            tmpmean = rlgnout.outputs.mean_image
            tmpparameterfile = rlgnout.outputs.realignment_parameters

            logging.info('realigned %s' % subid)

        # 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