def extract_ruptures(dstore, what): """ Extract some information about the ruptures, including the boundary. Example: http://127.0.0.1:8800/v1/calc/30/extract/ruptures?min_mag=6 """ qdict = parse(what) if 'min_mag' in qdict: [min_mag] = qdict['min_mag'] else: min_mag = 0 bio = io.StringIO() first = True trts = list(dstore.getitem('full_lt').attrs['trts']) for rgetter in getters.gen_rgetters(dstore): rups = [ rupture._get_rupture(proxy.rec, proxy.geom, rgetter.trt) for proxy in rgetter.get_proxies(min_mag) ] arr = rupture.to_csv_array(rups) if first: header = None comment = dict(trts=trts) first = False else: header = 'no-header' comment = None writers.write_csv(bio, arr, header=header, comment=comment) return bio.getvalue()
def _get_ebruptures(fname, conv=None, ses_seed=None): """ :param fname: path to a rupture file (XML or CSV) :param conv: RuptureConverter instanc, used for XML ruptures :param ses_seed: used for XML ruptures :returns: a list of one or more EBRuptures """ if fname.endswith('.xml'): [rup_node] = nrml.read(fname) rup = conv.convert_node(rup_node) rup.tectonic_region_type = '*' # no TRT for scenario ruptures rup.rup_id = ses_seed ebrs = [EBRupture(rup, 'NA', 0, id=rup.rup_id, scenario=True)] return ebrs assert fname.endswith('.csv'), fname aw = get_ruptures(fname) ebrs = [] for i, rec in enumerate(aw.array): rupture = _get_rupture(rec, aw.geoms[i], aw.trts[rec['trt_smr']]) ebr = EBRupture(rupture, rec['source_id'], rec['trt_smr'], rec['n_occ'], rec['id'], rec['e0']) ebrs.append(ebr) return ebrs