Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
0901b4d
Merge branch 'forecast-class' into impact-forecast-class
peanutfun Dec 8, 2025
b7b6545
Add ImpactForecast
peanutfun Dec 8, 2025
3b077a0
Add fixture for impact kwargs
peanutfun Dec 8, 2025
44bf09a
Use kwarg assignment in ImpactForecast.__init__
peanutfun Dec 8, 2025
347fcf1
Add test for ImpactForecast.select
peanutfun Dec 8, 2025
01c138e
Merge branch 'forecast-class' into impact-forecast-select
peanutfun Dec 8, 2025
fe5d705
Merge branch 'forecast-class' into impact-forecast-select
peanutfun Dec 8, 2025
7da50f1
Return impactForecast object in _return_impact
luseverin Dec 8, 2025
4d36a0d
Fix merge issue
peanutfun Dec 8, 2025
bd3502f
Return impactForecast object in _return_empty
luseverin Dec 8, 2025
78878b7
minor test modification
Evelyn-M Dec 8, 2025
dfa0198
Add full impactcalc test for impactForecast
luseverin Dec 8, 2025
59c0e5b
Correct mistakes in _return_empty and _return_impact
luseverin Dec 8, 2025
4b5ae95
Raise value error when computing impact with impact forecast without …
luseverin Dec 8, 2025
9a516e1
Cosmetics: Improve error message, move test to own class
Dec 8, 2025
d571bb7
Merge branch 'forecast-class' into impactCalc_block_nonsense_attrs
luseverin Dec 9, 2025
6fe29f0
Merge branch 'impactCalc_return_impactForecast' into impactCalc_block…
luseverin Dec 9, 2025
899d8f0
add test to check that eai_exp and aai_agg are nan for forecasts
luseverin Dec 9, 2025
db32170
Write nans for eai_exp and aai_agg when forecast is used
luseverin Dec 9, 2025
d2f035f
update tests using pytest
luseverin Dec 9, 2025
c10a4b3
Fix error in test fixtures
luseverin Dec 9, 2025
d3a5642
Returns nans for eai_exp and aai_agg when exposures is empty
luseverin Dec 9, 2025
d43a46c
add warning when at_event is used with forecast
luseverin Dec 9, 2025
e197566
Update ImpactCalc tests for forecasts
peanutfun Dec 9, 2025
0a324b2
Merge branch 'impactCalc_return_impactForecast' of https://github.com…
peanutfun Dec 9, 2025
554cfc8
Review ImpactCalc forecast handling
peanutfun Dec 9, 2025
30ed14d
Block local_exceedance_impact
luseverin Dec 9, 2025
f3ab44a
Fix bug in test
peanutfun Dec 9, 2025
612a53c
Merge branch 'impactCalc_return_impactForecast' of https://github.com…
peanutfun Dec 9, 2025
9e4f2bb
Block return_period and exceedance_freq_curve
luseverin Dec 9, 2025
727357e
Log warning for at_event getter
luseverin Dec 9, 2025
f79f4a1
fix formatting
Evelyn-M Dec 9, 2025
d01aef4
fc-specific date and event_name attrs
Evelyn-M Dec 9, 2025
0bc5846
Add mean max min methods to impact forecast and tests
luseverin Dec 9, 2025
a55ab3b
Merge branch 'forecast-class' into implement_mean_min_max
luseverin Dec 9, 2025
0aad2a5
Reduce lead time and member and update test
luseverin Dec 10, 2025
102f9be
Update docstrings
luseverin Dec 10, 2025
dfce16f
Remove useless comments
luseverin Dec 10, 2025
0b6e1e4
Add min max mean for hazard forecast
luseverin Dec 10, 2025
3fc25af
Correct some mistakes in mean min max on hazard forecast
luseverin Dec 10, 2025
a4fe3b0
Add tests for hazard forecast mean min max
luseverin Dec 10, 2025
e099868
Set reduced date to 0 and cosmetic changes
luseverin Dec 10, 2025
23660de
Set reduced date to 0 in impact forecast
luseverin Dec 10, 2025
3d7e37a
tests for xarray hazard fc reader
Evelyn-M Dec 10, 2025
053ffc8
merge changes
Evelyn-M Dec 10, 2025
64149df
Simplify code and tests
peanutfun Dec 10, 2025
85b92ef
Make Impact.concat support ImpactForecast
peanutfun Dec 10, 2025
5d0f062
fix failing forecast tests
Evelyn-M Dec 10, 2025
c9041fe
remove unused kwargs
Evelyn-M Dec 10, 2025
2e028e3
Merge branch 'forecast-class' into implement_mean_min_max
peanutfun Dec 10, 2025
b289efb
first draft of tutorial
ValentinGebhart Dec 10, 2025
464e592
add crs and private method tests
Evelyn-M Dec 10, 2025
c6c5882
Merge branch 'forecast-io' into add_forecast_tutorial
ValentinGebhart Dec 10, 2025
b00509f
fix merge conflicts
Evelyn-M Dec 10, 2025
2c35791
Add reduce_unique_selection in forecast base class
luseverin Dec 10, 2025
b2a691d
add crs attr to test file
Evelyn-M Dec 10, 2025
c91a2cb
Add dim to mean min max in hazard forecast
luseverin Dec 10, 2025
64574ec
Draft test mean min max with dim hazard forecat
luseverin Dec 10, 2025
bc2e6bd
Merge branch 'forecast-class' into implement_unique_selection_reduction
luseverin Dec 10, 2025
ff49d98
add impact calc
ValentinGebhart Dec 10, 2025
643edfa
Merge branch 'forecast-class' into forecast-io
peanutfun Dec 10, 2025
7204e90
Merge branch 'forecast-io' of https://github.com/CLIMADA-project/clim…
Evelyn-M Dec 10, 2025
96ccc58
Simplify data parsing and tests
peanutfun Dec 10, 2025
84b344b
Merge branch 'forecast-class' into forecast-io
peanutfun Dec 10, 2025
b5e7d7a
Restore test_impact_forecast.py
peanutfun Dec 10, 2025
1076719
Correct wrong use of self.dim in mean min max
luseverin Dec 10, 2025
c4f06a6
continue OGD showcase
Evelyn-M Dec 10, 2025
bc6f576
Parametrize hazard fixtures with different members and lead times and…
luseverin Dec 10, 2025
001f340
Merge branch 'forecast-class' into implement_unique_selection_reduction
luseverin Dec 10, 2025
6e25208
update tutorial
ValentinGebhart Dec 11, 2025
d84db1e
Merge branch 'forecast-class' of github.com:CLIMADA-project/climada_p…
ValentinGebhart Dec 11, 2025
ec2948b
Merge branch 'forecast-class' into add_forecast_tutorial
ValentinGebhart Dec 11, 2025
3781391
finalize tutorial (some statistics method to be checked)
ValentinGebhart Dec 11, 2025
4741fd0
update tutorial
ValentinGebhart Dec 11, 2025
9685a81
Skip tests for incompatible xarray versions
peanutfun Dec 15, 2025
db69a0f
merge from io
Evelyn-M Dec 16, 2025
e01c7d2
API data and cleaning of tutorial
Evelyn-M Dec 16, 2025
0dc8644
TOC for notebook
Evelyn-M Dec 16, 2025
5b46f63
Adjust reduction logic with respect to members
peanutfun Dec 17, 2025
4f5e4e5
Merge branch 'implement_unique_selection_reduction' into add_forecast…
peanutfun Dec 17, 2025
bb72db3
Fix dimension reduction for HazardForecast
peanutfun Dec 22, 2025
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
46 changes: 34 additions & 12 deletions climada/engine/impact_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from ..util import log_level
from ..util.checker import size
from ..util.forecast import Forecast
from ..util.forecast import Forecast, reduce_unique_selection
from .impact import Impact

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -244,7 +244,7 @@ def _check_sizes(self):
size(exp_len=num_entries, var=self.member, var_name="Forecast.member")
size(exp_len=num_entries, var=self.lead_time, var_name="Forecast.lead_time")

def _reduce_attrs(self, event_name: str):
def _reduce_attrs(self, event_name: str, **attrs):
"""
Reduce the attributes of an ImpactForecast to a single value.

Expand All @@ -261,18 +261,25 @@ def _reduce_attrs(self, event_name: str):
event_name : str
The event name given to the reduced data.
"""

def unique_or_default(attr, default):
if len(unique := np.unique(getattr(self, attr))) == 1:
return unique.item(0)
return default

reduced_attrs = {
"lead_time": np.array([np.timedelta64("NaT")]),
"member": np.array([-1]),
"event_id": np.array([0]),
"event_name": np.array([event_name]),
"date": np.array([0]),
"frequency": np.array([1]),
}
"lead_time": unique_or_default("lead_time", np.timedelta64("NaT")),
"member": unique_or_default("member", -1),
"event_id": unique_or_default("event_id", 1),
"event_name": unique_or_default("event_name", event_name),
"date": unique_or_default("date", 0),
"frequency": 1,
} | attrs
reduced_attrs = {key: np.array([value]) for key, value in reduced_attrs.items()}

return reduced_attrs

def min(self):
def min(self, dim=None):
"""
Reduce the impact matrix and at_event of an ImpactForecast to the minimum
value.
Expand All @@ -286,6 +293,11 @@ def min(self):
ImpactForecast
An ImpactForecast object with the min impact matrix and at_event.
"""
if dim is not None:
return reduce_unique_selection(
self, values=getattr(self, dim), select=dim, reduce_attr="min"
)

red_imp_mat = self.imp_mat.min(axis=0).tocsr()
red_at_event = np.array([red_imp_mat.sum()])
return ImpactForecast(
Expand All @@ -302,7 +314,7 @@ def min(self):
**self._reduce_attrs("min"),
)

def max(self):
def max(self, dim=None):
"""
Reduce the impact matrix and at_event of an ImpactForecast to the maximum
value.
Expand All @@ -316,6 +328,11 @@ def max(self):
ImpactForecast
An ImpactForecast object with the max impact matrix and at_event.
"""
if dim is not None:
return reduce_unique_selection(
self, values=getattr(self, dim), select=dim, reduce_attr="max"
)

red_imp_mat = self.imp_mat.max(axis=0).tocsr()
red_at_event = np.array([red_imp_mat.sum()])
return ImpactForecast(
Expand All @@ -332,7 +349,7 @@ def max(self):
**self._reduce_attrs("max"),
)

def mean(self):
def mean(self, dim=None):
"""
Reduce the impact matrix and at_event of an ImpactForecast to the mean value.

Expand All @@ -345,6 +362,11 @@ def mean(self):
ImpactForecast
An ImpactForecast object with the mean impact matrix and at_event.
"""
if dim is not None:
return reduce_unique_selection(
self, values=getattr(self, dim), select=dim, reduce_attr="mean"
)

red_imp_mat = sparse.csr_matrix(self.imp_mat.mean(axis=0))
red_at_event = np.array([red_imp_mat.sum()])
return ImpactForecast(
Expand Down
5 changes: 5 additions & 0 deletions climada/engine/test/test_impact_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
Tests for Impact Forecast.
"""

import datetime as dt
from pathlib import Path

import numpy as np
import numpy.testing as npt
import pandas as pd
import pytest
import xarray as xr
from scipy.sparse import csr_matrix

from climada.engine import Impact, ImpactForecast
Expand Down Expand Up @@ -58,6 +62,7 @@ def impact_forecast(impact, lead_time, member):


class TestImpactForecastInit:

def assert_impact_kwargs(self, impact: Impact, **kwargs):
for key, value in kwargs.items():
attr = getattr(impact, key)
Expand Down
Loading
Loading