Пример #1
0
    def test_call_no_insured(self):
        vf = mock.MagicMock()
        calc = workflows.Scenario('PGA', 'TAXO', vf, False)

        assets = [asset(dict(structural=10))] * 4
        vf = calc.risk_functions[self.loss_type]
        vf.apply_to = mock.Mock(return_value=numpy.empty((4, 2)))

        out = calc(self.loss_type, assets, mock.Mock(), mock.Mock())

        self.assertEqual((4, 2), out.loss_matrix.shape)
        self.assertEqual((2,), out.aggregate_losses.shape)
        self.assertIsNone(out.insured_loss_matrix)
        self.assertIsNone(out.insured_losses)
Пример #2
0
def get_risk_models(inputs,
                    loss_types,
                    insured_losses=False,
                    retrofitted=False):
    """
    Given a directory path name and a list of loss_types (for instance
    ['structural', 'nonstructural', ...]) look for files with name
    <loss_type>__vulnerability_model.xml, parse them and return a
    dictionary {taxonomy: risk_model}.
    """
    risk_models = {}
    for taxonomy, vf_by_loss_type in get_taxonomy_vfs(inputs, loss_types,
                                                      retrofitted):
        workflow = workflows.Scenario(vf_by_loss_type, insured_losses)
        risk_models[taxonomy] = workflows.RiskModel(taxonomy, workflow)
    return risk_models
Пример #3
0
    def test_call(self):
        vf = mock.MagicMock()
        calc = workflows.Scenario('PGA', 'TAXO', vf, True)

        assets = [asset(
            dict(structural=10),
            deductibles=dict(structural=0.1),
            insurance_limits=dict(structural=0.8))] * 4

        calc.risk_functions[self.loss_type].apply_to = mock.Mock(
            return_value=numpy.empty((4, 2)))

        out = calc(self.loss_type, assets, mock.Mock(), mock.Mock())

        self.assertEqual((4, 2), out.loss_matrix.shape)
        self.assertEqual((2,), out.aggregate_losses.shape)
        self.assertEqual((4, 2), out.insured_loss_matrix.shape)
        self.assertEqual((2,), out.insured_losses.shape)
Пример #4
0
    def calculation_unit(self, loss_type, assets):
        """
        :returns:
          a list of instances of `..base.CalculationUnit` for the given
          `assets` to be run in the celery task
        """

        # assume all assets have the same taxonomy
        taxonomy = assets[0].taxonomy
        model = self.risk_models[taxonomy][loss_type]

        return workflows.CalculationUnit(
            loss_type,
            workflows.Scenario(model.vulnerability_function,
                               self.rnd.randint(0, models.MAX_SINT_32),
                               self.rc.asset_correlation,
                               self.rc.insured_losses),
            hazard_getters.GroundMotionValuesGetter(
                self.rc.hazard_outputs(), assets,
                self.rc.best_maximum_distance, model.imt))