def test_sub_kwargs(): """ Test creating a sub workspace with kwargs """ wsp = Workspace() wsp.sub("child", wibble="squid", pudding=4) assert(isinstance(wsp.child, Workspace)) assert(wsp.child.wibble == "squid") assert(wsp.child.pudding == 4)
def test_sub(): """ Test sub-workspaces """ wsp = Workspace() wsp.sub("child") assert(isinstance(wsp.child, Workspace)) assert(wsp.child.wibble is None) assert(wsp.child.log == wsp.log)
def test_default_wsp_multiple(): """ Test multiple default sub-workspaces for search """ wsp = Workspace(defaults=["plants", "trees"]) wsp.daffodil = 9 wsp.larch = 1 wsp.sub("trees") wsp.trees.oak = 3 wsp.trees.larch = 2 wsp.trees.apple = 7 assert(wsp.daffodil == 9) assert(wsp.larch == 1) assert(wsp.oak == 3) assert(wsp.apple == 7) assert(wsp.trees.larch == 2) assert(wsp.trees.oak == 3) assert(wsp.trees.daffodil is None) assert(wsp.trees.apple == 7) wsp.sub("plants") wsp.plants.lily = 4 wsp.plants.oak = 5 assert(wsp.daffodil == 9) assert(wsp.larch == 1) assert(wsp.lily == 4) assert(wsp.oak == 5) assert(wsp.apple == 7) assert(wsp.trees.oak == 3) assert(wsp.trees.lily is None) assert(wsp.plants.daffodil is None) assert(wsp.plants.lily == 4) assert(wsp.plants.oak == 5)
def test_sub_inherit_wsp(): """ Test sub workspaces can inherit sub-workspaces from their parent """ wsp = Workspace() wsp.sub("child1") wsp.child1.wibble = 7 wsp.sub("child2") assert(wsp.child2.child1 is not None) assert(wsp.child2.child1.wibble == 7)
def test_sub_inherit(): """ Test sub workspaces can inherit values from their parent """ wsp = Workspace() wsp.wibble = 7 wsp.wobble = 6 wsp.sub("child") wsp.child.wobble = 5 assert(wsp.child.wibble == 7) assert(wsp.child.wobble == 5)
def main(): """ Simple test case """ from fsl.data.image import Image from oxasl import Workspace wsp = Workspace(savedir="epi_py_out", debug=True) wsp.sub("reg") wsp.regfrom = Image(sys.argv[1]) wsp.fslanat = sys.argv[2] struc.init(wsp) result = epi_reg(wsp, wsp.regfrom) wsp.imgreg, wsp.img2struc = result["out.nii.gz"], result["out"]
def test_savedir_sub(): """ Test sub-workspace have subdirs created """ tempdir = tempfile.mktemp("_oxasl") try: log = StringIO() wsp = Workspace(savedir=tempdir, log=log) wsp.sub("quark") path = os.path.join(tempdir, "quark") assert(wsp.quark.savedir == path) assert(os.path.isdir(path)) assert("WARNING" not in log.getvalue()) finally: shutil.rmtree(tempdir)
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 test_default_wsp(): """ Test default sub-workspaces for search """ wsp = Workspace(defaults=["cars"]) assert(wsp.cars is None) wsp.ferrari = 9 wsp.merc = 8 wsp.sub("cars") wsp.cars.porsche = 6 wsp.cars.ferrari = 4 assert(wsp.cars is not None) assert(wsp.ferrari == 9) assert(wsp.porsche == 6) assert(wsp.merc == 8) assert(wsp.cars.porsche == 6) assert(wsp.cars.ferrari == 4) assert(wsp.cars.merc is None)