Ejemplo n.º 1
0
def oxasl_preproc(wsp):
    """
    Run standard processing on ASL data

    This method requires wsp to be a Workspace containing certain standard information.
    As a minimum, the attribute ``asldata`` must contain an AslImage object.
    """
    if wsp.calib_first_vol and wsp.calib is None:
        wsp.input.calib = wsp.asldata.calib

    report_asl(wsp)

    struc.init(wsp)
    corrections.apply_corrections(wsp)

    corrections.get_motion_correction(wsp)
    corrections.apply_corrections(wsp)

    reg.reg_asl2calib(wsp)
    reg.reg_asl2struc(wsp, True, False)
    reg.reg_asl2custom(wsp)

    corrections.get_fieldmap_correction(wsp)
    corrections.get_cblip_correction(wsp)
    corrections.get_sensitivity_correction(wsp)
    corrections.apply_corrections(wsp)

    mask.generate_mask(wsp)

    if oxasl_enable and wsp.use_enable:
        wsp.sub("enable")
        oxasl_enable.enable(wsp.enable)
        wsp.corrected.asldata = wsp.enable.asldata_enable
Ejemplo n.º 2
0
def get_mask(wsp):
    if wsp.mask is None:
        mask.generate_mask(wsp.deblur)
        wsp.mask = wsp.rois.mask
    else:
        wsp.mask = wsp.mask
Ejemplo n.º 3
0
def model_basil(wsp):
    """
    Do model fitting on TC/CT or subtracted data

    Workspace attributes updated
    ----------------------------

     - ``basil``         - Contains model fitting output on data without partial volume correction
     - ``basil_pvcorr``  - Contains model fitting output with partial volume correction if
                           ``wsp.pvcorr`` is ``True``
     - ``output.native`` - Native (ASL) space output from last Basil modelling output
     - ``output.struc``  - Structural space output
    """
    wsp.basil_options = wsp.ifnone("basil_options", {})

    basil.basil(wsp, output_wsp=wsp.sub("basil"))
    redo_reg(wsp, wsp.basil.finalstep.mean_ftiss)

    wsp.sub("output")
    output_native(wsp.output, wsp.basil)
    output_trans(wsp.output)

    # If the user has provided manual PV maps (pvgm and pvgm) then do PVEc, even if they
    # have not explicitly given the --pvcorr option
    user_pv_flag = ((wsp.pvwm is not None) and (wsp.pvgm is not None))
    if (wsp.pvcorr) or (wsp.surf_pvcorr) or user_pv_flag:
        # Partial volume correction is very sensitive to the mask, so recreate it
        # if it came from the structural image as this requires accurate ASL->Struc registration
        if wsp.rois.mask_src == "struc":
            wsp.rois.mask_orig = wsp.rois.mask
            wsp.rois.mask = None
            mask.generate_mask(wsp)

        if wsp.pvcorr or user_pv_flag:
            # Do partial volume correction fitting
            #
            # FIXME: We could at this point re-apply all corrections derived from structural space?
            # But would need to make sure corrections module re-transforms things like sensitivity map

            # Prepare GM and WM partial volume maps from FAST segmentation
            if user_pv_flag:
                wsp.log.write("\nUsing user-supplied PV estimates\n")
                wsp.structural.wm_pv_asl = wsp.pvwm
                wsp.structural.gm_pv_asl = wsp.pvgm
            else:
                struc.segment(wsp)
                wsp.structural.wm_pv_asl = reg.struc2asl(
                    wsp, wsp.structural.wm_pv)
                wsp.structural.gm_pv_asl = reg.struc2asl(
                    wsp, wsp.structural.gm_pv)

            wsp.basil_options.update({
                "pwm": wsp.structural.wm_pv_asl,
                "pgm": wsp.structural.gm_pv_asl
            })
            basil.basil(wsp, output_wsp=wsp.sub("basil_pvcorr"), prefit=False)

            wsp.sub("output_pvcorr")
            output_native(wsp.output_pvcorr, wsp.basil_pvcorr)
            output_trans(wsp.output_pvcorr)

        if wsp.surf_pvcorr:
            if oxasl_surfpvc is None:
                raise RuntimeError(
                    "Surface-based PVC requested but oxasl_surfpvc is not installed"
                )
            if user_pv_flag:
                wsp.log.write(
                    " - WARNING: Performing surface based PVC ignores user-specified PV maps\n"
                )
            # Prepare GM and WM partial volume maps from surface using Toblerone plugin
            # Then reform the ASL ROI mask - Toblerone does not handle the cerebellum so need
            # to mask it out
            oxasl_surfpvc.prepare_surf_pvs(wsp)
            wsp.rois.mask_pvcorr = wsp.rois.mask
            min_pv = 0.01
            new_roi = (wsp.basil_options["pwm"].data >
                       min_pv) | (wsp.basil_options["pgm"].data > min_pv)
            wsp.rois.mask = Image(new_roi.astype(np.int8),
                                  header=wsp.rois.mask_pvcorr.header)
            basil.basil(wsp,
                        output_wsp=wsp.sub("basil_surf_pvcorr"),
                        prefit=False)

            wsp.sub('output_surf_pvcorr')
            output_native(wsp.output_surf_pvcorr, wsp.basil_surf_pvcorr)
            output_trans(wsp.output_surf_pvcorr)