Example #1
0
        the value can't be casted to int.
        """

        number_of_samples = None
        raw_value = getattr(self, "PROB_NUM_OF_SAMPLES", None)

        if raw_value:
            try:
                number_of_samples = int(raw_value)
            except ValueError:
                LOGGER.error("PROB_NUM_OF_SAMPLES %s can't be converted "
                             "to int, using default value..." % raw_value)

        return number_of_samples

    def compute_loss_curve(self, column, row, loss_ratio_curve, asset):
        """Compute the loss curve for a single site."""
        if asset is None:
            return None

        loss_curve = loss_ratio_curve.rescale_abscissae(asset["assetValue"])
        key = kvs.tokens.loss_curve_key(self.id, row, column, asset["assetID"])

        LOGGER.warn("RESULT: loss curve is %s, write to key %s" % (
                loss_curve, key))
        kvs.set(key, loss_curve.to_json())
        return loss_curve


RiskJobMixin.register("Probabilistic Event", ProbabilisticEventMixin)
Example #2
0
        :param hazard_curve: the hazard curve used to compute the
            loss ratio curve
        :type hazard_curve: :py:class:`openquake.shapes.Curve`
        """

        # we get the vulnerability function related to the asset

        vuln_function_reference = asset["vulnerabilityFunctionReference"]
        vuln_function = self.vuln_curves.get(vuln_function_reference, None)

        if not vuln_function:
            LOGGER.error(
                "Unknown vulnerability function %s for asset %s" %
                (asset["vulnerabilityFunctionReference"], asset["assetID"]))

            return None

        loss_ratio_curve = cpsha_based.compute_loss_ratio_curve(
            vuln_function, hazard_curve)

        loss_ratio_key = kvs.tokens.loss_ratio_key(self.job_id, point.row,
                                                   point.column,
                                                   asset['assetID'])

        kvs.set(loss_ratio_key, loss_ratio_curve.to_json())

        return loss_ratio_curve


RiskJobMixin.register("Classical PSHA", ClassicalPSHABasedMixin)
Example #3
0
        :param hazard_curve: the hazard curve used to compute the
            loss ratio curve
        :type hazard_curve: :py:class:`openquake.shapes.Curve`
        """

        # we get the vulnerability function related to the asset

        vuln_function_reference = asset["vulnerabilityFunctionReference"]
        vuln_function = self.vuln_curves.get(
            vuln_function_reference, None)

        if not vuln_function:
            LOGGER.error(
                "Unknown vulnerability function %s for asset %s"
                % (asset["vulnerabilityFunctionReference"],
                asset["assetID"]))

            return None

        loss_ratio_curve = cpsha_based.compute_loss_ratio_curve(
            vuln_function, hazard_curve)

        loss_ratio_key = kvs.tokens.loss_ratio_key(
            self.job_id, point.row, point.column, asset['assetID'])

        kvs.set(loss_ratio_key, loss_ratio_curve.to_json())

        return loss_ratio_curve

RiskJobMixin.register("Classical PSHA", ClassicalPSHABasedMixin)
Example #4
0
    uses the values) to use a generator instead.

    :param point: :py:class:`openquake.shapes.GridPoint` object

    :returns: List of ground motion values (as floats). Each value represents a
        realization of the calculation for a single point.
    """
    gmfs_key = kvs.tokens.ground_motion_values_key(job_id, point)
    gmfs = kvs.get_client().lrange(gmfs_key, 0, -1)
    decoder = json.JSONDecoder()
    return [float(decoder.decode(x)['mag']) for x in gmfs]


def load_assets_for_point(job_id, point):
    """
    From the KVS, load all assets for the given point.

    :param point: :py:class:`openquake.shapes.GridPoint` object

    :returns: List of asset dicts at the given location (point) in the
        following form::
            {u'assetValue': 124.27, u'vulnerabilityFunctionReference': u'ID'}
    """
    assets_key = kvs.tokens.asset_key(job_id, point.row, point.column)
    assets = kvs.get_client().lrange(assets_key, 0, -1)
    decoder = json.JSONDecoder()
    return [decoder.decode(x) for x in assets]


RiskJobMixin.register("Deterministic", DeterministicEventBasedMixin)
Example #5
0
        the value can't be casted to int.
        """

        number_of_samples = None
        raw_value = getattr(self, "PROB_NUM_OF_SAMPLES", None)

        if raw_value:
            try:
                number_of_samples = int(raw_value)
            except ValueError:
                LOGGER.error("PROB_NUM_OF_SAMPLES %s can't be converted "
                             "to int, using default value..." % raw_value)

        return number_of_samples

    def compute_loss_curve(self, column, row, loss_ratio_curve, asset):
        """Compute the loss curve for a single site."""
        if asset is None:
            return None

        loss_curve = loss_ratio_curve.rescale_abscissae(asset["assetValue"])
        key = kvs.tokens.loss_curve_key(self.id, row, column, asset["assetID"])

        LOGGER.warn("RESULT: loss curve is %s, write to key %s" %
                    (loss_curve, key))
        kvs.set(key, loss_curve.to_json())
        return loss_curve


RiskJobMixin.register("Probabilistic Event", ProbabilisticEventMixin)