How to use the timemory.util function in timemory

To help you get started, we’ve selected a few timemory examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tomopy / tomopy / benchmarking / pyctest_tomopy_phantom.py View on Github external
os.makedirs(adir)
        except:
            pass
    else:
        try:
            import shutil
            if os.path.exists(adir):
                shutil.rmtree(adir)
                os.makedirs(adir)
        except:
            pass

    ret = 0
    try:

        with timemory.util.timer('\nTotal time for "{}"'.format(__file__)):
            main(args)

    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exception(exc_type, exc_value, exc_traceback, limit=5)
        print('Exception - {}'.format(e))
        ret = 2

    sys.exit(ret)
github tomopy / tomopy / benchmarking / pyctest_tomopy_phantom.py View on Github external
dname = os.path.join(bname, "diff_{}_".format(algorithm))

    prj, ang, obj = generate(phantom, args.size, args.angles)

    # always add algorithm
    _kwargs = {"algorithm": algorithm}

    # assign number of cores
    _kwargs["ncore"] = ncores

    # don't assign "num_iter" if gridrec or fbp
    if algorithm not in ["fbp", "gridrec"]:
        _kwargs["num_iter"] = args.num_iter

    print("kwargs: {}".format(_kwargs))
    with timemory.util.auto_timer("[tomopy.recon(algorithm='{}')]".format(
                                  algorithm)):
        rec = tomopy.recon(prj, ang, **_kwargs)

    obj = normalize(obj)
    rec = normalize(rec)

    rec = trim_border(rec, rec.shape[0],
                      rec[0].shape[0] - obj[0].shape[0],
                      rec[0].shape[1] - obj[0].shape[1])

    label = "{} @ {}".format(algorithm.upper(), phantom.upper())

    quantify_difference(label, obj, rec)

    if "orig" not in image_quality:
        image_quality["orig"] = obj
github tomopy / tomopy / benchmarking / pyctest_tomopy_phantom.py View on Github external
def generate(phantom="shepp3d", nsize=512, nangles=360):

    with timemory.util.auto_timer("[tomopy.misc.phantom.{}]".format(phantom)):
        obj = getattr(tomopy.misc.phantom, phantom)(size=nsize)
    with timemory.util.auto_timer("[tomopy.angles]"):
        ang = tomopy.angles(nangles)
    with timemory.util.auto_timer("[tomopy.project]"):
        prj = tomopy.project(obj, ang)

    return [prj, ang, obj]
github tomopy / tomopy / benchmarking / pyctest_tomopy_utils.py View on Github external
@timemory.util.auto_timer()
def output_images(rec, fpath, format="jpeg", scale=1, ncol=1):

    imgs = []
    nitr = 0
    nimages = rec.shape[0]
    rec_i = None
    fname = "{}".format(fpath)

    if nimages < ncol:
        ncol = nimages

    rec_n = rec.copy()
    if scale > 1:
        rescale_image(rec, nimages, scale)

    print("Image size: {} x {} x {}".format(
github NERSC / timemory / python / unit_testing.py View on Github external
timing.toggle(True)
        tman.clear()

        def create_timer(n):
            autotimer = timing.auto_timer('{}'.format(n))
            fibonacci(30)
            if n < 8:
                create_timer(n + 1)

        ntimers = 4
        timing.set_max_depth(ntimers)

        create_timer(0)

        timing.util.opts.set_report(join(self.outdir, "timing_depth.out"))
        timing.util.opts.set_serial(join(self.outdir, "timing_depth.json"))
        tman.report()

        self.assertEqual(tman.size(), ntimers)
github tomopy / tomopy / source / tomopy / misc / benchmark.py View on Github external
@timemory.util.auto_timer()
def output_image(image, fname):
    """Save an image and check that it exists afterward."""
    pylab.imsave(fname, image, cmap='gray')

    if not os.path.exists(fname):
        print("  ##################### WARNING #####################")
        print("  --> No image file at @ '{}' (expected) ...".format(fname))
github tomopy / tomopy / benchmarking / rec.py View on Github external
@timemory.util.auto_timer()
def reconstruct(h5fname, sino, rot_center, args, blocked_views=None):

    # Read APS 32-BM raw data.
    proj, flat, dark, theta = dxchange.read_aps_32id(h5fname, sino=sino)

    # Manage the missing angles:
    if blocked_views is not None:
        print("Blocked Views: ", blocked_views)
        proj = np.concatenate((proj[0:blocked_views[0], :, :],
                               proj[blocked_views[1]+1:-1, :, :]), axis=0)
        theta = np.concatenate((theta[0:blocked_views[0]],
                                theta[blocked_views[1]+1: -1]))

    # Flat-field correction of raw data.
    data = tomopy.normalize(proj, flat, dark, cutoff=1.4)
github NERSC / timemory / examples / nested.py View on Github external
func_1(nfib)
    func_2(nfib)
    func_3(nfib)


#------------------------------------------------------------------------------#
if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("-n", "--nfib",
                        help="Number of fibonacci calculations",
                        default=15, type=int)
    parser.add_argument("-s", "--size",
                        help="Size of array allocations",
                        default=array_size, type=int)
    args = tim.util.add_arguments_and_parse(parser)
    array_size = args.size

    print ('')
    try:
        t = tim.timer("Total time")
        t.start()
        main(args.nfib)
        print ('')
        tman = tim.timing_manager()
        tman.report()
        tman.serialize('output.json')
        print ('')
        _data = tim.util.read(tman.json())
        _data.title = tim.FILE(noquotes=True)
        _data.filename = tim.FILE(noquotes=True)
        tim.util.plot(data = [_data], files = ["output.json"], display=False)
github NERSC / timemory / examples / nested.py View on Github external
array_size = args.size

    print ('')
    try:
        t = tim.timer("Total time")
        t.start()
        main(args.nfib)
        print ('')
        tman = tim.timing_manager()
        tman.report()
        tman.serialize('output.json')
        print ('')
        _data = tim.util.read(tman.json())
        _data.title = tim.FILE(noquotes=True)
        _data.filename = tim.FILE(noquotes=True)
        tim.util.plot(data = [_data], files = ["output.json"], display=False)
        t.stop()
        print ('')
        t.report()
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exception(exc_type, exc_value, exc_traceback, limit=5)
        print ('Exception - {}'.format(e))

    print ('')