def export_uhs_xml(ekey, dstore): oq = dstore['oqparam'] rlzs_assoc = dstore['csm_info'].get_rlzs_assoc() pgetter = calc.PmapGetter(dstore) sitemesh = get_mesh(dstore['sitecol'].complete) key, kind, fmt = get_kkf(ekey) fnames = [] periods = [imt for imt in oq.imtls if imt.startswith('SA') or imt == 'PGA'] for kind, hcurves in pgetter.items(kind): metadata = get_metadata(rlzs_assoc.realizations, kind) _, periods = calc.get_imts_periods(oq.imtls) uhs = calc.make_uhs(hcurves, oq.imtls, oq.poes, len(sitemesh)) for poe in oq.poes: fname = hazard_curve_name(dstore, (key, fmt), kind + '-%s' % poe, rlzs_assoc) writer = hazard_writers.UHSXMLWriter( fname, periods=periods, poe=poe, investigation_time=oq.investigation_time, **metadata) data = [] for site, curve in zip(sitemesh, uhs[str(poe)]): data.append(UHS(curve, Location(site))) writer.serialize(data) fnames.append(fname) return sorted(fnames)
def make_figure(indices, n_sites, imtls, poes, pmaps): """ :param indices: the indices of the sites under analysis :param n_sites: total number of sites :param imtls: DictArray with the IMTs and levels :param poes: PoEs used to compute the hazard maps :param pmaps: a list of probability maps per realization """ # NB: matplotlib is imported inside since it is a costly import import matplotlib.pyplot as plt fig = plt.figure() n_poes = len(poes) uhs_by_rlz = [calc.make_uhs(pmap, imtls, poes, n_sites) for pmap in pmaps] _, periods = calc.get_imts_periods(imtls) for i, site in enumerate(indices): for j, poe in enumerate(poes): ax = fig.add_subplot(len(indices), n_poes, i * n_poes + j + 1) ax.grid(True) ax.set_xlim([periods[0], periods[-1]]) ax.set_xlabel( 'UHS on site %d, poe=%s, period in seconds' % (site, poe)) if j == 0: # set Y label only on the leftmost graph ax.set_ylabel('SA') for r, all_uhs in enumerate(uhs_by_rlz): uhs = list(all_uhs[str(poe)][site]) ax.plot(periods, uhs, label=r) plt.legend() return plt
def export_uhs_xml(ekey, dstore): oq = dstore['oqparam'] rlzs_assoc = dstore['csm_info'].get_rlzs_assoc() sitemesh = dstore['sitemesh'].value key, fmt = ekey fnames = [] periods = [imt for imt in oq.imtls if imt.startswith('SA') or imt == 'PGA'] for kind, hmaps in dstore['hmaps'].items(): metadata = get_metadata(rlzs_assoc.realizations, kind) _, periods = calc.get_imts_periods(oq.imtls) uhs = calc.make_uhs(hmaps, oq.imtls, oq.poes) for poe in oq.poes: poe_str = 'poe~%s' % poe fname = hazard_curve_name( dstore, ekey, kind + '-%s' % poe, rlzs_assoc, oq.number_of_logic_tree_samples) writer = hazard_writers.UHSXMLWriter( fname, periods=periods, poe=poe, investigation_time=oq.investigation_time, **metadata) data = [] for site, curve in zip(sitemesh, uhs[poe_str]): data.append(UHS(curve, Location(site))) writer.serialize(data) fnames.append(fname) return sorted(fnames)
def export_uhs_xml(ekey, dstore): oq = dstore['oqparam'] rlzs_assoc = dstore['csm_info'].get_rlzs_assoc() sitemesh = get_mesh(dstore['sitecol']) key, fmt = ekey fnames = [] periods = [imt for imt in oq.imtls if imt.startswith('SA') or imt == 'PGA'] for kind in dstore['hcurves']: hcurves = dstore['hcurves/' + kind] metadata = get_metadata(rlzs_assoc.realizations, kind) _, periods = calc.get_imts_periods(oq.imtls) uhs = calc.make_uhs(hcurves, oq.imtls, oq.poes, len(sitemesh)) for poe in oq.poes: fname = hazard_curve_name( dstore, ekey, kind + '-%s' % poe, rlzs_assoc) writer = hazard_writers.UHSXMLWriter( fname, periods=periods, poe=poe, investigation_time=oq.investigation_time, **metadata) data = [] for site, curve in zip(sitemesh, uhs[str(poe)]): data.append(UHS(curve, Location(site))) writer.serialize(data) fnames.append(fname) return sorted(fnames)