示例#1
0
文件: reg.py 项目: a3sha2/oxasl
def main():
    """
    Entry point for command line tool
    """
    try:
        parser = AslOptionParser(usage="asl_reg [options]",
                                 version=__version__)
        parser.add_category(RegOptions())
        parser.add_category(struc.StructuralImageOptions())
        parser.add_category(GenericOptions())

        options, _ = parser.parse_args(sys.argv)
        wsp = Workspace(**vars(options))

        if not options.regfrom:
            sys.stderr.write("Input file not specified\n")
            parser.print_help()
            sys.exit(1)

        reg_asl2struc(wsp, wsp.do_flirt, wsp.do_bbr)
        if wsp.output:
            wsp.reg.regto.save(wsp.output)
        if wsp.reg.asl2struc:
            with open(wsp.omat, "w") as transform_file:
                for row in wsp.reg.asl2struc:
                    transform_file.write(" ".join(["%f" % val
                                                   for val in row]) + "\n")

    except ValueError as exc:
        sys.stderr.write("ERROR: " + str(exc) + "\n")
        sys.exit(1)
示例#2
0
def main():
    """
    Entry point for command line tool
    """
    try:
        parser = AslOptionParser(usage="asl_mask -i <asl_image> [options...]",
                                 version=__version__)
        parser.add_option("--calib",
                          "-c",
                          help="Calibration image",
                          default=None)
        parser.add_option(
            "--use-pwi",
            help=
            "Use the perfusion weighted average rather than the timeseries mean",
            action="store_true",
            default=False)
        parser.add_category(image.AslImageOptions())
        parser.add_category(struc.StructuralImageOptions())
        parser.add_category(GenericOptions())

        options, _ = parser.parse_args(sys.argv)
        options.mask = None  # No point in using command line tool if you already have a mask!
        wsp = Workspace(**vars(options))

        if not options.asldata:
            sys.stderr.write("Input file not specified\n")
            parser.print_help()
            sys.exit(1)

        wsp.asldata = AslImage(wsp.asldata,
                               **parser.filter(vars(options), "image"))
        wsp.asldata.summary()

        wsp.generate_mask()

        if wsp.output is None:
            wsp.output = wsp.asldata.name + "_mask"
        wsp.rois.mask.save(wsp.output)

    except ValueError as exc:
        sys.stderr.write("ERROR: " + str(exc) + "\n")
        sys.exit(1)
示例#3
0
def main():
    """
    Entry point for ENABLE command line application
    """
    try:
        parser = AslOptionParser(usage="oxasl_enable -i <ASL input file> [options...]", version=__version__)
        parser.add_category(image.AslImageOptions())
        parser.add_category(EnableOptions())
        parser.add_category(struc.StructuralImageOptions())
        parser.add_category(GenericOptions())
        
        options, _ = parser.parse_args()
        if not options.output:
            options.output = "enable_output"
        if options.debug:
            options.save_all = True

        wsp = Workspace(savedir=options.output, auto_asldata=True, **vars(options))
        wsp.report.title = "ENABLE processing report"
        print("ASL_ENABLE %s (%s)" % (__version__, __timestamp__))
        
        wsp.asldata.summary()
        print("")

        # Preprocessing (TC subtraction, optional MoCo/smoothing)
        #options.diff = True
        #preproc = preprocess(asldata, options, ref=ref)

        enable(wsp)
        print(wsp.enable_results)
        
        print("\nTo run BASIL use input data %s" % wsp.asldata_enable.name)
        print("and %s" % " ".join(["--rpt%i=%i" % (idx+1, rpt) for idx, rpt in enumerate(wsp.asldata_enable.rpts)]))
    
        wsp.report.generate_html(os.path.join(wsp.output, "report"), "report_build")

    except RuntimeError as e:
        print("ERROR: " + str(e) + "\n")
        sys.exit(1)
示例#4
0
def main():
    """
    Entry point for oxasl command line tool
    """
    debug = True
    wsp = None
    try:
        parser = AslOptionParser(usage="oxasl -i <asl_image> [options]",
                                 version=__version__)
        parser.add_category(image.AslImageOptions())
        parser.add_category(struc.StructuralImageOptions())
        parser.add_category(OxfordAslOptions())
        parser.add_category(calib.CalibOptions(ignore=["perf", "tis"]))
        parser.add_category(reg.RegOptions())
        parser.add_category(corrections.DistcorrOptions())
        if oxasl_ve:
            parser.add_category(oxasl_ve.VeaslOptions())
        if oxasl_mp:
            parser.add_category(oxasl_mp.MultiphaseOptions())
        if oxasl_enable:
            parser.add_category(
                oxasl_enable.EnableOptions(ignore=[
                    "regfrom",
                ]))
        if oxasl_multite:
            parser.add_category(oxasl_multite.MultiTEOptions())
        parser.add_category(GenericOptions())

        options, _ = parser.parse_args()
        debug = options.debug
        if not options.output:
            options.output = "oxasl"

        # Some oxasl command-line specific defaults
        if (options.calib is not None
                or options.calib_first_vol) and options.calib_method is None:
            if options.struc is not None:
                options.calib_method = "refregion"
            else:
                options.calib_method = "voxelwise"
        if options.debug:
            options.save_all = True
        options.output_native = True
        options.output_struc = True
        options.save_mask = True

        if options.asldata is None:
            raise RuntimeError("Input ASL file not specified\n")

        if os.path.exists(options.output) and not options.overwrite:
            raise RuntimeError(
                "Output directory exists - use --overwrite to overwrite it")

        wsp = Workspace(savedir=options.output,
                        auto_asldata=True,
                        **vars(options))
        oxasl(wsp)

    except Exception as e:
        sys.stderr.write("ERROR: " + str(e) + "\n")
        if debug:
            traceback.print_exc()
        if wsp is not None:
            wsp.log.write("ERROR: " + str(e) + "\n")
            wsp.log.write(traceback.format_exc() + "\n")
        sys.exit(1)