@@ -98,13 +98,13 @@ def setUp(self):
9898 )
9999
100100 # Create mock snapshots
101- self .mock_snapshot0 = Snapshot (
101+ self .mock_snapshot_start = Snapshot (
102102 self .exposure_present ,
103103 self .hazard_present ,
104104 self .impfset_present ,
105105 self .present_date ,
106106 )
107- self .mock_snapshot1 = Snapshot (
107+ self .mock_snapshot_end = Snapshot (
108108 self .exposure_future ,
109109 self .hazard_future ,
110110 self .impfset_future ,
@@ -113,8 +113,8 @@ def setUp(self):
113113
114114 # Create an instance of CalcRiskPeriod
115115 self .calc_risk_period = CalcRiskPeriod (
116- self .mock_snapshot0 ,
117- self .mock_snapshot1 ,
116+ self .mock_snapshot_start ,
117+ self .mock_snapshot_end ,
118118 time_resolution = "AS-JAN" ,
119119 interpolation_strategy = AllLinearStrategy (),
120120 impact_computation_strategy = ImpactCalcComputation (),
@@ -125,8 +125,8 @@ def setUp(self):
125125 )
126126
127127 def test_init (self ):
128- self .assertEqual (self .calc_risk_period .snapshot_start , self .mock_snapshot0 )
129- self .assertEqual (self .calc_risk_period .snapshot_end , self .mock_snapshot1 )
128+ self .assertEqual (self .calc_risk_period .snapshot_start , self .mock_snapshot_start )
129+ self .assertEqual (self .calc_risk_period .snapshot_end , self .mock_snapshot_end )
130130 self .assertEqual (self .calc_risk_period .time_resolution , "AS-JAN" )
131131 self .assertEqual (
132132 self .calc_risk_period .time_points , self .future_date - self .present_date + 1
@@ -139,11 +139,11 @@ def test_init(self):
139139 )
140140 np .testing .assert_array_equal (
141141 self .calc_risk_period ._group_id_E0 ,
142- self .mock_snapshot0 .exposure .gdf ["group_id" ].values ,
142+ self .mock_snapshot_start .exposure .gdf ["group_id" ].values ,
143143 )
144144 np .testing .assert_array_equal (
145145 self .calc_risk_period ._group_id_E1 ,
146- self .mock_snapshot1 .exposure .gdf ["group_id" ].values ,
146+ self .mock_snapshot_end .exposure .gdf ["group_id" ].values ,
147147 )
148148 self .assertIsInstance (self .calc_risk_period .date_idx , pd .DatetimeIndex )
149149 self .assertEqual (
@@ -198,7 +198,7 @@ def test_set_time_points_wtype(self):
198198 with self .assertRaises (ValueError ):
199199 self .calc_risk_period .time_points = "1"
200200
201- def test_set_interval_freq (self ):
201+ def test_set_time_resolution (self ):
202202 self .calc_risk_period .time_resolution = "MS"
203203 self .assertEqual (self .calc_risk_period .time_resolution , "MS" )
204204 pd .testing .assert_index_equal (
@@ -298,10 +298,6 @@ def test_set_impact_computation_strategy_wtype(self):
298298 with self .assertRaises (ValueError ):
299299 self .calc_risk_period .impact_computation_strategy = "A"
300300
301- def test_set_calc_residual_wtype (self ):
302- with self .assertRaises (ValueError ):
303- self .calc_risk_period .calc_residual = "A"
304-
305301 # The computation are tested in the CalcImpactStrategy / InterpolationStrategyBase tests
306302 # Here we just make sure that the calling works
307303 @patch .object (CalcRiskPeriod , "impact_computation_strategy" )
@@ -321,9 +317,6 @@ def test_impacts_arrays(self, mock_impact_compute):
321317 self .calc_risk_period .snapshot_start ,
322318 self .calc_risk_period .snapshot_end ,
323319 fut ,
324- self .calc_risk_period .risk_transf_attach ,
325- self .calc_risk_period .risk_transf_cover ,
326- self .calc_risk_period .calc_residual ,
327320 )
328321 for fut in [
329322 (0 , 0 , 0 ),
@@ -340,43 +333,43 @@ def test_impacts_arrays(self, mock_impact_compute):
340333
341334 @patch .object (CalcRiskPeriod , "interpolation_strategy" )
342335 def test_imp_mats_H0V0 (self , mock_interpolate ):
343- mock_interpolate .interp_exposure_dim .return_value = 1
336+ mock_interpolate .interp_over_exposure_dim .return_value = 1
344337 result = self .calc_risk_period .imp_mats_H0V0
345338 self .assertEqual (result , 1 )
346- mock_interpolate .interp_exposure_dim .assert_called_with (
339+ mock_interpolate .interp_over_exposure_dim .assert_called_with (
347340 self .calc_risk_period .E0H0V0 .imp_mat ,
348341 self .calc_risk_period .E1H0V0 .imp_mat ,
349342 self .calc_risk_period .time_points ,
350343 )
351344
352345 @patch .object (CalcRiskPeriod , "interpolation_strategy" )
353346 def test_imp_mats_H1V0 (self , mock_interpolate ):
354- mock_interpolate .interp_exposure_dim .return_value = 1
347+ mock_interpolate .interp_over_exposure_dim .return_value = 1
355348 result = self .calc_risk_period .imp_mats_H1V0
356349 self .assertEqual (result , 1 )
357- mock_interpolate .interp_exposure_dim .assert_called_with (
350+ mock_interpolate .interp_over_exposure_dim .assert_called_with (
358351 self .calc_risk_period .E0H1V0 .imp_mat ,
359352 self .calc_risk_period .E1H1V0 .imp_mat ,
360353 self .calc_risk_period .time_points ,
361354 )
362355
363356 @patch .object (CalcRiskPeriod , "interpolation_strategy" )
364357 def test_imp_mats_H0V1 (self , mock_interpolate ):
365- mock_interpolate .interp_exposure_dim .return_value = 1
358+ mock_interpolate .interp_over_exposure_dim .return_value = 1
366359 result = self .calc_risk_period .imp_mats_H0V1
367360 self .assertEqual (result , 1 )
368- mock_interpolate .interp_exposure_dim .assert_called_with (
361+ mock_interpolate .interp_over_exposure_dim .assert_called_with (
369362 self .calc_risk_period .E0H0V1 .imp_mat ,
370363 self .calc_risk_period .E1H0V1 .imp_mat ,
371364 self .calc_risk_period .time_points ,
372365 )
373366
374367 @patch .object (CalcRiskPeriod , "interpolation_strategy" )
375368 def test_imp_mats_H1V1 (self , mock_interpolate ):
376- mock_interpolate .interp_exposure_dim .return_value = 1
369+ mock_interpolate .interp_over_exposure_dim .return_value = 1
377370 result = self .calc_risk_period .imp_mats_H1V1
378371 self .assertEqual (result , 1 )
379- mock_interpolate .interp_exposure_dim .assert_called_with (
372+ mock_interpolate .interp_over_exposure_dim .assert_called_with (
380373 self .calc_risk_period .E0H1V1 .imp_mat ,
381374 self .calc_risk_period .E1H1V1 .imp_mat ,
382375 self .calc_risk_period .time_points ,
@@ -609,14 +602,14 @@ def setUp(self):
609602 self .calc_risk_period .date_idx = pd .DatetimeIndex (
610603 ["2020-01-01" , "2025-01-01" , "2030-01-01" ], name = "date"
611604 )
612- self .calc_risk_period .snapshot0 .exposure .gdf = gpd .GeoDataFrame (
605+ self .calc_risk_period .snapshot_start .exposure .gdf = gpd .GeoDataFrame (
613606 {
614607 "group_id" : [1 , 2 , 2 ],
615608 "geometry" : [Point (0 , 0 ), Point (1 , 1 ), Point (2 , 2 )],
616609 "value" : [10 , 10 , 20 ],
617610 }
618611 )
619- self .calc_risk_period .snapshot1 .exposure .gdf = gpd .GeoDataFrame (
612+ self .calc_risk_period .snapshot_end .exposure .gdf = gpd .GeoDataFrame (
620613 {
621614 "group_id" : [1 , 2 , 2 ],
622615 "geometry" : [Point (0 , 0 ), Point (1 , 1 ), Point (2 , 2 )],
@@ -627,20 +620,20 @@ def setUp(self):
627620 self .calc_risk_period .measure .name = "dummy_measure"
628621
629622 def test_calc_eai (self ):
630- # Mock the return values of interp_hazard_dim
631- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .side_effect = [
623+ # Mock the return values of interp_over_hazard_dim
624+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .side_effect = [
632625 "V0_interpolated_data" , # First call (for per_date_eai_V0)
633626 "V1_interpolated_data" , # Second call (for per_date_eai_V1)
634627 ]
635- # Mock the return value of interp_vulnerability_dim
636- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .return_value = (
628+ # Mock the return value of interp_over_vulnerability_dim
629+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .return_value = (
637630 "final_eai_result"
638631 )
639632
640633 result = self .calc_risk_period .calc_eai ()
641634
642- # Assert that interp_hazard_dim was called with the correct arguments
643- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .assert_has_calls (
635+ # Assert that interp_over_hazard_dim was called with the correct arguments
636+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .assert_has_calls (
644637 [
645638 call (
646639 self .calc_risk_period .per_date_eai_H0V0 ,
@@ -653,8 +646,8 @@ def test_calc_eai(self):
653646 ]
654647 )
655648
656- # Assert that interp_vulnerability_dim was called with the results of interp_hazard_dim
657- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .assert_called_once_with (
649+ # Assert that interp_over_vulnerability_dim was called with the results of interp_over_hazard_dim
650+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .assert_called_once_with (
658651 "V0_interpolated_data" , "V1_interpolated_data"
659652 )
660653
@@ -743,25 +736,25 @@ def test_calc_return_periods_metric(self):
743736 self .calc_risk_period .per_date_return_periods_H1V0 .return_value = "H1V0"
744737 self .calc_risk_period .per_date_return_periods_H0V1 .return_value = "H0V1"
745738 self .calc_risk_period .per_date_return_periods_H1V1 .return_value = "H1V1"
746- # Mock the return values of interp_hazard_dim
747- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .side_effect = [
739+ # Mock the return values of interp_over_hazard_dim
740+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .side_effect = [
748741 "V0_interpolated_data" , # First call (for per_date_rp_V0)
749742 "V1_interpolated_data" , # Second call (for per_date_rp_V1)
750743 ]
751- # Mock the return value of interp_vulnerability_dim
752- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .return_value = np .array (
744+ # Mock the return value of interp_over_vulnerability_dim
745+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .return_value = np .array (
753746 [[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]
754747 )
755748
756749 result = self .calc_risk_period .calc_return_periods_metric ([10 , 20 , 30 ])
757750
758- # Assert that interp_hazard_dim was called with the correct arguments
759- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .assert_has_calls (
751+ # Assert that interp_over_hazard_dim was called with the correct arguments
752+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .assert_has_calls (
760753 [call ("H0V0" , "H1V0" ), call ("H0V1" , "H1V1" )]
761754 )
762755
763- # Assert that interp_vulnerability_dim was called with the results of interp_hazard_dim
764- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .assert_called_once_with (
756+ # Assert that interp_over_vulnerability_dim was called with the results of interp_over_hazard_dim
757+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .assert_called_once_with (
765758 "V0_interpolated_data" , "V1_interpolated_data"
766759 )
767760
@@ -791,26 +784,26 @@ def test_calc_risk_components_metric(self):
791784 self .calc_risk_period .per_date_aai_H1V1 = np .array ([3 , 3 , 3 ])
792785 self .calc_risk_period .per_date_aai = np .array ([0 , 6 / 4 , 3 ])
793786
794- # Mock the return values of interp_hazard_dim
795- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .return_value = (
796- np . array ( [0 , 0.5 , 1 ])
787+ # Mock the return values of interp_over_hazard_dim
788+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .return_value = np . array (
789+ [0 , 0.5 , 1 ]
797790 )
798791
799- # Mock the return value of interp_vulnerability_dim
800- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .return_value = np .array (
792+ # Mock the return value of interp_over_vulnerability_dim
793+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .return_value = np .array (
801794 [0 , 1 , 2 ]
802795 )
803796
804797 result = self .calc_risk_period .calc_risk_components_metric ()
805798
806- # Assert that interp_hazard_dim was called with the correct arguments
807- self .calc_risk_period .interpolation_strategy .interp_hazard_dim .assert_called_once_with (
799+ # Assert that interp_over_hazard_dim was called with the correct arguments
800+ self .calc_risk_period .interpolation_strategy .interp_over_hazard_dim .assert_called_once_with (
808801 self .calc_risk_period .per_date_aai_H0V0 ,
809802 self .calc_risk_period .per_date_aai_H1V0 ,
810803 )
811804
812- # Assert that interp_vulnerability_dim was called with the results of interp_hazard_dim
813- self .calc_risk_period .interpolation_strategy .interp_vulnerability_dim .assert_called_once_with (
805+ # Assert that interp_over_vulnerability_dim was called with the results of interp_over_hazard_dim
806+ self .calc_risk_period .interpolation_strategy .interp_over_vulnerability_dim .assert_called_once_with (
814807 self .calc_risk_period .per_date_aai_H0V0 ,
815808 self .calc_risk_period .per_date_aai_H0V1 ,
816809 )
@@ -847,20 +840,17 @@ def test_calc_risk_components_metric(self):
847840 @patch ("climada.trajectories.riskperiod.CalcRiskPeriod" )
848841 def test_apply_measure (self , mock_CalcRiskPeriod ):
849842 mock_CalcRiskPeriod .return_value = MagicMock (spec = CalcRiskPeriod )
850- self .calc_risk_period .snapshot0 .apply_measure .return_value = 2
851- self .calc_risk_period .snapshot1 .apply_measure .return_value = 3
843+ self .calc_risk_period .snapshot_start .apply_measure .return_value = 2
844+ self .calc_risk_period .snapshot_end .apply_measure .return_value = 3
852845 result = self .calc_risk_period .apply_measure (self .calc_risk_period .measure )
853846 self .assertEqual (result .measure , self .calc_risk_period .measure )
854847 mock_CalcRiskPeriod .assert_called_with (
855848 2 ,
856849 3 ,
857- self .calc_risk_period .interval_freq ,
850+ self .calc_risk_period .time_resolution ,
858851 self .calc_risk_period .time_points ,
859852 self .calc_risk_period .interpolation_strategy ,
860853 self .calc_risk_period .impact_computation_strategy ,
861- self .calc_risk_period .risk_transf_attach ,
862- self .calc_risk_period .risk_transf_cover ,
863- self .calc_risk_period .calc_residual ,
864854 )
865855
866856
0 commit comments