Ejemplo n.º 1
0
    def test_risk_trans_pass(self):
        """Test calc_risk_transfer"""
        # Create impact object
        imp = Impact()
        imp.event_id = np.arange(10)
        imp.event_name = [0, 1, 2, 3, 4, 5, 6, 7, 8, 15]
        imp.date = np.arange(10)
        imp.coord_exp = np.array([[1, 2], [2, 3]])
        imp.crs = DEF_CRS
        imp.eai_exp = np.array([1, 2])
        imp.at_event = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 15])
        imp.frequency = np.ones(10) / 5
        imp.tot_value = 10
        imp.aai_agg = 100
        imp.unit = 'USD'
        imp.imp_mat = sparse.csr_matrix(np.empty((0, 0)))

        new_imp, imp_rt = imp.calc_risk_transfer(2, 10)
        self.assertEqual(new_imp.unit, imp.unit)
        self.assertEqual(new_imp.tot_value, imp.tot_value)
        np.testing.assert_array_equal(new_imp.imp_mat.toarray(),
                                      imp.imp_mat.toarray())
        self.assertEqual(new_imp.event_name, imp.event_name)
        np.testing.assert_array_almost_equal_nulp(new_imp.event_id,
                                                  imp.event_id)
        np.testing.assert_array_almost_equal_nulp(new_imp.date, imp.date)
        np.testing.assert_array_almost_equal_nulp(new_imp.frequency,
                                                  imp.frequency)
        np.testing.assert_array_almost_equal_nulp(new_imp.coord_exp, [])
        np.testing.assert_array_almost_equal_nulp(new_imp.eai_exp, [])
        np.testing.assert_array_almost_equal_nulp(
            new_imp.at_event, [0, 1, 2, 2, 2, 2, 2, 2, 2, 5])
        self.assertAlmostEqual(new_imp.aai_agg, 4.0)

        self.assertEqual(imp_rt.unit, imp.unit)
        self.assertEqual(imp_rt.tot_value, imp.tot_value)
        np.testing.assert_array_equal(imp_rt.imp_mat.toarray(),
                                      imp.imp_mat.toarray())
        self.assertEqual(imp_rt.event_name, imp.event_name)
        np.testing.assert_array_almost_equal_nulp(imp_rt.event_id,
                                                  imp.event_id)
        np.testing.assert_array_almost_equal_nulp(imp_rt.date, imp.date)
        np.testing.assert_array_almost_equal_nulp(imp_rt.frequency,
                                                  imp.frequency)
        np.testing.assert_array_almost_equal_nulp(imp_rt.coord_exp, [])
        np.testing.assert_array_almost_equal_nulp(imp_rt.eai_exp, [])
        np.testing.assert_array_almost_equal_nulp(
            imp_rt.at_event, [0, 0, 0, 1, 2, 3, 4, 5, 6, 10])
        self.assertAlmostEqual(imp_rt.aai_agg, 6.2)
Ejemplo n.º 2
0
    def _calc_impact(self, new_exp, new_ifs, new_haz):
        """Compute impact and risk transfer of measure implemented over inputs.

        Parameters:
            new_exp (Exposures): exposures once measure applied
            new_ifs (ImpactFuncSet): impact functions once measure applied
            new_haz (Hazard): hazard once measure applied

        Returns:
            Impact, Impact
        """
        from climada.engine.impact import Impact
        imp = Impact()
        imp.calc(new_exp, new_ifs, new_haz)
        return imp.calc_risk_transfer(self.risk_transf_attach, self.risk_transf_cover)
Ejemplo n.º 3
0
    def test_risk_trans_pass(self):
        """ Test calc_risk_transfer """
        # Create impact object
        imp = Impact()
        imp.event_id = np.arange(10)
        imp.event_name = [0, 1, 2, 3, 4, 5, 6, 7, 8, 15]
        imp.date = np.arange(10)
        imp.coord_exp = np.array([[1, 2], [2, 3]])
        imp.crs = DEF_CRS
        imp.eai_exp = np.array([1, 2])
        imp.at_event = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 15])
        imp.frequency = np.ones(10) / 5
        imp.tot_value = 10
        imp.aai_agg = 100
        imp.unit = 'USD'
        imp.imp_mat = []

        new_imp, imp_rt = imp.calc_risk_transfer(2, 10)
        self.assertEqual(new_imp.unit, imp.unit)
        self.assertEqual(new_imp.tot_value, imp.tot_value)
        self.assertEqual(new_imp.imp_mat, imp.imp_mat)
        self.assertEqual(new_imp.event_name, imp.event_name)
        self.assertTrue(np.allclose(new_imp.event_id, imp.event_id))
        self.assertTrue(np.allclose(new_imp.date, imp.date))
        self.assertTrue(np.allclose(new_imp.frequency, imp.frequency))
        self.assertTrue(np.allclose(new_imp.coord_exp, np.array([])))
        self.assertTrue(np.allclose(new_imp.eai_exp, np.array([])))
        self.assertTrue(
            np.allclose(new_imp.at_event,
                        np.array([0, 1, 2, 2, 2, 2, 2, 2, 2, 5])))
        self.assertAlmostEqual(new_imp.aai_agg, 4.0)

        self.assertEqual(imp_rt.unit, imp.unit)
        self.assertEqual(imp_rt.tot_value, imp.tot_value)
        self.assertEqual(imp_rt.imp_mat, imp.imp_mat)
        self.assertEqual(imp_rt.event_name, imp.event_name)
        self.assertTrue(np.allclose(imp_rt.event_id, imp.event_id))
        self.assertTrue(np.allclose(imp_rt.date, imp.date))
        self.assertTrue(np.allclose(imp_rt.frequency, imp.frequency))
        self.assertTrue(np.allclose(imp_rt.coord_exp, np.array([])))
        self.assertTrue(np.allclose(imp_rt.eai_exp, np.array([])))
        self.assertTrue(
            np.allclose(imp_rt.at_event,
                        np.array([0, 0, 0, 1, 2, 3, 4, 5, 6, 10])))
        self.assertAlmostEqual(imp_rt.aai_agg, 6.2)
Ejemplo n.º 4
0
    def _calc_impact(self, new_exp, new_impfs, new_haz):
        """Compute impact and risk transfer of measure implemented over inputs.

        Parameters
        ----------
        new_exp : climada.entity.Exposures
            exposures once measure applied
        new_ifs : climada.entity.ImpactFuncSet
            impact function set once measure applied
        new_haz  : climada.hazard.Hazard
            hazard once measure applied

        Returns
        -------
            : climada.engine.Impact
        """
        from climada.engine.impact import Impact
        imp = Impact()
        imp.calc(new_exp, new_impfs, new_haz)
        return imp.calc_risk_transfer(self.risk_transf_attach,
                                      self.risk_transf_cover)