Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

598 adaptation calculate impact adaptation option for time horizon #617

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ra2ce/analysis/adaptation/adaptation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from copy import deepcopy
from pathlib import Path

import numpy as np
from cleo.helpers import option
from geopandas import GeoDataFrame

from ra2ce.analysis.adaptation.adaptation_option_collection import (
Expand Down Expand Up @@ -76,6 +78,34 @@ def run_cost(self) -> GeoDataFrame:

return _cost_gdf

def run_impact(self) -> GeoDataFrame:
"""
Calculate the impact for all adaptation options
"""
return None

def run_net_present_impact(self) -> GeoDataFrame:
"""
Calculate the net present impact for all adaptation options for the entire time horizon.
"""
_impact_gdf = self.run_impact()
for _option in self.adaptation_collection.adaptation_options:

_impact_array = _impact_gdf[f"impact_{_option.id}"].to_numpy()

def calc_net_impact_time_horizon(event_impact: float):
_years_array = np.arange(0, self.adaptation_collection.time_horizon)
_frequency_per_year = self.adaptation_collection.initial_frequency + _years_array * self.adaptation_collection.climate_factor
_discount = (1 + self.adaptation_collection.discount_rate) ** _years_array

_damage_per_year = event_impact * _frequency_per_year / _discount
return np.sum(_damage_per_year)

_net_impact_array = np.array([calc_net_impact_time_horizon(damage) for damage in _impact_array])
_impact_gdf[f"net_present_impact_{_option.id}"] = _net_impact_array

return _impact_gdf

def run_benefit(self) -> GeoDataFrame:
"""
Calculate the benefit for all adaptation options
Expand Down
25 changes: 25 additions & 0 deletions tests/analysis/adaptation/test_adaptation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,28 @@ def test_run_cost(
for _option in _adaptation.adaptation_collection.adaptation_options
]
)

def test_run_net_present_impact(
self,
valid_adaptation_input: AnalysisInputWrapper,
valid_adaptation_config: AnalysisConfigData,
):
# 1. Define test data.
_adaptation = Adaptation(valid_adaptation_input, valid_adaptation_config)
_adaptation.adaptation_collection.initial_frequency = 0.01
_adaptation.adaptation_collection.climate_factor = 0.00036842
_adaptation.adaptation_collection.discount_rate = 0.025
_adaptation.adaptation_collection.time_horizon = 20

# 2. Run test.
_impact_gdf = _adaptation.run_net_present_impact()

# 3. Verify expectations.
assert isinstance(_impact_gdf, GeoDataFrame)
assert all(
[
f"net_present_impact_{_option.id}" in _impact_gdf.columns
for _option in _adaptation.adaptation_collection.adaptation_options
]
)