def compute_mean_hazard_maps(job):
    """Compute mean hazard maps using as input all the
    pre computed mean hazard curves.

    The POES_HAZARD_MAPS parameter in the configuration file specifies
    all the values used in the computation.
    """

    poes = _extract_values_from_config(job, POES_PARAM_NAME)

    LOG.debug("[MEAN_HAZARD_MAPS] List of POEs is %s" % poes)

    # get all the pre computed mean curves
    pattern = "%s*%s*" % (kvs.tokens.MEAN_HAZARD_CURVE_KEY_TOKEN, job.id)
    mean_curves = kvs.mget_decoded(pattern)

    LOG.debug("[MEAN_HAZARD_MAPS] Found %s pre computed mean curves"
            % len(mean_curves))

    keys = []
    for poe in poes:
        for mean_curve in mean_curves:
            site = shapes.Site(mean_curve["site_lon"],
                               mean_curve["site_lat"])

            key = kvs.tokens.mean_hazard_map_key(
                    job.id, site, poe)
            keys.append(key)

            _store_iml_for(mean_curve, key, job, poe)

    return keys
Exemple #2
0
def curves_at(job_id, site):
    """Return all the json deserialized hazard curves for
    a single site (different realizations).

    :param job_id: the id of the job.
    :type job_id: integer
    :param site: site where the curves are computed.
    :type site: :py:class:`shapes.Site` object
    :returns: the hazard curves.
    :rtype: list of :py:class:`dict` with the following keys:
        ***site_lat***: latitude of the site
        ***site_lon***: longitude of the site
        ***curve***: list of :py:class:`dict` with the following keys:
            ***x***: the x value (Intensity Measure Level) of the curve
            ***y***: the y value (Probability of Exceedance) of the curve
    """

    pattern = "%s*%s*%s" % (kvs.tokens.HAZARD_CURVE_KEY_TOKEN, job_id,
                            site.hash())

    curves = []
    raw_curves = kvs.mget_decoded(pattern)

    for raw_curve in raw_curves:
        curves.append(raw_curve["curve"])

    return curves
Exemple #3
0
def curves_at(job_id, site):
    """Return all the json deserialized hazard curves for
    a single site (different realizations).

    :param job_id: the id of the job.
    :type job_id: integer
    :param site: site where the curves are computed.
    :type site: :py:class:`shapes.Site` object
    :returns: the hazard curves.
    :rtype: list of :py:class:`dict` with the following keys:
        ***site_lat***: latitude of the site
        ***site_lon***: longitude of the site
        ***curve***: list of :py:class:`dict` with the following keys:
            ***x***: the x value (Intensity Measure Level) of the curve
            ***y***: the y value (Probability of Exceedance) of the curve
    """

    pattern = "%s*%s*%s" % (
        kvs.tokens.HAZARD_CURVE_KEY_TOKEN, job_id, site.hash())

    curves = []
    raw_curves = kvs.mget_decoded(pattern)

    for raw_curve in raw_curves:
        curves.append(raw_curve["curve"])

    return curves
Exemple #4
0
def curves_at(job_id, site):
    """Return all the json deserialized hazard curves for
    a single site (different realizations)."""
    pattern = "%s*%s*%s*%s" % (kvs.tokens.HAZARD_CURVE_KEY_TOKEN, job_id, site.longitude, site.latitude)

    curves = []
    raw_curves = kvs.mget_decoded(pattern)

    for raw_curve in raw_curves:
        curves.append(_extract_y_values_from(raw_curve["curve"]))

    return curves
def curves_at(job_id, site):
    """Return all the json deserialized hazard curves for
    a single site (different realizations)."""
    pattern = "%s*%s*%s*%s" % (kvs.tokens.HAZARD_CURVE_KEY_TOKEN,
            job_id, site.longitude, site.latitude)

    curves = []
    raw_curves = kvs.mget_decoded(pattern)

    for raw_curve in raw_curves:
        curves.append(raw_curve["curve"])

    return curves
Exemple #6
0
def poes_at(job_id, site, realizations):
    """Return all the json deserialized hazard curves for
    a single site (different realizations).

    :param job_id: the id of the job.
    :type job_id: integer
    :param site: site where the curves are computed.
    :type site: :py:class:`shapes.Site` object
    :param realizations: number of realizations.
    :type realizations: integer
    :returns: the hazard curves.
    :rtype: list of :py:class:`list` of :py:class:`float`
        containing the probability of exceedence for each realization
    """
    keys = [kvs.tokens.hazard_curve_poes_key(job_id, realization, site) for realization in xrange(realizations)]
    # get the probablity of exceedence for each curve in the site
    return kvs.mget_decoded(keys)
def compute_quantile_hazard_maps(job):
    """Compute quantile hazard maps using as input all the
    pre computed quantile hazard curves.

    The POES_HAZARD_MAPS parameter in the configuration file specifies
    all the values used in the computation.
    """

    quantiles = _extract_values_from_config(job, QUANTILE_PARAM_NAME)
    poes = _extract_values_from_config(job, POES_PARAM_NAME)

    LOG.debug("[QUANTILE_HAZARD_MAPS] List of POEs is %s" % poes)
    LOG.debug("[QUANTILE_HAZARD_MAPS] List of quantiles is %s" % quantiles)

    keys = []
    for quantile in quantiles:
        # get all the pre computed quantile curves
        pattern = "%s*%s*%s" % (kvs.tokens.QUANTILE_HAZARD_CURVE_KEY_TOKEN,
                job.id, quantile)

        quantile_curves = kvs.mget_decoded(pattern)

        LOG.debug("[QUANTILE_HAZARD_MAPS] Found %s pre computed " \
                "quantile curves for quantile %s"
                % (len(quantile_curves), quantile))

        for poe in poes:
            for quantile_curve in quantile_curves:
                site = shapes.Site(quantile_curve["site_lon"],
                                   quantile_curve["site_lat"])

                key = kvs.tokens.quantile_hazard_map_key(
                        job.id, site, poe, quantile)
                keys.append(key)

                _store_iml_for(quantile_curve, key, job, poe)

    return keys
    def bb_hazard_map_values_are_correctly_stored_in_kvs(self):
        """Hazard map values are correct and stored in kvs.

        This test verifies that the hazard map values we are going
        to store in .tiff and .xml formats are correct.
        """

        self.engine.launch()

        pattern = "%s*%s*%s*" % (kvs.tokens.MEAN_HAZARD_MAP_KEY_TOKEN,
                                 self.engine.id, POE)

        map_values = kvs.mget_decoded(pattern)

        self.assertEqual(len(self.expected_results), len(map_values))

        for expected_result in self.expected_results:
            key = kvs.tokens.mean_hazard_map_key(self.engine.id,
                                                 expected_result[0], POE)

            computed_value = float(kvs.get_value_json_decoded(key)["IML"])

            self.assertTrue(
                numpy.allclose(computed_value, expected_result[1], atol=0.001))
Exemple #9
0
    def bb_hazard_map_values_are_correctly_stored_in_kvs(self):
        """Hazard map values are correct and stored in kvs.

        This test verifies that the hazard map values we are going
        to store in .tiff and .xml formats are correct.
        """

        self.engine.launch()

        pattern = "%s*%s*%s*" % (
            kvs.tokens.MEAN_HAZARD_MAP_KEY_TOKEN, self.engine.id, POE)

        map_values = kvs.mget_decoded(pattern)

        self.assertEqual(len(self.expected_results), len(map_values))

        for expected_result in self.expected_results:
            key = kvs.tokens.mean_hazard_map_key(
                self.engine.id, expected_result[0], POE)

            computed_value = float(kvs.get_value_json_decoded(key)["IML"])

            self.assertTrue(numpy.allclose(computed_value,
                    expected_result[1], atol=0.001))
Exemple #10
0
 def _get_iml_at(self, site, poe):
     return kvs.mget_decoded("%s*%s*%s*%s" %
             (kvs.tokens.MEAN_HAZARD_MAP_KEY_TOKEN,
             self.job_id, site.hash(), str(poe)))[0]
Exemple #11
0
 def _get_iml_at(self, site, poe):
     return kvs.mget_decoded("%s*%s*%s*%s*%s" %
             (kvs.tokens.MEAN_HAZARD_MAP_KEY_TOKEN,
             self.job_id, site.longitude, site.latitude,
             str(poe)))[0]