def main(): """ Entry point for BASIL command line application """ try: parser = AslOptionParser(usage="basil -i <ASL input file> [options...]", version=__version__) parser.add_category(image.AslImageOptions()) parser.add_category(BasilOptions()) parser.add_category(GenericOptions()) options, _ = parser.parse_args() if not options.output: options.output = "basil" if not options.asldata: sys.stderr.write("Input file not specified\n") parser.print_help() sys.exit(1) wsp = Workspace(savedir=options.output, separate_input=True, auto_asldata=True, **vars(options)) # Deal with --artonly if wsp.artonly: wsp.infertiss = False wsp.inferart = True # Adjust number of iterations based on fast option if not wsp.fast: num_iter, num_trials, onestep = 20, 10, False elif wsp.fast == 1: num_iter, num_trials, onestep = 5, 2, False elif wsp.fast == 2: num_iter, num_trials, onestep = 10, 5, True else: raise ValueError("Not a valid option for fast: %s" % str(wsp.fast)) wsp.max_iterations = num_iter wsp.max_trials = num_trials wsp.onestep = onestep # Read in additional model options from a file wsp.model_options = {} if wsp.model_options: with open(wsp.model_options) as optfile: for line in optfile: keyval = line.strip().rstrip("\n").lstrip("--").split("=", 1) key = keyval[0].strip().replace("-", "_") if key != "": if len(keyval) == 1: wsp.model_options[key] = True else: wsp.model_options[key] = keyval[1].strip() # Run BASIL processing basil(wsp) except ValueError as exc: sys.stderr.write("\nERROR: " + str(exc) + "\n") sys.stderr.write("Use --help for usage information\n") sys.exit(1)
def main(): """ Entry point for BASIL command line application """ try: parser = AslOptionParser( usage="basil -i <ASL input file> [options...]", version=__version__) parser.add_category(image.AslImageOptions()) parser.add_category(BasilOptions()) parser.add_category(GenericOptions()) options, _ = parser.parse_args(sys.argv) if not options.output: options.output = "basil" if not options.asldata: sys.stderr.write("Input file not specified\n") parser.print_help() sys.exit(1) asldata = AslImage(options.asldata, **parser.filter(options, "image")) wsp = Workspace(savedir=options.output, **vars(options)) wsp.asldata = asldata # Deal with --artonly if wsp.artonly: wsp.infertiss = False wsp.inferart = True # Adjust number of iterations based on fast option if not wsp.fast: num_iter, num_trials, onestep = 20, 10, False elif wsp.fast == 1: num_iter, num_trials, onestep = 5, 2, False elif wsp.fast == 2: num_iter, num_trials, onestep = 10, 5, True else: raise ValueError("Not a valid option for fast: %s" % str(wsp.fast)) wsp.max_iterations = num_iter wsp.max_trials = num_trials wsp.onestep = onestep # Run BASIL processing, passing options as keyword arguments using ** basil(wsp) except ValueError as exc: sys.stderr.write("\nERROR: " + str(exc) + "\n") sys.stderr.write("Use --help for usage information\n") sys.exit(1)
def main(): """ Entry point for OXASL_DEBLUR command line application """ try: parser = AslOptionParser( usage="oxasl_deblur -i <ASL input file> [options...]", version=__version__) if hasattr(image, "Options"): parser.add_category(image.Options()) else: parser.add_category(image.AslImageOptions()) parser.add_category(Options()) parser.add_category(basil.BasilOptions()) #parser.add_category(calib.CalibOptions()) parser.add_category(GenericOptions()) options, _ = parser.parse_args() if not options.output: options.output = "oxasl_deblur" if not options.asldata: sys.stderr.write("Input ASL data not specified\n") parser.print_help() sys.exit(1) print("OXASL_DEBLUR %s (%s)\n" % (__version__, __timestamp__)) wsp = Workspace(savedir=options.output, auto_asldata=True, **vars(options)) wsp.asldata.summary() wsp.sub("reg") wsp.reg.nativeref = wsp.asldata.perf_weighted() wsp.sub("output") run(wsp, output_wsp=wsp.output) if wsp.save_kernel: wsp.output.kernel = wsp.deblur.kernel if wsp.save_residuals: wsp.output.residuals = wsp.deblur.residuals if not wsp.debug: wsp.deblur = None wsp.input = None print('\nOXASL_DEBLUR - DONE - output is in %s' % options.output) except RuntimeError as e: print("ERROR: " + str(e) + "\n") sys.exit(1)
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)
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)
def main(): """ Entry point for command line tool """ try: parser = AslOptionParser(usage="asl_preproc -i <filename> [options]") parser.add_category(GenericOptions(output_type="file")) parser.add_category(image.AslImageOptions()) parser.add_category(AslPreprocOptions()) options, _ = parser.parse_args() if not options.output: options.output = "oxasl_preproc_out" wsp = Workspace(auto_asldata=True, **vars(options)) print("") wsp.asldata.summary() preprocess(wsp) wsp.asldata_preproc.save(options.output) except ValueError as exc: sys.stderr.write("ERROR: " + str(exc) + "\n") sys.exit(1)
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)