Exemple #1
0
    def compute_loss_ratio_curve(
            self, col, row, asset, gmf_slice, loss_ratios):
        """Compute the loss ratio curve for a single asset."""
        calc_proxy = self.calc_proxy

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

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

            return None

        epsilon_provider = general.EpsilonProvider(calc_proxy.params)

        loss_histogram_bins = calc_proxy.oq_job_profile.loss_histogram_bins
        loss_ratio_curve = general.compute_loss_ratio_curve(
            vuln_function, gmf_slice, epsilon_provider, asset,
            loss_histogram_bins, loss_ratios=loss_ratios)

        # NOTE (jmc): Early exit if the loss ratio is all zeros
        if not False in (loss_ratio_curve.ordinates == 0.0):
            return None

        key = kvs.tokens.loss_ratio_key(
            self.calc_proxy.job_id, row, col, asset["assetID"])

        kvs.get_client().set(key, loss_ratio_curve.to_json())

        LOGGER.debug("Loss ratio curve is %s, write to key %s" %
                (loss_ratio_curve, key))

        return loss_ratio_curve
Exemple #2
0
    def _compute_loss_ratio_curve(self, asset, gmf, loss_ratios):
        """
        Generates a loss ratio curve for the given asset.
        """

        vulnerability_function = self.vulnerability_curves.get(
            asset.taxonomy, None)

        if not vulnerability_function:
            LOGGER.error("Unknown vulnerability function %s for asset %s" %
                         (asset.taxonomy, asset.asset_ref))

            return None

        epsilon_provider = general.EpsilonProvider(self.job_ctxt.params)
        loss_histogram_bins = self.job_ctxt.oq_job_profile.loss_histogram_bins

        loss_ratio_curve = general.compute_loss_ratio_curve(
            vulnerability_function,
            gmf,
            epsilon_provider,
            asset,
            loss_histogram_bins,
            loss_ratios=loss_ratios)

        return loss_ratio_curve
Exemple #3
0
 def get_loss_curve(point, vuln_function, asset):
     "Compute loss curve basing on GMF data"
     gmf_slice = gmf_slices[point.site]
     loss_ratios = general.compute_loss_ratios(
         vuln_function, gmf_slice, epsilon_provider, asset)
     loss_ratio_curve = general.compute_loss_ratio_curve(
         vuln_function, gmf_slice, epsilon_provider, asset,
         self.calc_proxy.oq_job_profile.loss_histogram_bins,
         loss_ratios=loss_ratios)
     return loss_ratio_curve.rescale_abscissae(asset["assetValue"])
Exemple #4
0
        def get_loss_curve(point, vuln_function, asset):
            "Compute loss curve basing on GMF data"
            gmf_slice = gmf_slices[point.site]
            loss_ratios = general.compute_loss_ratios(
                vuln_function, gmf_slice, epsilon_provider, asset)
            loss_ratio_curve = general.compute_loss_ratio_curve(
                vuln_function, gmf_slice, epsilon_provider, asset,
                self.job_ctxt.oq_job_profile.loss_histogram_bins,
                loss_ratios=loss_ratios)

            aggregate_curve.append(loss_ratios * asset.value)

            return loss_ratio_curve.rescale_abscissae(asset.value)
Exemple #5
0
        def get_loss_curve(point, vuln_function, asset):
            "Compute loss curve basing on GMF data"
            gmf_slice = gmf_slices[point.site]
            loss_ratios = general.compute_loss_ratios(vuln_function, gmf_slice,
                                                      epsilon_provider, asset)
            loss_ratio_curve = general.compute_loss_ratio_curve(
                vuln_function,
                gmf_slice,
                epsilon_provider,
                asset,
                self.job_ctxt.oq_job_profile.loss_histogram_bins,
                loss_ratios=loss_ratios)

            aggregate_curve.append(loss_ratios * asset.value)

            return loss_ratio_curve.rescale_abscissae(asset.value)
Exemple #6
0
        def get_loss_curve(site, vuln_function, asset):
            "Compute loss curve basing on GMF data"
            gmvs = self._get_gmvs_at(general.hazard_input_site(
                    self.job_ctxt, site))

            gmf_slice = {"IMLs": gmvs, "TSES": self._tses(),
                    "TimeSpan": self._time_span()}

            loss_ratios = general.compute_loss_ratios(
                vuln_function, gmf_slice, epsilon_provider, asset)
            loss_ratio_curve = general.compute_loss_ratio_curve(
                vuln_function, gmf_slice, epsilon_provider, asset,
                self.job_ctxt.oq_job_profile.loss_histogram_bins,
                loss_ratios=loss_ratios)

            aggregate_curve.append(loss_ratios * asset.value)

            return loss_ratio_curve.rescale_abscissae(asset.value)
Exemple #7
0
    def compute_loss_ratio_curve(self, col, row, asset, gmf_slice,
                                 loss_ratios):
        """Compute the loss ratio curve for a single asset.

        :param asset: the asset used to compute loss
        :type asset: an :py:class:`openquake.db.model.ExposureData` instance
        """
        job_ctxt = self.job_ctxt

        vuln_function = self.vuln_curves.get(asset.taxonomy, None)

        if not vuln_function:
            LOGGER.error("Unknown vulnerability function %s for asset %s" %
                         (asset.taxonomy, asset.asset_ref))
            return None

        epsilon_provider = general.EpsilonProvider(job_ctxt.params)

        loss_histogram_bins = job_ctxt.oq_job_profile.loss_histogram_bins
        loss_ratio_curve = general.compute_loss_ratio_curve(
            vuln_function,
            gmf_slice,
            epsilon_provider,
            asset,
            loss_histogram_bins,
            loss_ratios=loss_ratios)

        # NOTE (jmc): Early exit if the loss ratio is all zeros
        if not False in (loss_ratio_curve.ordinates == 0.0):
            return None

        key = kvs.tokens.loss_ratio_key(self.job_ctxt.job_id, row, col,
                                        asset.asset_ref)

        kvs.get_client().set(key, loss_ratio_curve.to_json())

        LOGGER.debug("Loss ratio curve is %s, write to key %s" %
                     (loss_ratio_curve, key))

        return loss_ratio_curve
Exemple #8
0
    def _compute_loss_ratio_curve(self, asset, gmf, loss_ratios):
        """
        Generates a loss ratio curve for the given asset.
        """

        vulnerability_function = self.vulnerability_curves.get(
                    asset.taxonomy, None)

        if not vulnerability_function:
            LOGGER.error("Unknown vulnerability function %s for asset %s"
                         % (asset.taxonomy, asset.asset_ref))

            return None

        epsilon_provider = general.EpsilonProvider(self.job_ctxt.params)
        loss_histogram_bins = self.job_ctxt.oq_job_profile.loss_histogram_bins

        loss_ratio_curve = general.compute_loss_ratio_curve(
            vulnerability_function, gmf, epsilon_provider, asset,
            loss_histogram_bins, loss_ratios=loss_ratios)

        return loss_ratio_curve
Exemple #9
0
    def compute_loss_ratio_curve(self, col, row, asset, gmf_slice,
                                 loss_ratios):
        """Compute the loss ratio curve for a single asset.

        :param asset: the asset used to compute loss
        :type asset: an :py:class:`openquake.db.model.ExposureData` instance
        """
        job_ctxt = self.job_ctxt

        vuln_function = self.vuln_curves.get(asset.taxonomy, None)

        if not vuln_function:
            LOGGER.error("Unknown vulnerability function %s for asset %s"
                         % (asset.taxonomy, asset.asset_ref))
            return None

        epsilon_provider = general.EpsilonProvider(job_ctxt.params)

        loss_histogram_bins = job_ctxt.oq_job_profile.loss_histogram_bins
        loss_ratio_curve = general.compute_loss_ratio_curve(
            vuln_function, gmf_slice, epsilon_provider, asset,
            loss_histogram_bins, loss_ratios=loss_ratios)

        # NOTE (jmc): Early exit if the loss ratio is all zeros
        if not False in (loss_ratio_curve.ordinates == 0.0):
            return None

        key = kvs.tokens.loss_ratio_key(
            self.job_ctxt.job_id, row, col, asset.asset_ref)

        kvs.get_client().set(key, loss_ratio_curve.to_json())

        LOGGER.debug("Loss ratio curve is %s, write to key %s" %
                (loss_ratio_curve, key))

        return loss_ratio_curve
Exemple #10
0
        def get_loss_curve(site, vuln_function, asset):
            "Compute loss curve basing on GMF data"
            gmvs = self._get_gmvs_at(
                general.hazard_input_site(self.job_ctxt, site))

            gmf_slice = {
                "IMLs": gmvs,
                "TSES": self._tses(),
                "TimeSpan": self._time_span()
            }

            loss_ratios = general.compute_loss_ratios(vuln_function, gmf_slice,
                                                      epsilon_provider, asset)
            loss_ratio_curve = general.compute_loss_ratio_curve(
                vuln_function,
                gmf_slice,
                epsilon_provider,
                asset,
                self.job_ctxt.oq_job_profile.loss_histogram_bins,
                loss_ratios=loss_ratios)

            aggregate_curve.append(loss_ratios * asset.value)

            return loss_ratio_curve.rescale_abscissae(asset.value)