def show(what='contents', calc_id=-1, extra=()): """ Show the content of a datastore (by default the last one). """ datadir = datastore.get_datadir() if what == 'all': # show all if not os.path.exists(datadir): return rows = [] for calc_id in datastore.get_calc_ids(datadir): try: ds = read(calc_id) oq = ds['oqparam'] cmode, descr = oq.calculation_mode, oq.description except: # invalid datastore file, or missing calculation_mode # and description attributes, perhaps due to a manual kill f = os.path.join(datadir, 'calc_%s.hdf5' % calc_id) logging.warn('Unreadable datastore %s', f) continue else: rows.append((calc_id, cmode, descr.encode('utf-8'))) for row in sorted(rows, key=lambda row: row[0]): # by calc_id print('#%d %s: %s' % row) return ds = read(calc_id) # this part is experimental if what == 'rlzs' and 'poes' in ds: min_value = 0.01 # used in rmsep getter = getters.PmapGetter(ds) sitecol = ds['sitecol'] pmaps = getter.get_pmaps(sitecol.sids) weights = [rlz.weight for rlz in getter.rlzs] mean = stats.compute_pmap_stats(pmaps, [numpy.mean], weights) dists = [] for rlz, pmap in zip(getter.rlzs, pmaps): dist = rmsep(mean.array, pmap.array, min_value) dists.append((dist, rlz)) print('Realizations in order of distance from the mean curves') for dist, rlz in sorted(dists): print('%s: rmsep=%s' % (rlz, dist)) elif view.keyfunc(what) in view: print(view(what, ds)) elif what.split('/', 1)[0] in extract: print(extract(ds, what, *extra)) elif what in ds: obj = ds[what] if hasattr(obj, 'value'): # an array print(write_csv(io.BytesIO(), obj.value).decode('utf8')) else: print(obj) else: print('%s not found' % what) ds.close()
def main(what='contents', calc_id: str_or_int = -1, extra=()): """ Show the content of a datastore (by default the last one). """ datadir = datastore.get_datadir() if what == 'all': # show all if not os.path.exists(datadir): return rows = [] for calc_id in datastore.get_calc_ids(datadir): try: ds = datastore.read(calc_id) oq = ds['oqparam'] cmode, descr = oq.calculation_mode, oq.description except Exception: # invalid datastore file, or missing calculation_mode # and description attributes, perhaps due to a manual kill f = os.path.join(datadir, 'calc_%s.hdf5' % calc_id) logging.warning('Unreadable datastore %s', f) continue else: rows.append((calc_id, cmode, descr.encode('utf-8'))) for row in sorted(rows, key=lambda row: row[0]): # by calc_id print('#%d %s: %s' % row) return ds = datastore.read(calc_id) # this part is experimental if view.keyfunc(what) in view: print(view(what, ds)) elif what.split('/', 1)[0] in extract: obj = extract(ds, what, *extra) if isinstance(obj, hdf5.ArrayWrapper): print_(obj) elif hasattr(obj, 'dtype') and obj.dtype.names: print(writers.write_csv(io.StringIO(), obj)) else: print(obj) elif what in ds: obj = ds.getitem(what) if '__pdcolumns__' in obj.attrs: df = ds.read_df(what) print(df.sort_values(df.columns[0])) elif hasattr(obj, 'items'): # is a group of datasets print(obj) else: # is a single dataset obj.refresh() # for SWMR mode print_(hdf5.ArrayWrapper.from_(obj)) else: print('%s not found' % what) ds.close()
def show(what, calc_id=-1): """ Show the content of a datastore (by default the last one). """ if what == 'all': # show all if not os.path.exists(datastore.DATADIR): return rows = [] for calc_id in datastore.get_calc_ids(datastore.DATADIR): try: ds = datastore.read(calc_id) oq = ds['oqparam'] cmode, descr = oq.calculation_mode, oq.description except: # invalid datastore file, or missing calculation_mode # and description attributes, perhaps due to a manual kill f = os.path.join(datastore.DATADIR, 'calc_%s.hdf5' % calc_id) logging.warn('Unreadable datastore %s', f) continue else: rows.append((calc_id, cmode, descr.encode('utf-8'))) for row in sorted(rows, key=lambda row: row[0]): # by calc_id print('#%d %s: %s' % row) return ds = read(calc_id) # this part is experimental if what == 'rlzs' and 'hcurves' in ds: min_value = 0.01 # used in rmsep curves_by_rlz, mean_curves = get_hcurves_and_means(ds) dists = [] for rlz, curves in curves_by_rlz.items(): dist = sum(rmsep(mean_curves[imt], curves[imt], min_value) for imt in mean_curves.dtype.fields) dists.append((dist, rlz)) print('Realizations in order of distance from the mean curves') for dist, rlz in sorted(dists): print('%s: rmsep=%s' % (rlz, dist)) elif view.keyfunc(what) in view: print(view(what, ds)) elif what in ds: obj = ds[what] if hasattr(obj, 'value'): # an array print(write_csv(io.StringIO(), obj.value)) else: print(obj) else: print('%s not found' % what) ds.close()
def show(what='contents', calc_id=-1, extra=()): """ Show the content of a datastore (by default the last one). """ datadir = datastore.get_datadir() if what == 'all': # show all if not os.path.exists(datadir): return rows = [] for calc_id in datastore.get_calc_ids(datadir): try: ds = util.read(calc_id) oq = ds['oqparam'] cmode, descr = oq.calculation_mode, oq.description except Exception: # invalid datastore file, or missing calculation_mode # and description attributes, perhaps due to a manual kill f = os.path.join(datadir, 'calc_%s.hdf5' % calc_id) logging.warning('Unreadable datastore %s', f) continue else: rows.append((calc_id, cmode, descr.encode('utf-8'))) for row in sorted(rows, key=lambda row: row[0]): # by calc_id print('#%d %s: %s' % row) return ds = util.read(calc_id) # this part is experimental if view.keyfunc(what) in view: print(view(what, ds)) elif what.split('/', 1)[0] in extract: print(extract(ds, what, *extra)) elif what in ds: obj = ds.getitem(what) if hasattr(obj, 'items'): # is a group of datasets print(obj) else: # is a single dataset obj.refresh() # for SWMR mode aw = hdf5.ArrayWrapper.from_(obj) if hasattr(aw, 'shape_descr'): print(rst_table(aw.to_table())) else: print(write_csv(io.BytesIO(), aw.array).decode('utf8')) else: print('%s not found' % what) ds.close()