示例#1
0
def export_disagg_matrix_xml(key, output, target):
    """
    Export disaggregation histograms to the ``target``.

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

    :returns:
        A list of exported file name (including the absolute path to each
        file).
    """
    # We expect 1 result per `Output`
    [disagg_result] = models.DisaggResult.objects.filter(output=output)
    lt_rlz = disagg_result.lt_realization
    haz_calc = output.oq_job

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

    writer_kwargs = dict(
        investigation_time=disagg_result.investigation_time,
        imt=disagg_result.imt,
        lon=disagg_result.location.x,
        lat=disagg_result.location.y,
        sa_period=disagg_result.sa_period,
        sa_damping=disagg_result.sa_damping,
        mag_bin_edges=disagg_result.mag_bin_edges,
        dist_bin_edges=disagg_result.dist_bin_edges,
        lon_bin_edges=disagg_result.lon_bin_edges,
        lat_bin_edges=disagg_result.lat_bin_edges,
        eps_bin_edges=disagg_result.eps_bin_edges,
        tectonic_region_types=disagg_result.trts,
        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),
    )

    writer = hazard_writers.DisaggXMLWriter(dest, **writer_kwargs)

    data = (_DisaggMatrix(disagg_result.matrix[i], dim_labels,
                          disagg_result.poe, disagg_result.iml)
            for i, dim_labels in enumerate(disagg.pmf_map))

    writer.serialize(data)

    return dest
示例#2
0
 def test_serialize(self):
     writer = writers.DisaggXMLWriter(path, **self.metadata)
     writer.serialize(self.data)
     check_equal(__file__, 'expected_disagg.xml', path)