Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
3692813
Implements equality methods for impf and impfset
spjuhel Mar 18, 2025
1606896
adds a few tests
spjuhel Mar 18, 2025
a8b45c6
Merge remote-tracking branch 'origin/develop' into feature/eq_methods…
spjuhel Mar 18, 2025
3776228
updates changelog
spjuhel Mar 18, 2025
f6d9feb
Improves dict comparison
spjuhel Mar 24, 2025
222644d
Applies suggestion from Lukas (1)
spjuhel Mar 24, 2025
29ecee4
init commit
spjuhel Apr 2, 2025
d7c0f23
Pushes tutorial notebook
spjuhel Apr 2, 2025
31ef976
Working tutorial
spjuhel Apr 2, 2025
10ca243
fixes a typo from mass edit
spjuhel Apr 2, 2025
389787e
Refactor to a more object-oriented design
spjuhel Apr 15, 2025
4ea685d
fixes some bugs
spjuhel Apr 15, 2025
0d6335b
fixses some linter issues
spjuhel Apr 16, 2025
31ea96d
feat(trajectory): interpolation and impactcalc files, eai_gdf metric
spjuhel Apr 17, 2025
3f13c2e
impact func __eq__
spjuhel Apr 24, 2025
519c9af
feat(test): adds test for ImpactFuncSet
spjuhel Apr 24, 2025
adfc7e2
fix(format): removes trailing whitespace
spjuhel Apr 24, 2025
6856117
Merge branch 'feature/eq_methods_for_impf' into feature/risk_trajectory
spjuhel Apr 24, 2025
9c358ca
fix: npv arg not considered in .all_risk_metrics()
spjuhel Apr 24, 2025
b7bf68b
refactor: enforce kwargs in RiskTrajectory init
spjuhel Apr 24, 2025
b75ab91
refactor: adds consistency between attribute
spjuhel Apr 24, 2025
e12b2c4
refactor(risktraj): lays better foundations for MeasureAppraiser
spjuhel Apr 25, 2025
8666197
minor additions, refactors and fixes
spjuhel May 7, 2025
9711379
format,doc: cleans up code, adds docstrings
spjuhel May 14, 2025
9aec92f
test: adds lots of unittests, and placeholders
spjuhel May 14, 2025
7387165
feature(Traj): fixes metrics generic and removes storing values
spjuhel May 19, 2025
20befdf
updates tutorial
spjuhel May 19, 2025
e06a3e7
doc(risk_traj): adds some docstrings
spjuhel May 21, 2025
924bb35
doc(module desc): improves top file desc
spjuhel May 21, 2025
6595e13
fix(log) : Removes endless logs
spjuhel May 21, 2025
94bd00e
fix(risk_traj): Fixes problems with >2 snapshots
spjuhel May 21, 2025
4921528
doc(notebook): adds disclaimers
spjuhel May 21, 2025
02244cb
fix(CalcRiskPeriod): fixes problem with undefined group_id
spjuhel May 22, 2025
b0a9f6d
fix(calcriskperiod): further fix for no group defined
spjuhel May 22, 2025
06afe2f
fix(groups): still fixing groups
spjuhel May 22, 2025
eceeba0
fix(groups): final fix (on the correct branch)
spjuhel May 22, 2025
a7dd0f7
Applies suggestion from Lucas (j/n)
spjuhel May 26, 2025
7989c71
Applies suggestion from Lucas (j/n)
spjuhel May 26, 2025
399572e
Applies suggestion from Lucas (j/n)
spjuhel May 26, 2025
3db32ca
Applies suggestion from Lucas (j/n)
spjuhel May 26, 2025
d2b0f6b
refactor(impact strat): Clarifies/Simplified computation
spjuhel Jun 5, 2025
3f0dfc6
feat(interpolation): Vastly improves interpolation of metrics
spjuhel Jun 5, 2025
d24a5b8
test(naming): updates names
spjuhel Jun 5, 2025
304a641
Squashed commit of the following:
spjuhel Jun 5, 2025
4ef643f
fix(plot, groups): improves plot, fixes group in eai
spjuhel Jun 23, 2025
bc38525
Merge remote-tracking branch 'origin/develop' into feature/risk_traje…
spjuhel Jun 23, 2025
33cfff4
fix(RiskPCalc): sorts the snapshots
spjuhel Jun 24, 2025
dd21493
doc(risk transfer): Improves clarity of risk transfer mechanism
spjuhel Jun 24, 2025
f4db1d0
format(docstring)
spjuhel Jun 24, 2025
c6e147e
test: fix for coverage
spjuhel Jul 1, 2025
25d0d0a
fix,doc(interpolation): minor improvements and fixes
spjuhel Jul 1, 2025
9634bd9
fix: minor fixes from testing
spjuhel Jul 1, 2025
d4af1a7
test: Updates test (98pct coverage o7)
spjuhel Jul 1, 2025
7e8df85
fix(group id): fix categories problem
spjuhel Jul 1, 2025
1bae9ad
still fixing groups
spjuhel Jul 1, 2025
b946f9b
group fixing
spjuhel Jul 1, 2025
622c8f6
fix(tests): fix tests with groups_id attr
spjuhel Jul 2, 2025
9c94c9f
tests: cleaning up
spjuhel Sep 9, 2025
953a5cf
updates notebook
spjuhel Sep 10, 2025
59bb831
more logical placement
spjuhel Sep 10, 2025
0a3a301
removes risk transfer mechanism (for now)
spjuhel Sep 10, 2025
b5f0bfc
doc(docstrings): Massive docstrings update + some renaming
spjuhel Sep 11, 2025
1fbe437
test: updates with new names and removing of risk transfer
spjuhel Sep 11, 2025
56966ca
Polishes names, plots, fixes minor bugs, fixes multiple snapshots
spjuhel Sep 12, 2025
a11a630
Updates tutorial
spjuhel Sep 12, 2025
6c8dd15
fix(RP impacts for periods): fixes aggregation (sum -> mean)
spjuhel Sep 16, 2025
3609471
drops unwanted col
spjuhel Sep 16, 2025
6eaf095
less confusing naming
spjuhel Sep 16, 2025
5ab8bda
improves structure
spjuhel Sep 16, 2025
21cc433
Improves for CB
spjuhel Sep 16, 2025
0a04ab9
Use of PeriodIndex instead of DateTimeIndex
spjuhel Sep 22, 2025
2bf7768
Big refactoring to include "static" (non-interpolated) trajectories
spjuhel Sep 23, 2025
e2fd678
Refactoring continued (Also now includes the new files)
spjuhel Sep 24, 2025
252e68e
fixes attachement/cover comment
spjuhel Sep 24, 2025
d694c64
Refactoring continued
spjuhel Sep 24, 2025
eadcb97
typing consistency
spjuhel Sep 24, 2025
fa17a48
fix apply_measure
spjuhel Sep 24, 2025
b4316d7
fixes Snapshot doc, makes measure and date immutable properties
spjuhel Sep 25, 2025
3a026cd
risk_disc -> risk_disc_rates, fixes return period mechanism
spjuhel Sep 25, 2025
3f0c5f9
Improves docstrings, typehint
spjuhel Sep 25, 2025
26bb85d
adds list comprehensions, fixes typo
spjuhel Sep 25, 2025
6e12608
improves docstring for calc strategies
spjuhel Sep 25, 2025
67641e0
first part of fix for cash_flows
spjuhel Sep 25, 2025
a68b79a
fixes cash_flow problem
spjuhel Sep 25, 2025
cbaca3c
force keyword args to avoid errors
spjuhel Sep 25, 2025
56f3715
fixes risk_contribution problem with multiple snapshot
spjuhel Sep 25, 2025
0234238
fix aggressive caching
spjuhel Sep 29, 2025
195a50f
fix missing group in exposure
spjuhel Sep 29, 2025
f14c9c1
Merge remote-tracking branch 'origin/develop' into feature/risk_traje…
spjuhel Oct 1, 2025
fe50ac1
adds risk metric unit based on exposure `value_unit`
spjuhel Oct 1, 2025
22570ef
Fixes npv values not cached correctly
spjuhel Oct 24, 2025
b681161
fixes risk contributions
spjuhel Oct 24, 2025
2512fbf
Proxies in __init__, cleaning
spjuhel Oct 24, 2025
24ea75e
tuto update
spjuhel Oct 24, 2025
da1f7ed
updates tests, and fixes problems found
spjuhel Oct 27, 2025
966df6a
Cleanup and tests
spjuhel Nov 3, 2025
6d27f38
Removes superfluous growth rate in expo interp
spjuhel Nov 3, 2025
1c84a34
Updates user guide
spjuhel Nov 3, 2025
de4b8cd
Removes start-end dates in plot (not working as intended)
spjuhel Nov 3, 2025
542e045
better imports, fixes a few tests
spjuhel Nov 3, 2025
3896812
user guide update
spjuhel Nov 3, 2025
a178970
Proper imports in test
spjuhel Nov 3, 2025
802eefc
Fix Callable signature type hint incompatible with 3.10
spjuhel Nov 3, 2025
e48c924
adds guide for using climada with spack on euler
spjuhel Nov 3, 2025
aedc811
Revert "adds guide for using climada with spack on euler" (wrong branch)
spjuhel Nov 3, 2025
7f3f8de
Massively updates the docstrings. Also cleans up some clutter.
spjuhel Nov 3, 2025
02eaa8d
updates notebooks, fixes a test
spjuhel Nov 3, 2025
81fefbc
fixes a test
spjuhel Nov 4, 2025
c2a9ccf
updates tests main
spjuhel Nov 4, 2025
1005965
Merge remote-tracking branch 'origin/develop' into feature/risk_traje…
spjuhel Dec 10, 2025
c8495ea
Removes global risk transfer for now
spjuhel Dec 11, 2025
d5f901f
Adds integration tests and polish:
spjuhel Dec 16, 2025
24d1e4e
Fixes unwanted inclusion of "rp" column
spjuhel Dec 16, 2025
0ea3445
Improves integration tests
spjuhel Dec 16, 2025
c9b1ad3
Merge remote-tracking branch 'origin/develop' into feature/risk_traje…
spjuhel Dec 16, 2025
f4d92c3
Better computation and interpretation of risk contributions
spjuhel Dec 16, 2025
2a8899c
Fixes corresponding test
spjuhel Dec 16, 2025
57f981b
Updates integration tests, factorizes interpolations
spjuhel Dec 17, 2025
4a4b08c
Uses ImpactFreqCurve for RPs instead of legacy code
spjuhel Dec 18, 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
643 changes: 643 additions & 0 deletions climada/test/test_trajectories.py

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions climada/trajectories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
This file is part of CLIMADA.

Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS.

CLIMADA is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free
Software Foundation, version 3.

CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with CLIMADA. If not, see <https://www.gnu.org/licenses/>.

---

This module implements risk trajectory objects which enable computation and
possibly interpolation of risk metric over multiple dates.

"""

from .interpolated_trajectory import InterpolatedRiskTrajectory
from .interpolation import AllLinearStrategy, ExponentialExposureStrategy
from .snapshot import Snapshot
from .static_trajectory import StaticRiskTrajectory

__all__ = [
"InterpolatedRiskTrajectory",
"AllLinearStrategy",
"ExponentialExposureStrategy",
"Snapshot",
"StaticRiskTrajectory",
]
55 changes: 55 additions & 0 deletions climada/trajectories/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
This file is part of CLIMADA.

Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS.

CLIMADA is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free
Software Foundation, version 3.

CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with CLIMADA. If not, see <https://www.gnu.org/licenses/>.

---

Define constants for trajectories module.
"""

DEFAULT_TIME_RESOLUTION = "Y"
DATE_COL_NAME = "date"
PERIOD_COL_NAME = "period"
GROUP_COL_NAME = "group"
GROUP_ID_COL_NAME = "group_id"
MEASURE_COL_NAME = "measure"
NO_MEASURE_VALUE = "no_measure"
METRIC_COL_NAME = "metric"
UNIT_COL_NAME = "unit"
RISK_COL_NAME = "risk"
COORD_ID_COL_NAME = "coord_id"

DEFAULT_PERIOD_INDEX_NAME = "date"

DEFAULT_RP = [20, 50, 100]
"""Default return periods to use when computing return period impact estimates."""

DEFAULT_ALLGROUP_NAME = "All"
"""Default string to use to define the exposure subgroup containing all exposure points."""

EAI_METRIC_NAME = "eai"
AAI_METRIC_NAME = "aai"
AAI_PER_GROUP_METRIC_NAME = "aai_per_group"
CONTRIBUTIONS_METRIC_NAME = "risk_contributions"
RETURN_PERIOD_METRIC_NAME = "return_periods"
RP_VALUE_PREFIX = "rp"


CONTRIBUTION_BASE_RISK_NAME = "base risk"
CONTRIBUTION_TOTAL_RISK_NAME = "total risk"
CONTRIBUTION_EXPOSURE_NAME = "exposure contribution"
CONTRIBUTION_HAZARD_NAME = "hazard contribution"
CONTRIBUTION_VULNERABILITY_NAME = "vulnerability contribution"
CONTRIBUTION_INTERACTION_TERM_NAME = "interaction contribution"
137 changes: 137 additions & 0 deletions climada/trajectories/impact_calc_strat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"""
This file is part of CLIMADA.

Copyright (C) 2017 ETH Zurich, CLIMADA contributors listed in AUTHORS.

CLIMADA is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free
Software Foundation, version 3.

CLIMADA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with CLIMADA. If not, see <https://www.gnu.org/licenses/>.

---

This modules implements the impact computation strategy objects for risk
trajectories.

"""

from abc import ABC, abstractmethod

from climada.engine.impact import Impact
from climada.engine.impact_calc import ImpactCalc
from climada.entity.exposures.base import Exposures
from climada.entity.impact_funcs.impact_func_set import ImpactFuncSet
from climada.hazard.base import Hazard

__all__ = ["ImpactCalcComputation"]


class ImpactComputationStrategy(ABC):
"""
Interface for impact computation strategies.

This abstract class defines the contract for all concrete strategies
responsible for calculating and optionally modifying with a risk transfer,
the impact computation, based on a set of inputs (exposure, hazard, vulnerability).

It revolves around a `compute_impacts()` method that takes as arguments
the three dimensions of risk (exposure, hazard, vulnerability) and return an
Impact object.
"""

@abstractmethod
def compute_impacts(
self,
exp: Exposures,
haz: Hazard,
vul: ImpactFuncSet,
) -> Impact:
"""
Calculates the total impact, including optional risk transfer application.

Parameters
----------
exp : Exposures
The exposure data.
haz : Hazard
The hazard data (e.g., event intensity).
vul : ImpactFuncSet
The set of vulnerability functions.

Returns
-------
Impact
An object containing the computed total impact matrix and metrics.

See Also
--------
ImpactCalcComputation : The default implementation of this interface.
"""
...


class ImpactCalcComputation(ImpactComputationStrategy):
r"""
Default impact computation strategy using the core engine of climada.

This strategy first calculates the raw impact using the standard
:class:`ImpactCalc` logic.

"""

def compute_impacts(
self,
exp: Exposures,
haz: Hazard,
vul: ImpactFuncSet,
) -> Impact:
"""
Calculates the impact and applies the "global" risk transfer mechanism.

Parameters
----------
exp : Exposures
The exposure data.
haz : Hazard
The hazard data.
vul : ImpactFuncSet
The set of vulnerability functions.

Returns
-------
Impact
The final impact object.
"""
impact = self.compute_impacts_pre_transfer(exp, haz, vul)
return impact

def compute_impacts_pre_transfer(
self,
exp: Exposures,
haz: Hazard,
vul: ImpactFuncSet,
) -> Impact:
"""
Calculates the raw impact matrix before any risk transfer is applied.

Parameters
----------
exp : Exposures
The exposure data.
haz : Hazard
The hazard data.
vul : ImpactFuncSet
The set of vulnerability functions.

Returns
-------
Impact
An Impact object containing the raw, pre-transfer impact matrix.
"""
return ImpactCalc(exposures=exp, impfset=vul, hazard=haz).impact()
Loading
Loading