Пример #1
0
def export_uhs_xml(ekey, dstore):
    oq = dstore['oqparam']
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    pgetter = PmapGetter(dstore, rlzs_assoc)
    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)
Пример #2
0
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)
Пример #3
0
def export_uhs_xml(ekey, dstore):
    oq = dstore['oqparam']
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    R = len(rlzs_assoc.realizations)
    sitemesh = get_mesh(dstore['sitecol'].complete)
    key, kind, fmt = get_kkf(ekey)
    fnames = []
    periods = [imt.period for imt in oq.imt_periods()]
    for kind in oq.get_kinds(kind, R):
        metadata = get_metadata(rlzs_assoc.realizations, kind)
        uhs = extract(dstore, 'uhs?kind=' + kind)[kind]
        for p, poe in enumerate(oq.poes):
            fname = hazard_curve_name(dstore, (key, fmt), kind + '-%s' % poe)
            writer = hazard_writers.UHSXMLWriter(
                fname,
                periods=periods,
                poe=poe,
                investigation_time=oq.investigation_time,
                **metadata)
            data = []
            for site, curve in zip(sitemesh, uhs):
                data.append(UHS(curve[:, p], Location(site)))
            writer.serialize(data)
            fnames.append(fname)
    return sorted(fnames)
Пример #4
0
    def test_serialize_mean(self):
        del self.metadata['smlt_path']
        del self.metadata['gsimlt_path']
        self.metadata['statistics'] = 'mean'

        writer = writers.UHSXMLWriter(path, **self.metadata)
        writer.serialize(self.data)
        utils.assert_xml_equal(self.expected_mean_xml, path)
Пример #5
0
    def test_serialize_quantile(self):
        del self.metadata['smlt_path']
        del self.metadata['gsimlt_path']
        self.metadata['statistics'] = 'quantile'
        self.metadata['quantile_value'] = 0.95

        writer = writers.UHSXMLWriter(path, **self.metadata)
        writer.serialize(self.data)
        utils.assert_xml_equal(self.expected_quantile_xml, path)
Пример #6
0
    def test_serialize(self):
        try:
            _, path = tempfile.mkstemp()
            writer = writers.UHSXMLWriter(path, **self.metadata)

            writer.serialize(self.data)

            utils.assert_xml_equal(self.expected_xml, path)
        finally:
            os.unlink(path)
Пример #7
0
    def test_serialize_mean(self):
        del self.metadata['smlt_path']
        del self.metadata['gsimlt_path']
        self.metadata['statistics'] = 'mean'

        try:
            _, path = tempfile.mkstemp()
            writer = writers.UHSXMLWriter(path, **self.metadata)

            writer.serialize(self.data)

            utils.assert_xml_equal(self.expected_mean_xml, path)
        finally:
            os.unlink(path)
Пример #8
0
def export_uh_spectra_xml(key, output, target):
    """
    Export the specified UHS ``output`` to the ``target``.

    :param output:
        :class:`openquake.engine.db.models.Output` with an `output_type` of
        `uh_spectra`.
    :param str target:
        Destination directory location for exported files.

    :returns:
        A list containing the exported file name.
    """
    uhs = models.UHS.objects.get(output=output)
    haz_calc = output.oq_job

    dest = _get_result_export_dest(haz_calc.id, target, output.uh_spectra)

    if uhs.lt_realization is not None:
        lt_rlz = uhs.lt_realization
        smlt_path = core.LT_PATH_JOIN_TOKEN.join(lt_rlz.sm_lt_path)
        gsimlt_path = core.LT_PATH_JOIN_TOKEN.join(lt_rlz.gsim_lt_path)
    else:
        smlt_path = None
        gsimlt_path = None

    metadata = {
        'quantile_value': uhs.quantile,
        'statistics': uhs.statistics,
        'smlt_path': smlt_path,
        'gsimlt_path': gsimlt_path,
        'poe': uhs.poe,
        'periods': uhs.periods,
        'investigation_time': uhs.investigation_time,
    }

    writer = hazard_writers.UHSXMLWriter(dest, **metadata)
    writer.serialize(uhs)

    return dest
Пример #9
0
    def test_serialize(self):
        writer = writers.UHSXMLWriter(path, **self.metadata)

        writer.serialize(self.data)

        utils.assert_xml_equal(self.expected_xml, path)