Skip to content

Commit 0a3a301

Browse files
committed
removes risk transfer mechanism (for now)
1 parent 59bb831 commit 0a3a301

File tree

4 files changed

+7
-130
lines changed

4 files changed

+7
-130
lines changed

climada/trajectories/impact_calc_strat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def compute_impacts(
5454
snapshot0: Snapshot,
5555
snapshot1: Snapshot,
5656
future: tuple[int, int, int],
57-
risk_transf_attach: float | None,
58-
risk_transf_cover: float | None,
57+
risk_transf_attach: float | None = None,
58+
risk_transf_cover: float | None = None,
5959
calc_residual: bool = False,
6060
):
6161
impact = self.compute_impacts_pre_transfer(snapshot0, snapshot1, future)

climada/trajectories/risk_trajectory.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,8 @@ class RiskTrajectory:
4949
"""Calculates risk trajectories over a series of snapshots.
5050
5151
This class computes risk metrics over a series of snapshots,
52-
optionally applying risk discounting and risk transfer adjustments.
52+
optionally applying risk discounting.
5353
54-
Attributes
55-
----------
56-
start_date : datetime
57-
The start date of the risk trajectory.
58-
end_date : datetime
59-
The end date of the risk trajectory.
60-
risk_disc : DiscRates | None
61-
The discount rates for risk, default is None.
62-
risk_transf_cover : optional
63-
The risk transfer coverage, default is None.
64-
risk_transf_attach : optional
65-
The risk transfer attachment, default is None.
66-
risk_periods : list
67-
The computed RiskPeriod objects from the snapshots.
6854
"""
6955

7056
_grouper = ["measure", "metric"]
@@ -77,9 +63,6 @@ def __init__(
7763
interval_freq: str = "YS",
7864
all_groups_name: str = "All",
7965
risk_disc: DiscRates | None = None,
80-
risk_transf_cover=None,
81-
risk_transf_attach=None,
82-
calc_residual: bool = True,
8366
interpolation_strategy: InterpolationStrategyBase | None = None,
8467
impact_computation_strategy: ImpactComputationStrategy | None = None,
8568
):
@@ -92,9 +75,6 @@ def __init__(
9275
self.end_date = max([snapshot.date for snapshot in snapshots_list])
9376
self._interval_freq = interval_freq
9477
self.risk_disc = risk_disc
95-
self._risk_transf_cover = risk_transf_cover
96-
self._risk_transf_attach = risk_transf_attach
97-
self._calc_residual = calc_residual
9878
self._interpolation_strategy = interpolation_strategy or AllLinearStrategy()
9979
self._impact_computation_strategy = (
10080
impact_computation_strategy or ImpactCalcComputation()
@@ -207,9 +187,6 @@ def pairwise(container: list):
207187
interval_freq=self._interval_freq,
208188
interpolation_strategy=self._interpolation_strategy,
209189
impact_computation_strategy=self._impact_computation_strategy,
210-
risk_transf_cover=self.risk_transf_cover,
211-
risk_transf_attach=self.risk_transf_attach,
212-
calc_residual=self._calc_residual,
213190
)
214191
for start_snapshot, end_snapshot in pairwise(
215192
sorted(snapshots, key=lambda snap: snap.date)

climada/trajectories/riskperiod.py

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ def __init__(
114114
time_points: int | None = None,
115115
interpolation_strategy: InterpolationStrategyBase | None = None,
116116
impact_computation_strategy: ImpactComputationStrategy | None = None,
117-
risk_transf_attach: float | None = None,
118-
risk_transf_cover: float | None = None,
119-
calc_residual: bool = False,
120117
):
121118
LOGGER.debug("Instantiating new CalcRiskPeriod.")
122119
self._snapshot0 = snapshot0
@@ -132,9 +129,6 @@ def __init__(
132129
self.impact_computation_strategy = (
133130
impact_computation_strategy or ImpactCalcComputation()
134131
)
135-
self.risk_transf_attach = risk_transf_attach
136-
self.risk_transf_cover = risk_transf_cover
137-
self.calc_residual = calc_residual
138132
self.measure = None # Only possible to set with apply_measure to make sure snapshots are consistent
139133

140134
self._group_id_E0 = (
@@ -299,12 +293,7 @@ def impact_computation_strategy(self, value, /):
299293
@lazy_property
300294
def E0H0V0(self):
301295
return self.impact_computation_strategy.compute_impacts(
302-
self.snapshot0,
303-
self.snapshot1,
304-
(0, 0, 0),
305-
self.risk_transf_attach,
306-
self.risk_transf_cover,
307-
self.calc_residual,
296+
self.snapshot0, self.snapshot1, (0, 0, 0)
308297
)
309298

310299
@lazy_property
@@ -313,42 +302,24 @@ def E1H0V0(self):
313302
self.snapshot0,
314303
self.snapshot1,
315304
(1, 0, 0),
316-
self.risk_transf_attach,
317-
self.risk_transf_cover,
318-
self.calc_residual,
319305
)
320306

321307
@lazy_property
322308
def E0H1V0(self):
323309
return self.impact_computation_strategy.compute_impacts(
324-
self.snapshot0,
325-
self.snapshot1,
326-
(0, 1, 0),
327-
self.risk_transf_attach,
328-
self.risk_transf_cover,
329-
self.calc_residual,
310+
self.snapshot0, self.snapshot1, (0, 1, 0)
330311
)
331312

332313
@lazy_property
333314
def E1H1V0(self):
334315
return self.impact_computation_strategy.compute_impacts(
335-
self.snapshot0,
336-
self.snapshot1,
337-
(1, 1, 0),
338-
self.risk_transf_attach,
339-
self.risk_transf_cover,
340-
self.calc_residual,
316+
self.snapshot0, self.snapshot1, (1, 1, 0)
341317
)
342318

343319
@lazy_property
344320
def E0H0V1(self):
345321
return self.impact_computation_strategy.compute_impacts(
346-
self.snapshot0,
347-
self.snapshot1,
348-
(0, 0, 1),
349-
self.risk_transf_attach,
350-
self.risk_transf_cover,
351-
self.calc_residual,
322+
self.snapshot0, self.snapshot1, (0, 0, 1)
352323
)
353324

354325
@lazy_property
@@ -357,9 +328,6 @@ def E1H0V1(self):
357328
self.snapshot0,
358329
self.snapshot1,
359330
(1, 0, 1),
360-
self.risk_transf_attach,
361-
self.risk_transf_cover,
362-
self.calc_residual,
363331
)
364332

365333
@lazy_property
@@ -368,9 +336,6 @@ def E0H1V1(self):
368336
self.snapshot0,
369337
self.snapshot1,
370338
(0, 1, 1),
371-
self.risk_transf_attach,
372-
self.risk_transf_cover,
373-
self.calc_residual,
374339
)
375340

376341
@lazy_property
@@ -379,47 +344,10 @@ def E1H1V1(self):
379344
self.snapshot0,
380345
self.snapshot1,
381346
(1, 1, 1),
382-
self.risk_transf_attach,
383-
self.risk_transf_cover,
384-
self.calc_residual,
385347
)
386348

387349
###############################
388350

389-
######## Risk transfer ########
390-
391-
@property
392-
def risk_transf_attach(self):
393-
return self._risk_transfer_attach
394-
395-
@risk_transf_attach.setter
396-
def risk_transf_attach(self, value, /):
397-
self._risk_transfer_attach = value
398-
self._reset_impact_data()
399-
400-
@property
401-
def risk_transf_cover(self):
402-
return self._risk_transfer_cover
403-
404-
@risk_transf_cover.setter
405-
def risk_transf_cover(self, value, /):
406-
self._risk_transfer_cover = value
407-
self._reset_impact_data()
408-
409-
@property
410-
def calc_residual(self):
411-
return self._calc_residual
412-
413-
@calc_residual.setter
414-
def calc_residual(self, value, /):
415-
if not isinstance(value, bool):
416-
raise ValueError("Not a boolean")
417-
418-
self._calc_residual = value
419-
self._reset_impact_data()
420-
421-
###############################
422-
423351
### Impact Matrices arrays ####
424352

425353
@lazy_property
@@ -826,9 +754,6 @@ def apply_measure(self, measure: Measure):
826754
self.time_points,
827755
self.interpolation_strategy,
828756
self.impact_computation_strategy,
829-
self.risk_transf_attach,
830-
self.risk_transf_cover,
831-
self.calc_residual,
832757
)
833758

834759
risk_period.measure = measure

climada/trajectories/test/test_risk_trajectory.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ def test_init_basic(self):
8989
self.assertEqual(rt.start_date, self.mock_snapshot1.date)
9090
self.assertEqual(rt.end_date, self.mock_snapshot3.date)
9191
self.assertIsNone(rt.risk_disc)
92-
self.assertIsNone(rt._risk_transf_cover)
93-
self.assertIsNone(rt._risk_transf_attach)
94-
self.assertTrue(rt._calc_residual)
9592
self.assertEqual(rt._interpolation_strategy, self.mock_interpolation_strategy)
9693
self.assertEqual(
9794
rt._impact_computation_strategy, self.mock_impact_computation_strategy
@@ -110,9 +107,6 @@ def test_init_with_custom_params(self):
110107
interval_freq="MS",
111108
all_groups_name="CustomAll",
112109
risk_disc=mock_disc,
113-
risk_transf_cover=0.5,
114-
risk_transf_attach=0.1,
115-
calc_residual=False,
116110
interpolation_strategy=Mock(),
117111
impact_computation_strategy=Mock(),
118112
)
@@ -121,7 +115,6 @@ def test_init_with_custom_params(self):
121115
self.assertEqual(rt.risk_disc, mock_disc)
122116
self.assertEqual(rt._risk_transf_cover, 0.5)
123117
self.assertEqual(rt._risk_transf_attach, 0.1)
124-
self.assertFalse(rt._calc_residual)
125118

126119
## Test Properties (`@property` and `@setter`)
127120
def test_default_rp_getter_setter(self):
@@ -143,24 +136,6 @@ def test_default_rp_setter_validation(self):
143136
with self.assertRaises(ValueError):
144137
rt.default_rp = [10, "not an int"]
145138

146-
@patch("climada.trajectories.risk_trajectory.RiskTrajectory._reset_metrics")
147-
def test_risk_transf_cover_setter(self, mock_reset_metrics):
148-
rt = RiskTrajectory(self.snapshots_list)
149-
rt._risk_period_up_to_date = True # Simulate old state
150-
rt.risk_transf_cover = 0.5
151-
self.assertEqual(rt._risk_transf_cover, 0.5)
152-
self.assertFalse(rt._risk_period_up_to_date) # Should be set to False
153-
mock_reset_metrics.assert_called_once() # Should call reset_metrics
154-
155-
@patch("climada.trajectories.risk_trajectory.RiskTrajectory._reset_metrics")
156-
def test_risk_transf_attach_setter(self, mock_reset_metrics):
157-
rt = RiskTrajectory(self.snapshots_list)
158-
rt._risk_period_up_to_date = True # Simulate old state
159-
rt.risk_transf_attach = 0.1
160-
self.assertEqual(rt._risk_transf_attach, 0.1)
161-
self.assertFalse(rt._risk_period_up_to_date) # Should be set to False
162-
mock_reset_metrics.assert_called_once() # Should call reset_metrics
163-
164139
# --- Test Core Risk Period Calculation (`risk_periods` property and `_calc_risk_periods`) ---
165140
# This is critical as many other methods depend on it.
166141

0 commit comments

Comments
 (0)