Esempio n. 1
0
def extract(what, calc_id, webapi=True):
    """
    Extract an output from the datastore and save it into an .hdf5 file.
    By default uses the WebAPI, otherwise the extraction is done locally.
    """
    with performance.Monitor('extract', measuremem=True) as mon:
        if webapi:
            obj = WebExtractor(calc_id).get(what)
        else:
            obj = Extractor(calc_id).get(what)
        fname = '%s_%d.hdf5' % (what.replace('/', '-').replace('?',
                                                               '-'), calc_id)
        obj.save(fname)
        print('Saved', fname)
    if mon.duration > 1:
        print(mon)
Esempio n. 2
0
def extract(what, calc_id=-1, webapi=True, local=False):
    """
    Extract an output from the datastore and save it into an .hdf5 file.
    By default uses the WebAPI, otherwise the extraction is done locally.
    """
    with performance.Monitor('extract', measuremem=True) as mon:
        if local:
            obj = WebExtractor(calc_id, 'http://localhost:8800', '').get(what)
        elif webapi:
            obj = WebExtractor(calc_id).get(what)
        else:
            obj = Extractor(calc_id).get(what)
        w = what.replace('/', '-').replace('?', '-')
        if not obj.shape:  # is a dictionary of arrays
            fname = '%s_%d.txt' % (w, calc_id)
            open(fname, 'w').write(obj.toml())
        else:  # a regular ArrayWrapper
            fname = '%s_%d.hdf5' % (w, calc_id)
            obj.save(fname)
        print('Saved', fname)
    if mon.duration > 1:
        print(mon)