def export_uhs_xml(ekey, dstore): oq = OqParam.from_(dstore.attrs) rlzs_assoc = dstore['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_hcurves_csv(ekey, dstore): """ Exports the hazard curves into several .csv files :param ekey: export key, i.e. a pair (datastore key, fmt) :param dstore: datastore object """ oq = OqParam.from_(dstore.attrs) rlzs_assoc = dstore['rlzs_assoc'] sitecol = dstore['sitecol'] sitemesh = dstore['sitemesh'] key, fmt = ekey fnames = [] for kind, hcurves in dstore['hmaps' if key == 'uhs' else key].items(): fname = hazard_curve_name(dstore, ekey, kind, rlzs_assoc, oq.number_of_logic_tree_samples) if key == 'uhs': uhs_curves = calc.make_uhs(hcurves, oq.imtls, oq.poes) write_csv(fname, util.compose_arrays(sitemesh, uhs_curves)) elif key == 'hmaps': write_csv(fname, util.compose_arrays(sitemesh, hcurves)) else: export_hazard_curves_csv(ekey, fname, sitecol, hcurves, oq.imtls) fnames.append(fname) return sorted(fnames)
def export_hcurves_csv(ekey, dstore): """ Exports the hazard curves into several .csv files :param ekey: export key, i.e. a pair (datastore key, fmt) :param dstore: datastore object """ oq = dstore['oqparam'] rlzs_assoc = dstore['csm_info'].get_rlzs_assoc() sitecol = dstore['sitecol'] sitemesh = dstore['sitemesh'] key, fmt = ekey fnames = [] items = dstore['hmaps' if key == 'uhs' else key].items() for kind, hcurves in sorted(items): fname = hazard_curve_name( dstore, ekey, kind, rlzs_assoc, oq.number_of_logic_tree_samples) if key == 'uhs': uhs_curves = calc.make_uhs(hcurves, oq.imtls, oq.poes) write_csv(fname, util.compose_arrays(sitemesh, uhs_curves)) elif key == 'hmaps': write_csv(fname, util.compose_arrays(sitemesh, hcurves)) else: export_hazard_curves_csv(ekey, fname, sitecol, hcurves, oq.imtls) fnames.append(fname) return sorted(fnames)
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 store_curves(self, kind, curves, rlz=None): """ Store all kind of curves, optionally computing maps and uhs curves. :param kind: the kind of curves to store :param curves: an array of N curves to store :param rlz: hazard realization, if any """ if not self.persistent: # do nothing return oq = self.oqparam self._store('hcurves/' + kind, curves, rlz) if oq.hazard_maps or oq.uniform_hazard_spectra: # hmaps is a composite array of shape (N, P) hmaps = self.hazard_maps(curves) if oq.hazard_maps: self._store('hmaps/' + kind, hmaps, rlz, poes=oq.poes) if oq.uniform_hazard_spectra: # uhs is an array of shape (N, I, P) self._store('uhs/' + kind, calc.make_uhs(hmaps), rlz, poes=oq.poes)