示例#1
0
    def test_remove_measure(self):
        """Test remove_measure method"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.check()
        entity.exposures.ref_year = 2018
        cost_ben = CostBenefit()
        cost_ben.calc(hazard,
                      entity,
                      future_year=2040,
                      risk_func=risk_aai_agg,
                      imp_time_depen=None,
                      save_imp=True)

        to_remove = 'Mangroves'
        self.assertTrue(to_remove in cost_ben.benefit.keys())
        cost_ben.remove_measure(to_remove)
        self.assertTrue(to_remove not in cost_ben.color_rgb.keys())
        self.assertTrue(to_remove not in cost_ben.benefit.keys())
        self.assertTrue(to_remove not in cost_ben.cost_ben_ratio.keys())
        self.assertTrue(to_remove not in cost_ben.imp_meas_future.keys())
        self.assertTrue(to_remove not in cost_ben.imp_meas_present.keys())
        self.assertEqual(len(cost_ben.imp_meas_present), 0)
        self.assertEqual(len(cost_ben.imp_meas_future), 4)
        self.assertEqual(len(cost_ben.color_rgb), 4)
        self.assertEqual(len(cost_ben.cost_ben_ratio), 3)
        self.assertEqual(len(cost_ben.benefit), 3)
    def test_calc_no_change_pass(self):
        """Test calc without future change"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.check()
        entity.exposures.ref_year = 2018
        cost_ben = CostBenefit()
        cost_ben.calc(hazard, entity, future_year=2040)

        self.assertEqual(cost_ben.imp_meas_present, dict())
        self.assertEqual(len(cost_ben.imp_meas_future), 5)
        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)

        self.assertEqual(cost_ben.cost_ben_ratio['Mangroves'],
                         0.04230714690616641)
        self.assertEqual(cost_ben.cost_ben_ratio['Beach nourishment'],
                         0.06998836431681373)
        self.assertEqual(cost_ben.cost_ben_ratio['Seawall'],
                         0.2679741183248266)
        self.assertEqual(cost_ben.cost_ben_ratio['Building code'],
                         0.30286828677985717)

        self.assertEqual(cost_ben.benefit['Mangroves'], 3.100583368954022e+10)
        self.assertEqual(cost_ben.benefit['Beach nourishment'],
                         2.468981832719974e+10)
        self.assertEqual(cost_ben.benefit['Seawall'], 3.3132973770502796e+10)
        self.assertEqual(cost_ben.benefit['Building code'],
                         3.0376240767284798e+10)

        self.assertEqual(cost_ben.tot_climate_risk, 1.2150496306913972e+11)
示例#3
0
    def test_calc_imp_mat_pass(self):
        """Test save imp_mat"""
        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # Compute the impact over the whole exposures
        impact.calc(ent.exposures, ent.impact_funcs, hazard, save_mat=True)
        self.assertTrue(isinstance(impact.imp_mat, sparse.csr_matrix))
        self.assertEqual(impact.imp_mat.shape,
                         (hazard.event_id.size, ent.exposures.value.size))
        self.assertTrue(
            np.allclose(
                np.sum(impact.imp_mat, axis=1).reshape(-1), impact.at_event))
        self.assertTrue(
            np.allclose(
                np.array(
                    np.sum(np.multiply(impact.imp_mat.toarray(),
                                       impact.frequency.reshape(-1, 1)),
                           axis=0)).reshape(-1), impact.eai_exp))
示例#4
0
    def test_write_read_excel_pass(self):
        """Test write and read in excel"""
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        imp_write = Impact()
        ent.exposures.assign_centroids(hazard)
        imp_write.calc(ent.exposures, ent.impact_funcs, hazard)
        file_name = os.path.join(DATA_FOLDER, 'test.xlsx')
        imp_write.write_excel(file_name)

        imp_read = Impact()
        imp_read.read_excel(file_name)

        self.assertTrue(np.array_equal(imp_write.event_id, imp_read.event_id))
        self.assertTrue(np.array_equal(imp_write.date, imp_read.date))
        self.assertTrue(np.array_equal(imp_write.coord_exp,
                                       imp_read.coord_exp))
        self.assertTrue(np.allclose(imp_write.eai_exp, imp_read.eai_exp))
        self.assertTrue(np.allclose(imp_write.at_event, imp_read.at_event))
        self.assertTrue(np.array_equal(imp_write.frequency,
                                       imp_read.frequency))
        self.assertEqual(imp_write.tot_value, imp_read.tot_value)
        self.assertEqual(imp_write.aai_agg, imp_read.aai_agg)
        self.assertEqual(imp_write.unit, imp_read.unit)
        self.assertEqual(
            0,
            len([
                i for i, j in zip(imp_write.event_name, imp_read.event_name)
                if i != j
            ]))
        self.assertIsInstance(imp_read.crs, dict)
    def test_combine_current_pass(self):
        """ Test combine_measures with only future"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.check()
        entity.exposures.ref_year = 2018
        cost_ben = CostBenefit()
        cost_ben.calc(hazard, entity, future_year=2040, risk_func=risk_aai_agg,
                      imp_time_depen=None, save_imp=True)

        new_name = 'combine'
        new_color = np.array([0.1, 0.1, 0.1])
        new_cb = cost_ben.combine_measures(['Mangroves', 'Seawall'], new_name, new_color,
            entity.disc_rates, imp_time_depen=None, risk_func=risk_aai_agg)

        self.assertTrue(np.allclose(new_cb.color_rgb[new_name], new_color))
        self.assertEqual(len(new_cb.imp_meas_present), 0)
        new_imp = cost_ben.imp_meas_future['no measure']['impact'].at_event - \
            cost_ben.imp_meas_future['Mangroves']['impact'].at_event
        new_imp += cost_ben.imp_meas_future['no measure']['impact'].at_event - \
            cost_ben.imp_meas_future['Seawall']['impact'].at_event
        new_imp = np.maximum(cost_ben.imp_meas_future['no measure']['impact'].at_event - new_imp, 0)
        self.assertTrue(np.allclose(new_cb.imp_meas_future[new_name]['impact'].at_event, new_imp))
        self.assertAlmostEqual(new_cb.imp_meas_future[new_name]['risk'],
                               np.sum(new_imp*cost_ben.imp_meas_future['no measure']['impact'].frequency), 5)
        self.assertAlmostEqual(new_cb.imp_meas_future[new_name]['cost'][0],
                               cost_ben.imp_meas_future['Mangroves']['cost'][0]+cost_ben.imp_meas_future['Seawall']['cost'][0])
        self.assertAlmostEqual(new_cb.imp_meas_future[new_name]['cost'][1], 1)
        self.assertTrue(np.allclose(new_cb.imp_meas_future[new_name]['efc'].impact,
                                    new_cb.imp_meas_future[new_name]['impact'].calc_freq_curve().impact))
        self.assertAlmostEqual(new_cb.imp_meas_future[new_name]['risk_transf'], 0)
        self.assertAlmostEqual(new_cb.benefit[new_name], 51781337529.07264)
        self.assertAlmostEqual(new_cb.cost_ben_ratio[new_name], 0.19679962474434248)
示例#6
0
    def test_calc_imp_mat_pass(self):
        """Test save imp_mat"""
        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # Compute the impact over the whole exposures
        impact.calc(ent.exposures, ent.impact_funcs, hazard, save_mat=True)
        self.assertIsInstance(impact.imp_mat, sparse.csr_matrix)
        self.assertEqual(impact.imp_mat.shape, (hazard.event_id.size,
                                                ent.exposures.gdf.value.size))
        np.testing.assert_array_almost_equal_nulp(
            np.array(impact.imp_mat.sum(axis=1)).ravel(), impact.at_event, nulp=5)
        np.testing.assert_array_almost_equal_nulp(
            np.sum(impact.imp_mat.toarray() * impact.frequency[:, None], axis=0).reshape(-1),
            impact.eai_exp)
    def test_calc_cb_no_change_pass(self):
        """Test _calc_cost_benefit without present value against reference value"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        cost_ben = CostBenefit()
        cost_ben._calc_impact_measures(hazard, entity.exposures, entity.measures,
            entity.impact_funcs, when='future', risk_func=risk_aai_agg, save_imp=True)

        cost_ben.present_year = 2018
        cost_ben.future_year = 2040
        cost_ben._calc_cost_benefit(entity.disc_rates)

        self.assertEqual(cost_ben.imp_meas_present, dict())
        self.assertEqual(len(cost_ben.imp_meas_future), 5)
        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)

        self.assertEqual(cost_ben.cost_ben_ratio['Mangroves'], 0.04230714690616641)
        self.assertEqual(cost_ben.cost_ben_ratio['Beach nourishment'], 0.06998836431681373)
        self.assertEqual(cost_ben.cost_ben_ratio['Seawall'], 0.2679741183248266)
        self.assertEqual(cost_ben.cost_ben_ratio['Building code'], 0.30286828677985717)

        self.assertEqual(cost_ben.benefit['Mangroves'], 3.100583368954022e+10)
        self.assertEqual(cost_ben.benefit['Beach nourishment'], 2.468981832719974e+10)
        self.assertEqual(cost_ben.benefit['Seawall'], 3.3132973770502796e+10)
        self.assertEqual(cost_ben.benefit['Building code'], 3.0376240767284798e+10)

        self.assertEqual(cost_ben.tot_climate_risk, 1.2150496306913972e+11)
    def test_calib_instance(self):
        """ Test save calib instance """
        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)

        # get impact function from set
        imp_func = ent.impact_funcs.get_func(hazard.tag.haz_type,
                                             ent.exposures.if_TC.median())

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # create input frame
        df_in = pd.DataFrame.from_dict({
            'v_threshold': [25.7],
            'other_param': [2],
            'hazard': [HAZ_TEST_MAT]
        })
        df_in_yearly = pd.DataFrame.from_dict({
            'v_threshold': [25.7],
            'other_param': [2],
            'hazard': [HAZ_TEST_MAT]
        })

        # Compute the impact over the whole exposures
        df_out = calib_instance(hazard, ent.exposures, imp_func, df_in)
        df_out_yearly = calib_instance(hazard,
                                       ent.exposures,
                                       imp_func,
                                       df_in_yearly,
                                       yearly_impact=True)
        # calc Impact as comparison
        impact = Impact()
        impact.calc(ent.exposures, ent.impact_funcs, hazard)
        IYS = impact.calc_impact_year_set(all_years=True)

        # do the tests
        self.assertTrue(isinstance(df_out, pd.DataFrame))
        self.assertTrue(isinstance(df_out_yearly, pd.DataFrame))
        self.assertEqual(df_out.shape[0], hazard.event_id.size)
        self.assertEqual(df_out_yearly.shape[0], 161)
        self.assertTrue(all(df_out['event_id'] == hazard.event_id))
        self.assertTrue(
            all(df_out[df_in.columns[0]].isin(df_in[df_in.columns[0]])))
        self.assertTrue(
            all(df_out_yearly[df_in.columns[1]].isin(df_in[df_in.columns[1]])))
        self.assertTrue(
            all(df_out_yearly[df_in.columns[2]].isin(df_in[df_in.columns[2]])))
        self.assertTrue(
            all(df_out['impact_CLIMADA'].values == impact.at_event))
        self.assertTrue(
            all(df_out_yearly['impact_CLIMADA'].values == [*IYS.values()]))
示例#9
0
    def test_ref_value_insure_pass(self):
        """Test result against reference value"""
        # Read demo entity values
        # Set the entity default file to the demo one
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()
        impact.at_event = np.zeros(hazard.intensity.shape[0])
        impact.eai_exp = np.zeros(len(ent.exposures.value))
        impact.tot_value = 0

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # Compute impact for 6th exposure
        iexp = 5
        # Take its impact function
        imp_id = ent.exposures.if_TC[iexp]
        imp_fun = ent.impact_funcs.get_func(hazard.tag.haz_type, imp_id)
        # Compute
        insure_flag = True
        impact._exp_impact(np.array([iexp]), ent.exposures, hazard, imp_fun,
                           insure_flag)

        self.assertEqual(impact.eai_exp.size, ent.exposures.shape[0])
        self.assertEqual(impact.at_event.size, hazard.intensity.shape[0])

        events_pos = hazard.intensity[:, ent.exposures.centr_TC[iexp]].nonzero(
        )[0]
        res_exp = np.zeros((ent.exposures.shape[0]))
        res_exp[iexp] = np.sum(impact.at_event[events_pos] *
                               hazard.frequency[events_pos])
        self.assertTrue(np.array_equal(res_exp, impact.eai_exp))

        self.assertEqual(0, impact.at_event[12])
        # Check first 3 values
        self.assertEqual(0, impact.at_event[12])
        self.assertEqual(0, impact.at_event[41])
        self.assertEqual(1.0626600695059455e+06, impact.at_event[44])

        # Check intermediate values
        self.assertEqual(0, impact.at_event[6281])
        self.assertEqual(0, impact.at_event[4998])
        self.assertEqual(0, impact.at_event[9527])
        self.assertEqual(1.3318063850487845e+08, impact.at_event[7192])
        self.assertEqual(4.667108555054083e+06, impact.at_event[8624])

        # Check last 3 values
        self.assertEqual(0, impact.at_event[14349])
        self.assertEqual(0, impact.at_event[14347])
        self.assertEqual(0, impact.at_event[14309])
    def test_calc_cb_change_pass(self):
        """Test _calc_cost_benefit with present value against reference value"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        cost_ben = CostBenefit()
        cost_ben._calc_impact_measures(hazard, entity.exposures, entity.measures,
            entity.impact_funcs, when='present', risk_func=risk_aai_agg, save_imp=False)

        ent_future = Entity()
        ent_future.read_excel(ENT_DEMO_FUTURE)
        ent_future.check()

        haz_future = copy.deepcopy(hazard)
        haz_future.intensity.data += 25

        cost_ben._calc_impact_measures(haz_future, ent_future.exposures, ent_future.measures,
            ent_future.impact_funcs, when='future', risk_func=risk_aai_agg, save_imp=False)

        cost_ben.present_year = 2018
        cost_ben.future_year = 2040
        cost_ben._calc_cost_benefit(entity.disc_rates, imp_time_depen=1)

        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)
        self.assertEqual(cost_ben.tot_climate_risk, 5.768659152882021e+11)

        self.assertEqual(cost_ben.imp_meas_present['no measure']['risk'], 6.51220115756442e+09)
        self.assertEqual(cost_ben.imp_meas_present['Mangroves']['risk'], 4.850407096284983e+09)
        self.assertEqual(cost_ben.imp_meas_present['Beach nourishment']['risk'], 5.188921355413834e+09)
        self.assertEqual(cost_ben.imp_meas_present['Seawall']['risk'], 4.736400526119911e+09)
        self.assertEqual(cost_ben.imp_meas_present['Building code']['risk'], 4.884150868173321e+09)

        self.assertEqual(cost_ben.imp_meas_future['no measure']['risk'], 5.9506659786664024e+10)
        self.assertEqual(cost_ben.imp_meas_future['Mangroves']['risk'], 4.826231151473135e+10)
        self.assertEqual(cost_ben.imp_meas_future['Beach nourishment']['risk'], 5.0647250923231674e+10)
        self.assertEqual(cost_ben.imp_meas_future['Seawall']['risk'], 21089567135.7345)
        self.assertEqual(cost_ben.imp_meas_future['Building code']['risk'], 4.462999483999791e+10)

        self.assertAlmostEqual(cost_ben.benefit['Mangroves'], 113345027690.81276)
        self.assertAlmostEqual(cost_ben.benefit['Beach nourishment'], 89444869971.53653)
        self.assertAlmostEqual(cost_ben.benefit['Seawall'], 347977469896.1333)
        self.assertAlmostEqual(cost_ben.benefit['Building code'], 144216478822.05154)

        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Mangroves'], 0.011573232523528404)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Beach nourishment'], 0.01931916274851638)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Seawall'], 0.025515385913577368)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Building code'], 0.06379298728650741)

        self.assertEqual(cost_ben.tot_climate_risk, 576865915288.2021)
示例#11
0
 def test_impact(self):
     ent = Entity()
     ent.read_excel(ENT_DEMO_TODAY)
     ent.check()
     hazard = Hazard('TC')
     hazard.read_mat(HAZ_TEST_MAT)
     impact = Impact()
     ent.exposures.assign_centroids(hazard)
     impact.calc(ent.exposures, ent.impact_funcs, hazard)
     return impact
示例#12
0
    def test_wrongDisc_fail(self):
        """Wrong discount rates"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        ent.disc_rates.rates = np.array([1, 2])
        with self.assertRaises(ValueError) as cm:
            ent.check()
        self.assertIn('DiscRates.rates', str(cm.exception))

        with self.assertRaises(ValueError) as cm:
            ent.disc_rates = Exposures()
        self.assertIn('DiscRates', str(cm.exception))
示例#13
0
    def test_wrongImpFun_fail(self):
        """Wrong impact functions"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        ent.impact_funcs.get_func('TC', 1).paa = np.array([1, 2])
        with self.assertRaises(ValueError) as cm:
            ent.check()
        self.assertIn('ImpactFunc.paa', str(cm.exception))

        with self.assertRaises(ValueError) as cm:
            ent.impact_funcs = Exposures()
        self.assertIn('ImpactFuncSet', str(cm.exception))
示例#14
0
    def test_wrongMeas_fail(self):
        """Wrong measures"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        actions = ent.measures.get_measure('TC')
        actions[0].color_rgb = np.array([1, 2])
        with self.assertRaises(ValueError) as cm:
            ent.check()
        self.assertIn('Measure.color_rgb', str(cm.exception))

        with self.assertRaises(ValueError) as cm:
            ent.measures = Exposures()
        self.assertIn('MeasureSet', str(cm.exception))
示例#15
0
    def test_wrongImpFun_fail(self):
        """Wrong impact functions"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        ent.impact_funcs.get_func('TC', 1).paa = np.array([1, 2])
        with self.assertLogs('climada.util.checker', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.check()
        self.assertIn('ImpactFunc.paa', cm.output[0])

        with self.assertLogs('climada.entity.entity_def', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.impact_funcs = Exposures()
        self.assertIn('ImpactFuncSet', cm.output[0])
示例#16
0
    def test_wrongDisc_fail(self):
        """Wrong discount rates"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        ent.disc_rates.rates = np.array([1, 2])
        with self.assertLogs('climada.util.checker', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.check()
        self.assertIn('DiscRates.rates', cm.output[0])

        with self.assertLogs('climada.entity.entity_def', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.disc_rates = Exposures()
        self.assertIn('DiscRates', cm.output[0])
    def test_calc_change_pass(self):
        """Test calc with future change"""
        # present
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.exposures.rename(columns={'if_': 'if_TC'}, inplace=True)
        entity.check()
        entity.exposures.ref_year = 2018

        # future
        ent_future = Entity()
        ent_future.read_excel(ENT_DEMO_FUTURE)
        ent_future.check()
        ent_future.exposures.ref_year = 2040

        haz_future = copy.deepcopy(hazard)
        haz_future.intensity.data += 25

        cost_ben = CostBenefit()
        cost_ben.calc(hazard, entity, haz_future, ent_future)

        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)
        self.assertEqual(cost_ben.tot_climate_risk, 5.768659152882021e+11)

        self.assertEqual(cost_ben.imp_meas_present['no measure']['risk'], 6.51220115756442e+09)
        self.assertEqual(cost_ben.imp_meas_present['Mangroves']['risk'], 4.850407096284983e+09)
        self.assertEqual(cost_ben.imp_meas_present['Beach nourishment']['risk'], 5.188921355413834e+09)
        self.assertEqual(cost_ben.imp_meas_present['Seawall']['risk'], 4.736400526119911e+09)
        self.assertEqual(cost_ben.imp_meas_present['Building code']['risk'], 4.884150868173321e+09)

        self.assertEqual(cost_ben.imp_meas_future['no measure']['risk'], 5.9506659786664024e+10)
        self.assertEqual(cost_ben.imp_meas_future['Mangroves']['risk'], 4.826231151473135e+10)
        self.assertEqual(cost_ben.imp_meas_future['Beach nourishment']['risk'], 5.0647250923231674e+10)
        self.assertEqual(cost_ben.imp_meas_future['Seawall']['risk'], 21089567135.7345)
        self.assertEqual(cost_ben.imp_meas_future['Building code']['risk'], 4.462999483999791e+10)

        self.assertAlmostEqual(cost_ben.benefit['Mangroves'], 113345027690.81276)
        self.assertAlmostEqual(cost_ben.benefit['Beach nourishment'], 89444869971.53653)
        self.assertAlmostEqual(cost_ben.benefit['Seawall'], 347977469896.1333)
        self.assertAlmostEqual(cost_ben.benefit['Building code'], 144216478822.05154)

        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Mangroves'], 0.011573232523528404)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Beach nourishment'], 0.01931916274851638)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Seawall'], 0.025515385913577368)
        self.assertAlmostEqual(cost_ben.cost_ben_ratio['Building code'], 0.06379298728650741)

        self.assertEqual(cost_ben.tot_climate_risk, 576865915288.2021)
示例#18
0
    def test_calc_impact_transf_pass(self):
        """ Test calc_impact method: apply all measures and insurance """

        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)

        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.exposures.rename(columns={'if_': 'if_TC'}, inplace=True)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        meas = entity.measures.get_measure(name='Beach nourishment',
                                           haz_type='TC')
        meas.haz_type = 'TC'
        meas.hazard_inten_imp = (1, 0)
        meas.mdd_impact = (1, 0)
        meas.paa_impact = (1, 0)
        meas.risk_transf_attach = 5.0e8
        meas.risk_transf_cover = 1.0e9
        entity.check()

        imp, risk_transf = entity.measures.get_measure(
            name='Beach nourishment',
            haz_type='TC').calc_impact(entity.exposures, entity.impact_funcs,
                                       hazard)

        self.assertAlmostEqual(imp.aai_agg, 6.280804242609713e+09)
        self.assertAlmostEqual(imp.at_event[0], 0)
        self.assertAlmostEqual(imp.at_event[12], 8.648764833437817e+07)
        self.assertAlmostEqual(imp.at_event[41], 500000000)
        self.assertAlmostEqual(imp.at_event[11890], 6.498096646836635e+07)
        self.assertTrue(
            np.array_equal(imp.coord_exp[:, 0], entity.exposures.latitude))
        self.assertTrue(
            np.array_equal(imp.coord_exp[:, 1], entity.exposures.longitude))
        self.assertTrue(np.array_equal(imp.eai_exp, np.array([])))
        self.assertAlmostEqual(imp.tot_value, 6.570532945599105e+11)
        self.assertEqual(imp.unit, 'USD')
        self.assertEqual(imp.imp_mat, [])
        self.assertTrue(np.array_equal(imp.event_id, hazard.event_id))
        self.assertTrue(np.array_equal(imp.date, hazard.date))
        self.assertEqual(imp.event_name, hazard.event_name)
        self.assertEqual(imp.tag['exp'].file_name,
                         entity.exposures.tag.file_name)
        self.assertEqual(imp.tag['haz'].file_name, hazard.tag.file_name)
        self.assertEqual(imp.tag['if_set'].file_name,
                         entity.impact_funcs.tag.file_name)
        self.assertEqual(risk_transf, 2.3139691495470852e+08)
    def test_calc_change_pass(self):
        """Test calc with future change"""
        # present
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.exposures.rename(columns={'if_': 'if_TC'}, inplace=True)
        entity.check()
        entity.exposures.ref_year = 2018

        # future
        ent_future = Entity()
        ent_future.read_excel(ENT_DEMO_FUTURE)
        ent_future.check()
        ent_future.exposures.ref_year = 2040

        haz_future = copy.deepcopy(hazard)
        haz_future.intensity.data += 25

        cost_ben = CostBenefit()
        cost_ben.calc(hazard, entity, haz_future, ent_future)

        self.assertEqual(cost_ben.present_year, 2018)
        self.assertEqual(cost_ben.future_year, 2040)
        self.assertEqual(cost_ben.tot_climate_risk, 5.768659152882021e+11)

        self.assertEqual(cost_ben.imp_meas_present['no measure']['risk'],
                         6.51220115756442e+09)
        self.assertEqual(cost_ben.imp_meas_present['Mangroves']['risk'],
                         4.850407096284983e+09)
        self.assertEqual(
            cost_ben.imp_meas_present['Beach nourishment']['risk'],
            5.188921355413834e+09)
        self.assertEqual(cost_ben.imp_meas_present['Seawall']['risk'],
                         4.736400526119911e+09)
        self.assertEqual(cost_ben.imp_meas_present['Building code']['risk'],
                         4.884150868173321e+09)

        self.assertEqual(cost_ben.imp_meas_future['no measure']['risk'],
                         5.9506659786664024e+10)
        self.assertEqual(cost_ben.imp_meas_future['Mangroves']['risk'],
                         4.826231151473135e+10)
        self.assertEqual(cost_ben.imp_meas_future['Beach nourishment']['risk'],
                         5.0647250923231674e+10)
        self.assertEqual(cost_ben.imp_meas_future['Seawall']['risk'],
                         21089567135.7345)
        self.assertEqual(cost_ben.imp_meas_future['Building code']['risk'],
                         4.462999483999791e+10)
    def test_apply_transf_future_pass(self):
        """ Test apply_risk_transfer with present and future """
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        entity = Entity()
        entity.read_excel(ENT_DEMO_TODAY)
        entity.check()
        entity.exposures.ref_year = 2018

        fut_ent = copy.deepcopy(entity)
        fut_ent.exposures.ref_year = 2040

        cost_ben = CostBenefit()
        cost_ben.calc(hazard, entity, ent_future=fut_ent, risk_func=risk_aai_agg,
                      imp_time_depen=None, save_imp=True)

        new_name = 'combine'
        new_color = np.array([0.1, 0.1, 0.1])
        risk_transf=(1.0e7, 15.0e11, 1)
        new_cb = cost_ben.combine_measures(['Mangroves', 'Seawall'], new_name, new_color,
            entity.disc_rates, imp_time_depen=None, risk_func=risk_aai_agg)
        new_cb.apply_risk_transfer(new_name, risk_transf[0], risk_transf[1],
            entity.disc_rates, cost_fix=0, cost_factor=risk_transf[2], imp_time_depen=1,
            risk_func=risk_aai_agg)

        tr_name = 'risk transfer (' + new_name + ')'
        new_imp = cost_ben.imp_meas_future['no measure']['impact'].at_event - \
            cost_ben.imp_meas_future['Mangroves']['impact'].at_event
        new_imp += cost_ben.imp_meas_future['no measure']['impact'].at_event - \
            cost_ben.imp_meas_future['Seawall']['impact'].at_event
        new_imp = np.maximum(cost_ben.imp_meas_future['no measure']['impact'].at_event - new_imp, 0)
        imp_layer = np.minimum(np.maximum(new_imp - risk_transf[0], 0), risk_transf[1])
        risk_transfer = np.sum(imp_layer * cost_ben.imp_meas_future['no measure']['impact'].frequency)
        new_imp = np.maximum(new_imp - imp_layer, 0)

        self.assertTrue(np.allclose(new_cb.color_rgb[new_name], new_color))
        self.assertEqual(len(new_cb.imp_meas_present), 3)
        self.assertTrue(np.allclose(new_cb.imp_meas_future[tr_name]['impact'].at_event, new_imp))
        self.assertTrue(np.allclose(new_cb.imp_meas_present[tr_name]['impact'].at_event, new_imp))
        self.assertAlmostEqual(new_cb.imp_meas_future[tr_name]['risk'],
                               np.sum(new_imp*cost_ben.imp_meas_future['no measure']['impact'].frequency), 5)
        self.assertAlmostEqual(new_cb.imp_meas_present[tr_name]['risk'],
                               np.sum(new_imp*cost_ben.imp_meas_future['no measure']['impact'].frequency), 5)
        self.assertAlmostEqual(new_cb.cost_ben_ratio[tr_name]*new_cb.benefit[tr_name], 69715165679.7042)
        self.assertTrue(np.allclose(new_cb.imp_meas_future[tr_name]['efc'].impact,
                                    new_cb.imp_meas_future[tr_name]['impact'].calc_freq_curve().impact))
        self.assertAlmostEqual(new_cb.imp_meas_future[tr_name]['risk_transf'], risk_transfer)
        self.assertAlmostEqual(new_cb.benefit[tr_name], 69715165679.7042, 4) # benefit = impact layer
        self.assertAlmostEqual(new_cb.cost_ben_ratio[tr_name], 1)
示例#21
0
    def test_wrongMeas_fail(self):
        """Wrong measures"""
        ent = Entity()
        ent.read_excel(ENT_TEMPLATE_XLS)
        actions = ent.measures.get_measure('TC')
        actions[0].color_rgb = np.array([1, 2])
        with self.assertLogs('climada.util.checker', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.check()
        self.assertIn('Measure.color_rgb', cm.output[0])

        with self.assertLogs('climada.entity.entity_def', level='ERROR') as cm:
            with self.assertRaises(ValueError):
                ent.measures = Exposures()
        self.assertIn('MeasureSet', cm.output[0])
示例#22
0
    def test_ref_value_pass(self):
        """Test result against reference value"""
        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # Compute the impact over the whole exposures
        impact.calc(ent.exposures, ent.impact_funcs, hazard)

        # Check result
        num_events = len(hazard.event_id)
        num_exp = ent.exposures.shape[0]
        # Check relative errors as well when absolute value gt 1.0e-7
        # impact.at_event == EDS.damage in MATLAB
        self.assertEqual(num_events, len(impact.at_event))
        self.assertEqual(0, impact.at_event[0])
        self.assertEqual(0, impact.at_event[int(num_events / 2)])
        self.assertAlmostEqual(1.472482938320243e+08, impact.at_event[13809])
        self.assertEqual(7.076504723057620e+10, impact.at_event[12147])
        self.assertEqual(0, impact.at_event[num_events - 1])
        # impact.eai_exp == EDS.ED_at_centroid in MATLAB
        self.assertEqual(num_exp, len(impact.eai_exp))
        self.assertAlmostEqual(1.518553670803242e+08, impact.eai_exp[0])
        self.assertAlmostEqual(1.373490457046383e+08,
                               impact.eai_exp[int(num_exp / 2)], 6)
        self.assertTrue(
            np.isclose(1.373490457046383e+08,
                       impact.eai_exp[int(num_exp / 2)]))
        self.assertAlmostEqual(1.066837260150042e+08,
                               impact.eai_exp[num_exp - 1], 6)
        self.assertTrue(
            np.isclose(1.066837260150042e+08,
                       impact.eai_exp[int(num_exp - 1)]))
        # impact.tot_value == EDS.Value in MATLAB
        # impact.aai_agg == EDS.ED in MATLAB
        self.assertAlmostEqual(6.570532945599105e+11, impact.tot_value)
        self.assertAlmostEqual(6.512201157564421e+09, impact.aai_agg, 5)
        self.assertTrue(np.isclose(6.512201157564421e+09, impact.aai_agg))
示例#23
0
    def test_calc_impact_pass(self):
        """Test calc_impact method: apply all measures but insurance"""

        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)

        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.exposures.gdf.rename(columns={'if_': 'if_TC'}, inplace=True)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        entity.measures.get_measure(name='Mangroves',
                                    haz_type='TC').haz_type = 'TC'
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        imp, risk_transf = entity.measures.get_measure(
            'TC', 'Mangroves').calc_impact(entity.exposures,
                                           entity.impact_funcs, hazard)

        self.assertAlmostEqual(imp.aai_agg, 4.850407096284983e+09)
        self.assertAlmostEqual(imp.at_event[0], 0)
        self.assertAlmostEqual(imp.at_event[12], 1.470194187501225e+07)
        self.assertAlmostEqual(imp.at_event[41], 4.7226357936631286e+08)
        self.assertAlmostEqual(imp.at_event[11890], 1.742110428135755e+07)
        self.assertTrue(
            np.array_equal(imp.coord_exp[:, 0], entity.exposures.gdf.latitude))
        self.assertTrue(
            np.array_equal(imp.coord_exp[:, 1],
                           entity.exposures.gdf.longitude))
        self.assertAlmostEqual(imp.eai_exp[0], 1.15677655725858e+08)
        self.assertAlmostEqual(imp.eai_exp[-1], 7.528669956120645e+07)
        self.assertAlmostEqual(imp.tot_value, 6.570532945599105e+11)
        self.assertEqual(imp.unit, 'USD')
        self.assertEqual(imp.imp_mat.shape, (0, 0))
        self.assertTrue(np.array_equal(imp.event_id, hazard.event_id))
        self.assertTrue(np.array_equal(imp.date, hazard.date))
        self.assertEqual(imp.event_name, hazard.event_name)
        self.assertEqual(imp.tag['exp'].file_name,
                         entity.exposures.tag.file_name)
        self.assertEqual(imp.tag['haz'].file_name, hazard.tag.file_name)
        self.assertEqual(imp.tag['if_set'].file_name,
                         entity.impact_funcs.tag.file_name)
        self.assertEqual(risk_transf.aai_agg, 0)
示例#24
0
    def test_select_event_identity_pass(self):
        """ test select same impact with event name, id and date """

        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        imp = Impact()

        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)

        # Compute the impact over the whole exposures
        imp.calc(ent.exposures, ent.impact_funcs, hazard, save_mat=True)

        sel_imp = imp.select(event_ids=imp.event_id,
                             event_names=imp.event_name,
                             dates=(min(imp.date), max(imp.date)))

        self.assertEqual(sel_imp.crs, imp.crs)
        self.assertEqual(sel_imp.unit, imp.unit)

        self.assertTrue(np.array_equal(sel_imp.event_id, imp.event_id))
        self.assertEqual(sel_imp.event_name, imp.event_name)
        self.assertTrue(np.array_equal(sel_imp.date, imp.date))
        self.assertTrue(np.array_equal(sel_imp.frequency, imp.frequency))

        self.assertTrue(np.array_equal(sel_imp.at_event, imp.at_event))
        self.assertTrue(
            np.array_equal(sel_imp.imp_mat.todense(), imp.imp_mat.todense()))
        self.assertTrue(np.array_equal(sel_imp.eai_exp, imp.eai_exp))
        self.assertAlmostEqual(round(sel_imp.aai_agg, 5),
                               round(imp.aai_agg, 5))

        self.assertEqual(sel_imp.tot_value, imp.tot_value)
        self.assertTrue(np.array_equal(sel_imp.coord_exp, imp.coord_exp))

        self.assertIsInstance(sel_imp, Impact)
        self.assertIsInstance(sel_imp.imp_mat, sparse.csr_matrix)
示例#25
0
    def test_calc_if_pass(self):
        """Execute when no if_HAZ present, but only if_"""
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.exposures.gdf.rename(columns={'if_TC': 'if_'}, inplace=True)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()
        impact.calc(ent.exposures, ent.impact_funcs, hazard)

        # Check result
        num_events = len(hazard.event_id)
        num_exp = ent.exposures.gdf.shape[0]
        # Check relative errors as well when absolute value gt 1.0e-7
        # impact.at_event == EDS.damage in MATLAB
        self.assertEqual(num_events, len(impact.at_event))
        self.assertEqual(0, impact.at_event[0])
        self.assertEqual(0, impact.at_event[int(num_events / 2)])
        self.assertAlmostEqual(1.472482938320243e+08, impact.at_event[13809])
        self.assertEqual(7.076504723057620e+10, impact.at_event[12147])
        self.assertEqual(0, impact.at_event[num_events - 1])
        # impact.eai_exp == EDS.ED_at_centroid in MATLAB
        self.assertEqual(num_exp, len(impact.eai_exp))
        self.assertAlmostEqual(1.518553670803242e+08, impact.eai_exp[0])
        self.assertAlmostEqual(1.373490457046383e+08,
                               impact.eai_exp[int(num_exp / 2)], 6)
        self.assertTrue(
            np.isclose(1.373490457046383e+08,
                       impact.eai_exp[int(num_exp / 2)]))
        self.assertAlmostEqual(1.066837260150042e+08,
                               impact.eai_exp[num_exp - 1], 6)
        self.assertTrue(
            np.isclose(1.066837260150042e+08,
                       impact.eai_exp[int(num_exp - 1)]))
        # impact.tot_value == EDS.Value in MATLAB
        # impact.aai_agg == EDS.ED in MATLAB
        self.assertAlmostEqual(6.570532945599105e+11, impact.tot_value)
        self.assertAlmostEqual(6.512201157564421e+09, impact.aai_agg, 5)
        self.assertTrue(np.isclose(6.512201157564421e+09, impact.aai_agg))
示例#26
0
    def test_local_exceedance_imp_pass(self):
        """Test calc local impacts per return period"""
        # Read default entity values
        ent = Entity()
        ent.read_excel(ENT_DEMO_TODAY)
        ent.check()

        # Read default hazard file
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        # Create impact object
        impact = Impact()
        # Assign centroids to exposures
        ent.exposures.assign_centroids(hazard)
        # Compute the impact over the whole exposures
        impact.calc(ent.exposures, ent.impact_funcs, hazard, save_mat=True)
        # Compute the impact per return period over the whole exposures
        impact_rp = impact.local_exceedance_imp(return_periods=(10, 40))

        self.assertTrue(isinstance(impact_rp, np.ndarray))
        self.assertEqual(impact_rp.size, 2 * ent.exposures.value.size)
        self.assertAlmostEqual(np.max(impact_rp), 2916964966.388219, places=5)
        self.assertAlmostEqual(np.min(impact_rp), 444457580.131494, places=5)
示例#27
0
    def test_apply_ref_pass(self):
        """Test apply method: apply all measures but insurance"""
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)
        hazard.haz_type = 'TC'

        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        new_exp, new_ifs, new_haz = entity.measures.get_measure('TC', 'Mangroves').apply(entity.exposures,
            entity.impact_funcs, hazard)

        self.assertTrue(new_exp is entity.exposures)
        self.assertTrue(new_haz is hazard)
        self.assertFalse(new_ifs is entity.impact_funcs)

        new_imp = new_ifs.get_func('TC')[0]
        self.assertTrue(np.array_equal(new_imp.intensity, np.array([4., 24., 34., 44.,
            54., 64., 74., 84., 104.])))
        self.assertTrue(np.allclose(new_imp.mdd, np.array([0, 0, 0.021857142857143, 0.035887500000000,
            0.053977415307403, 0.103534246575342, 0.180414000000000, 0.410796000000000, 0.410796000000000])))
        self.assertTrue(np.allclose(new_imp.paa, np.array([0, 0.005000000000000, 0.042000000000000,
            0.160000000000000, 0.398500000000000, 0.657000000000000, 1.000000000000000,
            1.000000000000000, 1.000000000000000])))

        new_imp = new_ifs.get_func('TC')[1]
        self.assertTrue(np.array_equal(new_imp.intensity, np.array([4., 24., 34., 44.,
            54., 64., 74., 84., 104.])))
        self.assertTrue(np.allclose(new_imp.mdd, np.array([0, 0, 0, 0.025000000000000,
            0.054054054054054, 0.104615384615385, 0.211764705882353, 0.400000000000000, 0.400000000000000])))
        self.assertTrue(np.allclose(new_imp.paa, np.array([0, 0.004000000000000, 0, 0.160000000000000,
            0.370000000000000, 0.650000000000000, 0.850000000000000, 1.000000000000000,
            1.000000000000000])))
def ent_fut_dem():
    entity = Entity()
    entity.read_excel(ENT_DEMO_FUTURE)
    entity.exposures.ref_year = 2040
    entity.check()
    return entity
def ent_dem():
    entity = Entity()
    entity.read_excel(ENT_DEMO_TODAY)
    entity.exposures.ref_year = 2018
    entity.check()
    return entity
示例#30
0
    def test_calc_impact_measures_pass(self):
        """Test _calc_impact_measures against reference value"""
        self.assertTrue(HAZ_TEST_MAT.is_file(),
                        "{} is not a file".format(HAZ_TEST_MAT))
        hazard = Hazard('TC')
        hazard.read_mat(HAZ_TEST_MAT)

        self.assertTrue(ENT_TEST_MAT.is_file(),
                        "{} is not a file".format(ENT_TEST_MAT))
        entity = Entity()
        entity.read_mat(ENT_TEST_MAT)
        entity.check()
        entity.measures._data['TC'] = entity.measures._data.pop('XX')
        for meas in entity.measures.get_measure('TC'):
            meas.haz_type = 'TC'
        entity.check()

        cost_ben = CostBenefit()
        cost_ben._calc_impact_measures(hazard,
                                       entity.exposures,
                                       entity.measures,
                                       entity.impact_funcs,
                                       when='future',
                                       risk_func=risk_aai_agg,
                                       save_imp=True)

        self.assertEqual(cost_ben.imp_meas_present, dict())
        self.assertEqual(cost_ben.cost_ben_ratio, dict())
        self.assertEqual(cost_ben.benefit, dict())
        self.assertEqual(cost_ben.tot_climate_risk, 0.0)
        self.assertEqual(cost_ben.present_year, 2016)
        self.assertEqual(cost_ben.future_year, 2030)

        self.assertEqual(cost_ben.imp_meas_future['no measure']['cost'],
                         (0, 0))
        self.assertAlmostEqual(cost_ben.imp_meas_future['no measure']['risk'],
                               6.51220115756442e+09,
                               places=3)
        new_efc = cost_ben.imp_meas_future['no measure'][
            'impact'].calc_freq_curve()
        self.assertTrue(
            np.allclose(
                new_efc.return_per,
                cost_ben.imp_meas_future['no measure']['efc'].return_per))
        self.assertTrue(
            np.allclose(new_efc.impact,
                        cost_ben.imp_meas_future['no measure']['efc'].impact))
        self.assertEqual(
            cost_ben.imp_meas_future['no measure']
            ['impact'].at_event.nonzero()[0].size, 841)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['no measure']['impact'].at_event[14082],
            8.801682862431524e+06,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['no measure']['impact'].tot_value,
            6.570532945599105e+11,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['no measure']['impact'].aai_agg,
            6.51220115756442e+09,
            places=3)

        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Mangroves']['cost'][0],
            1.3117683608515418e+09,
            places=3)
        self.assertEqual(cost_ben.imp_meas_future['Mangroves']['cost'][1], 1)
        self.assertAlmostEqual(cost_ben.imp_meas_future['Mangroves']['risk'],
                               4.850407096284983e+09,
                               places=3)
        new_efc = cost_ben.imp_meas_future['Mangroves'][
            'impact'].calc_freq_curve()
        self.assertTrue(
            np.allclose(
                new_efc.return_per,
                cost_ben.imp_meas_future['Mangroves']['efc'].return_per))
        self.assertTrue(
            np.allclose(new_efc.impact,
                        cost_ben.imp_meas_future['Mangroves']['efc'].impact))
        self.assertEqual(
            cost_ben.imp_meas_future['Mangroves']['impact'].at_event.nonzero()
            [0].size, 665)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Mangroves']['impact'].at_event[13901],
            1.29576562770977e+09,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Mangroves']['impact'].tot_value,
            6.570532945599105e+11,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Mangroves']['impact'].aai_agg,
            4.850407096284983e+09,
            places=3)

        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Beach nourishment']['cost'][0],
            1.728000000000000e+09,
            places=3)
        self.assertEqual(
            cost_ben.imp_meas_future['Beach nourishment']['cost'][1], 1)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Beach nourishment']['risk'],
            5.188921355413834e+09,
            places=3)
        new_efc = cost_ben.imp_meas_future['Beach nourishment'][
            'impact'].calc_freq_curve()
        self.assertTrue(
            np.allclose(
                new_efc.return_per,
                cost_ben.imp_meas_future['Beach nourishment']
                ['efc'].return_per))
        self.assertTrue(
            np.allclose(
                new_efc.impact,
                cost_ben.imp_meas_future['Beach nourishment']['efc'].impact))
        self.assertEqual(
            cost_ben.imp_meas_future['Beach nourishment']
            ['impact'].at_event.nonzero()[0].size, 702)
        self.assertEqual(
            cost_ben.imp_meas_future['Beach nourishment']
            ['impact'].at_event[1110], 0.0)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Beach nourishment']['impact'].eai_exp[5],
            1.1133679079730146e+08,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Beach nourishment']['impact'].tot_value,
            6.570532945599105e+11,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Beach nourishment']['impact'].aai_agg,
            5.188921355413834e+09,
            places=3)

        self.assertAlmostEqual(cost_ben.imp_meas_future['Seawall']['cost'][0],
                               8.878779433630093e+09,
                               places=3)
        self.assertEqual(cost_ben.imp_meas_future['Seawall']['cost'][1], 1)
        self.assertAlmostEqual(cost_ben.imp_meas_future['Seawall']['risk'],
                               4.736400526119911e+09,
                               places=3)
        new_efc = cost_ben.imp_meas_future['Seawall'][
            'impact'].calc_freq_curve()
        self.assertTrue(
            np.allclose(new_efc.return_per,
                        cost_ben.imp_meas_future['Seawall']['efc'].return_per))
        self.assertTrue(
            np.allclose(new_efc.impact,
                        cost_ben.imp_meas_future['Seawall']['efc'].impact))
        self.assertEqual(
            cost_ben.imp_meas_future['Seawall']['impact'].at_event.nonzero()
            [0].size, 73)
        self.assertEqual(
            cost_ben.imp_meas_future['Seawall']['impact'].at_event[1229], 0.0)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Seawall']['impact'].tot_value,
            6.570532945599105e+11,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Seawall']['impact'].aai_agg,
            4.736400526119911e+09,
            places=3)

        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Building code']['cost'][0],
            9.200000000000000e+09,
            places=3)
        self.assertEqual(cost_ben.imp_meas_future['Building code']['cost'][1],
                         1)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Building code']['risk'],
            4.884150868173321e+09,
            places=3)
        new_efc = cost_ben.imp_meas_future['Building code'][
            'impact'].calc_freq_curve()
        self.assertTrue(
            np.allclose(
                new_efc.return_per,
                cost_ben.imp_meas_future['Building code']['efc'].return_per))
        self.assertTrue(
            np.allclose(
                new_efc.impact,
                cost_ben.imp_meas_future['Building code']['efc'].impact))
        self.assertEqual(
            cost_ben.imp_meas_future['Building code']
            ['impact'].at_event.nonzero()[0].size, 841)
        self.assertEqual(
            cost_ben.imp_meas_future['Building code']['impact'].at_event[122],
            0.0)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Building code']['impact'].eai_exp[11],
            7.757060129393841e+07,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Building code']['impact'].tot_value,
            6.570532945599105e+11,
            places=3)
        self.assertAlmostEqual(
            cost_ben.imp_meas_future['Building code']['impact'].aai_agg,
            4.884150868173321e+09,
            places=3)