Пример #1
0
def run_test():
    timemory.enable_signal_detection()
    timemory.settings.output_dir = "test_output"

    rss = timemory.rss_usage()
    rss.record()
    print('\nRSS at initialization: {}\n'.format(rss))

    measure('begin')

    main()
    main()
    main()
    dummy()

    manager = timemory.manager()
    print('\nTiming report:\n{}'.format(manager))
    timemory.settings.output_path = "timemory_array_test"
    #manager.report(ign_cutoff = True)
    #plotting.plot(files=[fserial], display=False, output_dir=options.output_dir)

    measure('end')

    timemory.disable_signal_detection()
    print('"{}" testing finished'.format(__file__))
Пример #2
0
def exit_action(errcode):
    man = timemory.manager()
    timemory.report(ign_cutoff=True)
    fname = 'signal_error_{}.out'.format(errcode)
    f = open(fname, 'w')
    f.write('{}\n'.format(man))
    f.close()
Пример #3
0
def exit_action(errcode):
    man = timemory.manager()
    timemory.report(ign_cutoff=True)
    fname = 'signal_error_{}.out'.format(errcode)
    f = open(fname, 'w')
    f.write('{}\n'.format(man))
    f.close()
Пример #4
0
def run(pattern="", exit_at_failure=True):
    """
    Run the TiMemory unit tests

    Args:
        pattern (str): a regex string for matching the name of the tests to run
            an empty string implies run all tests
    """
    import timemory
    manager = timemory.manager()
    test_names = ['timemory', 'array', 'nested', 'simple']
    names = []
    try:
        import re
        pat = re.compile(pattern)
        for t in test_names:
            mat = pat.match(t)
            if mat is not None:
                names.append(t)
    except:
        names = test_names

    if len(names) == 0:
        print('Warning! Pattern "{}" had no matches, running full suite: {}'.
              format(pattern, test_names))
        names = test_names

    print('\n--> TiMemory has MPI support: {}\n'.format(
        timemory.has_mpi_support()))
    print('\n--> Running tests...\n')
    _fail = 0
    _call = 0
    _tot = timemory.timer('Total test time')
    _tot.start()
    for i in names:
        manager.clear()
        _f = '{}_test'.format(i)
        _file = os.path.join(__this_path, '{}.py'.format(_f))
        t = timemory.timer('{}'.format(_f.upper()))
        t.start()
        print('\n--> [ Running {} ] ...\n'.format(_f))
        try:
            _call += 1
            sp.check_call([sys.executable, _file], cwd=os.getcwd())
        except:
            _fail += 1
            print('\n>>>>>>> Test [ {} ] failed! <<<<<<<\n'.format(_f))
        t.stop()
        print('\n\n>>>>>>> {} <<<<<<<\n\n'.format(t))
    print('\n\n============== PASSING TESTS: {}/{} =============='.format(
        _call - _fail, _call))
    print('============== FAILING TESTS: {}/{} ==============\n\n'.format(
        _fail, _call))
    _tot.stop()
    print('\n\n>>>>>>> {} <<<<<<<\n\n'.format(_tot))

    if _fail > 0 and exit_at_failure:
        sys.exit(_fail)
Пример #5
0
def main(nfib):
    timemory.set_max_depth(10)
    print('')
    print('main: file() {}'.format(timemory.FILE()))
    print('main: line() {}'.format(timemory.LINE()))
    print('main: line() {}'.format(timemory.LINE()))
    print('main: func() {}'.format(timemory.FUNC()))
    test()
    print('creating manager...')
    tman = timemory.manager()
    print('creating Fibonacci object...')
    fib = Fibonacci(int(nfib))
    print('calculating fibonacci...')
    ret = fib.calculate()
    print('completed...')

    timemory.report()
Пример #6
0
        set_environ("TIMEMORY_SCIENTIFIC", 0)
        set_environ("TIMEMORY_FILE_OUTPUT", 0)

        #----------------------------------------------------------------------#
        #   parse arguments
        #
        args = handle_arguments()

        #----------------------------------------------------------------------#
        #   import and setup
        #
        import timemory
        import subprocess as sp

        # grab a manager handle
        timemory_manager = timemory.manager()

        # rusage records child processes
        timemory.set_rusage_children()

        components = []
        for c in [
                "wall_clock", "user_clock", "sys_clock", "cpu_clock",
                "cpu_util", "peak_rss", "num_minor_page_faults",
                "num_major_page_faults", "voluntary_context_switch",
                "priority_context_switch"
        ]:
            components.append(getattr(timemory.component, c))

        # run the command
        exe_name = "[pytimem]"
Пример #7
0
def main(arg):

    import multiprocessing as mp
    default_ncores = mp.cpu_count()

    parser = argparse.ArgumentParser()
    parser.add_argument("fname",
                        help=("file name of a tmographic dataset: "
                              "/data/sample.h5")
                        )
    parser.add_argument("--axis", nargs='?', type=str, default="0",
                        help=("rotation axis location: 1024.0 "
                              "(default 1/2 image horizontal size)")
                        )
    parser.add_argument("--type", nargs='?', type=str, default="slice",
                        help="reconstruction type: full (default slice)")
    parser.add_argument("--nsino", nargs='?', type=restricted_float,
                        default=0.5,
                        help=("location of the sinogram used by slice "
                              "reconstruction (0 top, 1 bottom): 0.5 "
                              "(default 0.5)")
                        )
    parser.add_argument("-a", "--algorithm", help="Select the algorithm",
                        default="gridrec", choices=algorithms, type=str)
    parser.add_argument("-n", "--ncores", help="number of cores",
                        default=default_ncores, type=int)
    parser.add_argument("-f", "--format", help="output image format",
                        default="jpeg", type=str)
    parser.add_argument("-S", "--scale",
                        help="scale image by a positive factor",
                        default=1, type=int)
    parser.add_argument("-c", "--ncol", help="Number of images per row",
                        default=1, type=int)
    parser.add_argument("-i", "--num-iter", help="Number of iterations",
                        default=1, type=int)
    parser.add_argument("-o", "--output-dir", help="Output directory",
                        default=None, type=str)
    parser.add_argument("-g", "--grainsize",
                        help="Granularity of slices to compute",
                        default=16, type=int)

    args = parser.parse_args()

    print("\nargs: {}\n".format(args))

    if args.output_dir is None:
        fpath = os.path.basename(os.path.dirname(args.fname))
        args.output_dir = os.path.join(fpath + "_output", args.algorithm)
        if not os.path.exists(args.output_dir):
            os.makedirs(args.output_dir)

    manager = timemory.manager()

    # Set path to the micro-CT data to reconstruct.
    fname = args.fname

    rot_center = float(args.axis)

    # Set default rotation axis location
    if rot_center == 0:
        data_size = get_dx_dims(fname, 'data')
        rot_center =  data_size[2]/2

    nsino = float(args.nsino)

    blocked_views = None

    slice = False
    if args.type == "slice":
        slice = True

    imgs = []
    if os.path.isfile(fname):
        if slice:
            imgs = rec_slice(fname, nsino, rot_center, args, blocked_views)
        else:
            imgs = rec_full(fname, rot_center, args, blocked_views,
                            args.grainsize)

    else:
        print("File name does not exist: ", fname)

    output_analysis(manager, args)
Пример #8
0
def main(arg):

    import multiprocessing as mp
    default_ncores = mp.cpu_count()

    parser = argparse.ArgumentParser()
    parser.add_argument("fname",
                        help=("file name of a tmographic dataset: "
                              "/data/sample.h5")
                        )
    parser.add_argument("--axis", nargs='?', type=str, default="0",
                        help=("rotation axis location: 1024.0 "
                              "(default 1/2 image horizontal size)")
                        )
    parser.add_argument("--type", nargs='?', type=str, default="slice",
                        help="reconstruction type: full (default slice)")
    parser.add_argument("--nsino", nargs='?', type=restricted_float,
                        default=0.5,
                        help=("location of the sinogram used by slice "
                              "reconstruction (0 top, 1 bottom): 0.5 "
                              "(default 0.5)")
                        )
    parser.add_argument("-a", "--algorithm", help="Select the algorithm",
                        default="gridrec", choices=algorithms, type=str)
    parser.add_argument("-n", "--ncores", help="number of cores",
                        default=default_ncores, type=int)
    parser.add_argument("-f", "--format", help="output image format",
                        default="jpeg", type=str)
    parser.add_argument("-S", "--scale",
                        help="scale image by a positive factor",
                        default=1, type=int)
    parser.add_argument("-c", "--ncol", help="Number of images per row",
                        default=1, type=int)
    parser.add_argument("-i", "--num-iter", help="Number of iterations",
                        default=1, type=int)
    parser.add_argument("-o", "--output-dir", help="Output directory",
                        default=None, type=str)
    parser.add_argument("-g", "--grainsize",
                        help="Granularity of slices to compute",
                        default=16, type=int)

    args = parser.parse_args()

    print("\nargs: {}\n".format(args))

    if args.output_dir is None:
        fpath = os.path.basename(os.path.dirname(args.fname))
        args.output_dir = os.path.join(fpath + "_output", args.algorithm)
        if not os.path.exists(args.output_dir):
            os.makedirs(args.output_dir)

    manager = timemory.manager()

    # Set path to the micro-CT data to reconstruct.
    fname = args.fname

    rot_center = float(args.axis)

    # Set default rotation axis location
    if rot_center == 0:
        data_size = get_dx_dims(fname, 'data')
        rot_center =  data_size[2]/2

    nsino = float(args.nsino)

    blocked_views = None

    slice = False
    if args.type == "slice":
        slice = True

    imgs = []
    if os.path.isfile(fname):
        if slice:
            imgs = rec_slice(fname, nsino, rot_center, args, blocked_views)
        else:
            imgs = rec_full(fname, rot_center, args, blocked_views,
                            args.grainsize)

    else:
        print("File name does not exist: ", fname)

    output_analysis(manager, args)
Пример #9
0
def main(args):

    global image_quality

    manager = timemory.manager()

    algorithm = args.algorithm
    if len(args.compare) > 0:
        algorithm = "comparison"

    print(("\nArguments:\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n"
           "{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n").format(
               "\tPhantom", args.phantom, "\tAlgorithm", algorithm, "\tSize",
               args.size, "\tAngles", args.angles, "\tFormat", args.format,
               "\tScale", args.scale, "\tcomparison", args.compare,
               "\tnumber of cores", args.ncores, "\tnumber of columns",
               args.ncol, "\tnumber iterations", args.num_iter))

    if len(args.compare) > 0:
        args.ncol = 1
        args.scale = 1
        nitr = 1
        comparison = None
        for alg in args.compare:
            print("Reconstructing {} with {}...".format(args.phantom, alg))
            tmp = run(args.phantom, alg, args, get_recon=True)
            tmp = rescale_image(tmp, args.size, args.scale, transform=False)
            if comparison is None:
                comparison = image_comparison(len(args.compare), tmp.shape[0],
                                              tmp[0].shape[0], tmp[0].shape[1],
                                              image_quality["orig"])
            comparison.assign(alg, nitr, tmp)
            nitr += 1
        bname = get_basepath(args, algorithm, args.phantom)
        fname = os.path.join(bname, "stack_{}_".format(comparison.tagname()))
        dname = os.path.join(bname, "diff_{}_".format(comparison.tagname()))
        imgs = []
        imgs.extend(
            output_images(comparison.array, fname, args.format, args.scale,
                          args.ncol))
        imgs.extend(
            output_images(comparison.delta, dname, args.format, args.scale,
                          args.ncol))
    else:
        print("Reconstructing with {}...".format(args.algorithm))
        imgs = run(args.phantom, args.algorithm, args)

    # timing report to stdout
    print('{}\n'.format(manager))

    timemory.options.output_dir = "{}/{}/{}".format(args.output_dir,
                                                    args.phantom, algorithm)
    timemory.options.set_report("run_tomopy.out")
    timemory.options.set_serial("run_tomopy.json")
    manager.report()

    # provide timing plots
    try:
        timemory.plotting.plot(files=[timemory.options.serial_filename],
                               echo_dart=True,
                               output_dir=timemory.options.output_dir)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide results to dashboard
    try:
        for i in range(0, len(imgs)):
            img_base = "{}_{}_stack_{}".format(args.phantom, algorithm, i)
            img_name = os.path.basename(imgs[i]).replace(
                ".{}".format(args.format),
                "").replace("stack_{}_".format(algorithm), img_base)
            img_type = args.format
            img_path = imgs[i]
            timemory.plotting.echo_dart_tag(img_name, img_path, img_type)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide ASCII results
    try:
        notes = manager.write_ctest_notes(directory="{}/{}/{}".format(
            args.output_dir, args.phantom, algorithm))
        print('"{}" wrote CTest notes file : {}'.format(__file__, notes))
    except Exception as e:
        print("Exception - {}".format(e))
Пример #10
0
def main(args):

    global image_quality

    manager = timemory.manager()

    algorithm = args.algorithm
    if len(args.compare) > 0:
        algorithm = "comparison"

    print(("\nArguments:\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n"
          "{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n").format(
          "\tPhantom", args.phantom,
          "\tAlgorithm", algorithm,
          "\tSize", args.size,
          "\tAngles", args.angles,
          "\tFormat", args.format,
          "\tScale", args.scale,
          "\tcomparison", args.compare,
          "\tnumber of cores", args.ncores,
          "\tnumber of columns", args.ncol,
          "\tnumber iterations", args.num_iter))

    if len(args.compare) > 0:
        args.ncol = 1
        args.scale = 1
        nitr = 1
        comparison = None
        for alg in args.compare:
            print("Reconstructing {} with {}...".format(args.phantom, alg))
            tmp = run(args.phantom, alg, args, get_recon=True)
            tmp = rescale_image(tmp, args.size, args.scale, transform=False)
            if comparison is None:
                comparison = image_comparison(
                    len(args.compare), tmp.shape[0], tmp[0].shape[0],
                    tmp[0].shape[1], image_quality["orig"]
                    )
            comparison.assign(alg, nitr, tmp)
            nitr += 1
        bname = get_basepath(args, algorithm, args.phantom)
        fname = os.path.join(bname, "stack_{}_".format(comparison.tagname()))
        dname = os.path.join(bname, "diff_{}_".format(comparison.tagname()))
        imgs = []
        imgs.extend(
            output_images(comparison.array, fname,
                          args.format, args.scale, args.ncol))
        imgs.extend(
            output_images(comparison.delta, dname,
                          args.format, args.scale, args.ncol))
    else:
        print("Reconstructing with {}...".format(args.algorithm))
        imgs = run(args.phantom, args.algorithm, args)

    # timing report to stdout
    print('{}\n'.format(manager))

    timemory.options.output_dir = "{}/{}/{}".format(
        args.output_dir, args.phantom, algorithm)
    timemory.options.set_report("run_tomopy.out")
    timemory.options.set_serial("run_tomopy.json")
    manager.report()

    # provide timing plots
    try:
        timemory.plotting.plot(files=[timemory.options.serial_filename],
                               echo_dart=True,
                               output_dir=timemory.options.output_dir)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide results to dashboard
    try:
        for i in range(0, len(imgs)):
            img_base = "{}_{}_stack_{}".format(args.phantom, algorithm, i)
            img_name = os.path.basename(imgs[i]).replace(
                ".{}".format(args.format), "").replace(
                "stack_{}_".format(algorithm), img_base)
            img_type = args.format
            img_path = imgs[i]
            timemory.plotting.echo_dart_tag(img_name, img_path, img_type)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide ASCII results
    try:
        notes = manager.write_ctest_notes(
            directory="{}/{}/{}".format(args.output_dir, args.phantom,
                                        algorithm))
        print('"{}" wrote CTest notes file : {}'.format(__file__, notes))
    except Exception as e:
        print("Exception - {}".format(e))
Пример #11
0
def main(phantom, algorithm, output_dir, angles, size, ncores, format, scale,
         ncol, compare, num_iter, subset, preserve_output_dir, partial,
         no_center):
    """
    Parameters
    ----------
    phantom : string
        The name of the phantom to use.
        default = "shepp2d"
        choices = ["baboon", "cameraman", "barbara", "checkerboard",
                    "lena", "peppers", "shepp2d", "shepp3d"]
    algorithm : string
        The name of the algorithm to test. Select the algorithm.
        default="sirt"
        choices = ['gridrec', 'art', 'fbp', 'bart', 'mlem', 'osem',
                    'sirt', 'ospml_hybrid', 'ospml_quad', 'pml_hybrid',
                    'pml_quad', 'tv', 'grad']
    output_dir : string
        The location of the output directory.
        default = "."
    angles : integer
        number of angles
        default = 1501
    size : integer
        size of image
        default = 512
    ncores : integer
        number of cores
    format : string
        output image format
        default = "png"
    scale : integer
        scale image by a positive factor
        default = 1
    ncol : integer
        Number of images per row
        default = 1
    compare: list of strings (arbitrary length)
        Generate comparison
        default = ["none"]
    num_iter : integer
        Number of iterations
        default = 50
    subset : tuple of integers of length 2
        Select subset (range) of slices (center enabled by default)
        default = (0, 48)
    preserve_output_dir : Boolean
        Do not clean up output directory
        default = False
    partial : Boolean
        Enable partial reconstruction of 3D data
        default = False
    no_center : Boolean
        When used with 'subset', do no center subset
        default = False
    Returns
    -------
    Either rec or imgs
    rec : np.ndarray
        The reconstructed image.
    imgs : list
        A list of the original, reconstructed, and difference image
    """

    print("using tomopy: {}".format(tomopy.__file__))

    global image_quality

    manager = timemory.manager()

    algorithms = [
        'gridrec', 'art', 'fbp', 'bart', 'mlem', 'osem', 'sirt',
        'ospml_hybrid', 'ospml_quad', 'pml_hybrid', 'pml_quad', 'tv', 'grad'
    ]

    if len(compare) == 1 and compare[0].lower() == "all":
        compare = list(algorithms)
    elif len(compare) == 1:
        compare = []

    if len(compare) > 0:
        algorithm = "comparison"

    if output_dir is None:
        output_dir = "."

    # unique output directory w.r.t. phantom
    adir = os.path.join(os.getcwd(), output_dir, phantom)
    # unique output directory w.r.t. phantom and extension
    if len(compare) > 0:
        adir = os.path.join(adir, "comparison")
    else:
        adir = os.path.join(adir, algorithm)

    if not preserve_output_dir:
        try:
            print("removing output from '{}' (if not '{}')...".format(
                adir, os.getcwd()))
            import shutil
            if os.path.exists(adir) and adir != os.getcwd():
                shutil.rmtree(adir)
                os.makedirs(adir)
        except:
            pass
    else:
        os.makedirs(adir)

    output_dir = os.path.abspath(output_dir)

    print(("\nArguments:\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n"
           "{} = {}\n{} = {}\n{} = {}\n{} = {}\n{} = {}\n").format(
               "\tPhantom", phantom, "\tAlgorithm", algorithm, "\tSize", size,
               "\tAngles", angles, "\tFormat", format, "\tScale", scale,
               "\tcomparison", compare, "\tnumber of cores", ncores,
               "\tnumber of columns", ncol, "\tnumber iterations", num_iter))

    if len(compare) > 0:
        ncol = 1
        scale = 1
        nitr = 1
        comparison = None
        for alg in compare:
            print("Reconstructing {} with {}...".format(phantom, alg))
            tmp = run(phantom=phantom,
                      algorithm=alg,
                      output_dir=output_dir,
                      size=size,
                      partial=partial,
                      subset=subset,
                      no_center=no_center,
                      angles=angles,
                      ncores=ncores,
                      num_iter=num_iter,
                      format=format,
                      scale=scale,
                      ncol=ncol,
                      get_recon=True)
            tmp = rescale_image(tmp, size, scale, transform=False)
            if comparison is None:
                comparison = image_comparison(len(compare), tmp.shape[0],
                                              tmp[0].shape[0], tmp[0].shape[1],
                                              image_quality["orig"])
            comparison.assign(alg, nitr, tmp)
            nitr += 1
        bname = get_basepath(output_dir=output_dir,
                             algorithm=algorithm,
                             phantom=phantom)
        fname = os.path.join(bname, "stack_{}_".format(comparison.tagname()))
        dname = os.path.join(bname, "diff_{}_".format(comparison.tagname()))
        imgs = []
        imgs.extend(output_images(comparison.array, fname, format, scale,
                                  ncol))
        imgs.extend(output_images(comparison.delta, dname, format, scale,
                                  ncol))
    else:
        print("Reconstructing with {}...".format(algorithm))
        imgs = run(phantom=phantom,
                   algorithm=algorithm,
                   output_dir=output_dir,
                   size=size,
                   partial=partial,
                   subset=subset,
                   no_center=no_center,
                   angles=angles,
                   ncores=ncores,
                   num_iter=num_iter,
                   format=format,
                   scale=scale,
                   ncol=ncol)

    # timing report to stdout
    print('{}\n'.format(manager))

    _dir = os.path.abspath(output_dir)
    timemory.options.output_dir = "{}/{}/{}".format(_dir, phantom, algorithm)
    timemory.options.set_report("run_tomopy.out")
    timemory.options.set_serial("run_tomopy.json")
    manager.report()

    # provide timing plots
    try:
        timemory.plotting.plot(files=[timemory.options.serial_filename],
                               echo_dart=True,
                               output_dir=timemory.options.output_dir)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide results to dashboard
    try:
        for i in range(0, len(imgs)):
            img_base = "{}_{}_stack_{}".format(phantom, algorithm, i)
            img_name = os.path.basename(imgs[i]).replace(
                ".{}".format(format),
                "").replace("stack_{}_".format(algorithm), img_base)
            img_type = format
            img_path = imgs[i]
            img_path = os.path.abspath(img_path)
            timemory.plotting.echo_dart_tag(img_name, img_path, img_type)
    except Exception as e:
        print("Exception - {}".format(e))

    # provide ASCII results
    try:
        notes = manager.write_ctest_notes(
            directory="{}/{}/{}".format(output_dir, phantom, algorithm))
        print('"{}" wrote CTest notes file : {}'.format(
            tomopy.__file__, notes))
    except Exception as e:
        print("Exception - {}".format(e))
Пример #12
0
def main(arg):

    import multiprocessing as mp
    default_ncores = mp.cpu_count()

    parser = argparse.ArgumentParser()
    parser.add_argument("fname",
                        help=("file name of a tmographic dataset: "
                              "/data/sample.h5"))
    parser.add_argument("--axis",
                        nargs='?',
                        type=str,
                        default="0",
                        help=("rotation axis location: 1024.0 "
                              "(default 1/2 image horizontal size)"))
    parser.add_argument("--type",
                        nargs='?',
                        type=str,
                        default="slice",
                        help="reconstruction type: full (default slice)")
    parser.add_argument("--nsino",
                        nargs='?',
                        type=restricted_float,
                        default=0.5,
                        help=("location of the sinogram used by slice "
                              "reconstruction (0 top, 1 bottom): 0.5 "
                              "(default 0.5)"))
    parser.add_argument("-a",
                        "--algorithm",
                        help="Select the algorithm",
                        default="gridrec",
                        choices=algorithms,
                        type=str)
    parser.add_argument("-n",
                        "--ncores",
                        help="number of cores",
                        default=default_ncores,
                        type=int)
    parser.add_argument("-f",
                        "--format",
                        help="output image format",
                        default="jpeg",
                        type=str)
    parser.add_argument("-S",
                        "--scale",
                        help="scale image by a positive factor",
                        default=1,
                        type=int)
    parser.add_argument("-c",
                        "--ncol",
                        help="Number of images per row",
                        default=1,
                        type=int)
    parser.add_argument("-i",
                        "--num-iter",
                        help="Number of iterations",
                        default=1,
                        type=int)
    parser.add_argument("-o",
                        "--output-dir",
                        help="Output directory",
                        default=None,
                        type=str)
    parser.add_argument("-g",
                        "--grainsize",
                        help="Granularity of slices to compute",
                        default=16,
                        type=int)

    args = parser.parse_args()

    print("\nargs: {}\n".format(args))

    if args.output_dir is None:
        fpath = os.path.basename(os.path.dirname(args.fname))
        args.output_dir = os.path.join(fpath + "_output", args.algorithm)
        if not os.path.exists(args.output_dir):
            os.makedirs(args.output_dir)

    manager = timemory.manager()

    # Set path to the micro-CT data to reconstruct.
    fname = args.fname

    rot_center = float(args.axis)

    # Set default rotation axis location
    if rot_center == 0:
        data_size = get_dx_dims(fname, 'data')
        rot_center = data_size[2] / 2

    nsino = float(args.nsino)

    blocked_views = None

    slice = False
    if args.type == "slice":
        slice = True

    imgs = []
    if os.path.isfile(fname):
        if slice:
            imgs = rec_slice(fname, nsino, rot_center, args, blocked_views)
        else:
            imgs = rec_full(fname, rot_center, args, blocked_views,
                            args.grainsize)

    else:
        print("File Name does not exist: ", fname)

    # timing report to stdout
    print('{}'.format(manager))

    fpath = args.output_dir
    timemory.options.output_dir = fpath
    timemory.options.set_report("run_tomopy.out")
    timemory.options.set_serial("run_tomopy.json")
    manager.report()
    # provide timing plots
    try:
        print("\nPlotting TiMemory results...\n")
        timemory.plotting.plot(files=[timemory.options.serial_filename],
                               echo_dart=True,
                               output_dir=timemory.options.output_dir)
    except Exception as e:
        print("Exception [timemory.plotting] - {}".format(e))
    # provide results to dashboard
    try:
        print("\nEchoing dart tags...\n")
        for i in range(0, len(imgs)):
            print("imgs[{}] = {}".format(i, imgs[i]))
            img_type = args.format
            print("Image name: {}".format(img_type))
            img_name = os.path.basename(imgs[i]).replace(
                ".{}".format(args.format), "")
            print("Image name: {}".format(img_name))
            img_path = imgs[i]
            print("name: {}, type: {}, path: {}".format(
                img_name, img_type, img_path))
            timemory.plotting.echo_dart_tag(img_name, img_path, img_type)
    except Exception as e:
        print("Exception [echo_dart_tag] - {}".format(e))
    # provide ASCII results
    try:
        print("\nWriting notes...\n")
        notes = manager.write_ctest_notes(directory=fpath)
        print('"{}" wrote CTest notes file : {}'.format(__file__, notes))
    except Exception as e:
        print("Exception [write_ctest_notes] - {}".format(e))
Пример #13
0
 def setUp(self):
     self.output_dir = "test_output"
     timemory.settings.output_path = self.output_dir
     timemory.settings.enabled = True
     timemory.settings.json_output = True
     self.manager = timemory.manager()
Пример #14
0
 def get_pointer_max():
     return timemory.manager().get_max_depth()
Пример #15
0
    # enable stdout buffer
    result.buffer = True

    # run all tests in timTestSuite, use result object to store results
    print("\n============= Tests Stdout =============\n")
    # run the tests
    timTestSuite.run(result)

    # finalize tracing
    tim.trace.finalize()

    # finalize timemory
    tim.finalize()

    # print the results
    print("\n============= Results =============\n")
    print("{}\n".format(result))
    return result


# run all tests
if __name__ == "__main__":
    man = tim.manager()
    result = run_all_tests()
    man.write_ctest_notes("./python-testing")
    if result.errors is not None:
        nerr = len(result.errors)
        sys.exit(nerr)
    else:
        sys.exit(0)