Beispiel #1
0
 def task_completed_hook(self, message):
     """
     Updates the event loss table
     """
     for loss_type in base.loss_types(self.risk_models):
         task_loss_table = message['event_loss_tables'][loss_type]
         self.event_loss_tables[loss_type] += task_loss_table
Beispiel #2
0
    def create_statistical_outputs(self):
        """
        Create statistics output containers.

        In classical risk we need also loss fraction ids for aggregate
        results
        """

        containers = super(
            ClassicalRiskCalculator, self).create_statistical_outputs()

        if len(self.rc.hazard_outputs()) < 2:
            return containers

        for loss_type in base.loss_types(self.risk_models):
            for poe in self.rc.poes_disagg or []:
                name = "mean loss fractions. type=%s poe=%.4f" % (
                    loss_type, poe)
                containers.set(models.LossFraction.objects.create(
                    variable="taxonomy",
                    poe=poe,
                    loss_type=loss_type,
                    output=models.Output.objects.create_output(
                        job=self.job,
                        display_name=name,
                        output_type="loss_fraction"),
                    statistics="mean"))

        for loss_type in base.loss_types(self.risk_models):
            for quantile in self.rc.quantile_loss_curves or []:
                for poe in self.rc.poes_disagg or []:
                    name = ("quantile(%.4f) loss fractions "
                            "loss_type=%s poe=%.4f" % (
                                quantile, loss_type, poe))
                    containers.set(models.LossFraction.objects.create(
                        variable="taxonomy",
                        poe=poe,
                        loss_type=loss_type,
                        output=models.Output.objects.create_output(
                            job=self.job,
                            display_name=name,
                            output_type="loss_fraction"),
                        statistics="quantile",
                        quantile=quantile))

        return containers
Beispiel #3
0
    def task_completed_hook(self, message):
        aggregate_losses_dict = message.get('aggregate_losses')

        for loss_type in base.loss_types(self.risk_models):
            aggregate_losses = aggregate_losses_dict.get(loss_type)

            if aggregate_losses is not None:
                if self.aggregate_losses.get(loss_type) is None:
                    self.aggregate_losses[loss_type] = (
                        numpy.zeros(aggregate_losses.shape))
                self.aggregate_losses[loss_type] += aggregate_losses

        if self.rc.insured_losses:
            insured_losses_dict = message.get('insured_losses')
            for loss_type in base.loss_types(self.risk_models):
                insured_losses = insured_losses_dict.get(
                    loss_type)
                if insured_losses is not None:
                    if self.insured_losses.get(loss_type) is None:
                        self.insured_losses[loss_type] = numpy.zeros(
                            insured_losses.shape)
                    self.insured_losses[loss_type] += insured_losses
Beispiel #4
0
    def create_outputs(self, hazard_output):
        """
        Create BCR Distribution output container, i.e. a
        :class:`openquake.engine.db.models.BCRDistribution` instance and its
        :class:`openquake.engine.db.models.Output` container.

        :returns: an instance of OutputDict
        """
        ret = writers.OutputDict()

        for loss_type in base.loss_types(self.risk_models):
            name = "BCR Map. type=%s hazard=%s" % (loss_type, hazard_output)
            ret.set(models.BCRDistribution.objects.create(
                    hazard_output=hazard_output,
                    loss_type=loss_type,
                    output=models.Output.objects.create_output(
                        self.job, name, "bcr_distribution")))
        return ret
Beispiel #5
0
    def create_outputs(self, hazard_output):
        """
        Add Insured Curve output containers
        """
        # includes loss curves and loss maps
        outputs = super(EventBasedRiskCalculator, self).create_outputs(
            hazard_output)

        for loss_type in base.loss_types(self.risk_models):
            if loss_type != "fatalities":
                if self.rc.insured_losses:
                    name = "insured loss curves. type=%s hazard %s" % (
                        loss_type, hazard_output),
                    outputs.set(
                        models.LossCurve.objects.create(
                            insured=True,
                            loss_type=loss_type,
                            hazard_output=hazard_output,
                            output=models.Output.objects.create_output(
                                self.job, name, "loss_curve")))

            if self.rc.sites_disagg:
                name = ("loss fractions. type=%s variable=magnitude_distance "
                        "hazard=%s" % (loss_type, hazard_output))
                outputs.set(
                    models.LossFraction.objects.create(
                        output=models.Output.objects.create_output(
                            self.job, name, "loss_fraction"),
                        hazard_output=hazard_output,
                        loss_type=loss_type,
                        variable="magnitude_distance"))
                name = ("loss fractions. type=%s variable=coordinates "
                        "hazard=%s" % (loss_type, hazard_output))
                outputs.set(models.LossFraction.objects.create(
                    output=models.Output.objects.create_output(
                        self.job, name, "loss_fraction"),
                    hazard_output=hazard_output,
                    loss_type=loss_type,
                    variable="coordinate"))

        return outputs
Beispiel #6
0
    def create_outputs(self, hazard_output):
        """
        Create the the output of a ScenarioRisk calculator
        which is a LossMap.
        """
        ret = writers.OutputDict()

        for loss_type in base.loss_types(self.risk_models):
            if self.rc.insured_losses:
                ret.set(models.LossMap.objects.create(
                    output=models.Output.objects.create_output(
                        self.job, "Insured Loss Map", "loss_map"),
                    hazard_output=hazard_output,
                    loss_type=loss_type,
                    insured=True))

            ret.set(models.LossMap.objects.create(
                    output=models.Output.objects.create_output(
                        self.job, "Loss Map", "loss_map"),
                    hazard_output=hazard_output,
                    loss_type=loss_type))
        return ret
Beispiel #7
0
    def create_outputs(self, hazard_output):
        """
        Create outputs container objects.

        In classical risk, we finalize the output containers by adding
        ids of loss_fractions
        """
        containers = super(ClassicalRiskCalculator, self).create_outputs(
            hazard_output)

        for loss_type in base.loss_types(self.risk_models):
            for poe in self.rc.poes_disagg or []:
                containers.set(models.LossFraction.objects.create(
                    hazard_output_id=hazard_output.id,
                    variable="taxonomy",
                    loss_type=loss_type,
                    output=models.Output.objects.create_output(
                        self.job,
                        "loss fractions. type=%s poe=%s hazard=%s" % (
                            loss_type, poe, hazard_output.id),
                        "loss_fraction"),
                    poe=poe))
            return containers
Beispiel #8
0
 def create_statistical_outputs(self):
     for loss_type in base.loss_types(self.risk_models):
         self.event_loss_tables[loss_type] = collections.Counter()
     return super(
         EventBasedRiskCalculator, self).create_statistical_outputs()