climada.trajectories package#

climada.trajectories.calc_risk_metrics module#

class climada.trajectories.calc_risk_metrics.CalcRiskMetricsPoints(snapshots: list[Snapshot], impact_computation_strategy: ImpactComputationStrategy)[source]#

Bases: object

This class handles the computation of impacts for a list of Snapshot.

Note that most attribute like members are properties with their own docstring.

impact_computation_strategy#

The method used to calculate the impact from the (Haz,Exp,Vul) of the snapshots. Defaults to ImpactCalc

Type:

ImpactComputationStrategy, optional

measure#

The measure applied to snapshots. Defaults to None.

Type:

Measure, optional

Notes

This class is intended for internal computation.

__init__(snapshots: list[Snapshot], impact_computation_strategy: ImpactComputationStrategy) → None[source]#

Initialize a new CalcRiskMetricsPoints

This initializes and instantiate a new CalcRiskMetricsPoints object. No computation is done at initialisation and only done “just in time”.

Parameters:
  • snapshots (List[Snapshot]) – The Snapshot list to compute risk for.

  • impact_computation_strategy (ImpactComputationStrategy, optional) – The method used to calculate the impact from the (Haz,Exp,Vul) of the two snapshots. Defaults to ImpactCalc

property impact_computation_strategy: ImpactComputationStrategy#

The method used to calculate the impact from the (Haz,Exp,Vul) of the snapshots.

property impacts#
property per_date_eai#
property per_date_aai#
calc_eai_gdf() → DataFrame[source]#

Convenience function returning a DataFrame from per_date_eai.

This can easily be merged with the GeoDataFrame of the exposure object of one of the Snapshot.

Notes

The DataFrame from the first snapshot of the list is used as a basis (notably for value and group_id).

calc_aai_metric() → DataFrame[source]#

Compute a DataFrame of the AAI for each snapshot.

calc_aai_per_group_metric() → DataFrame | None[source]#

Compute a DataFrame of the AAI distinguised per group id in the exposures, for each snapshot.

calc_return_periods_metric(return_periods: list[int]) → DataFrame[source]#

Compute a DataFrame of the estimated impacts for a list of return periods, for each snapshot.

Parameters:

return_periods (list of int) – The return periods to estimate impacts for.

apply_measure(measure: Measure) → CalcRiskMetricsPoints[source]#

Creates a new CalcRiskMetricsPoints object by applying the effects of the given measure.

The effects of the measure are applied to all the snapshots contained in the initial CalcRiskMetricsPoints and a new CalcRiskMetricsPoints containing the modified snapshots is returned.

Parameters:

measure (Measure) – The measure to apply.

Returns:

The risk period with given measure applied.

Return type:

CalcRiskMetricsPoints

class climada.trajectories.calc_risk_metrics.CalcRiskMetricsPeriod(snapshot_start: Snapshot, snapshot_end: Snapshot, *, time_resolution: str, interpolation_strategy: ImpactInterpolationStrategy, impact_computation_strategy: ImpactComputationStrategy)[source]#

Bases: object

This class handles the computation of impacts for a risk period.

This object handles the interpolations and computations of risk metrics in between two given snapshots, along a DateTimeIndex build from either a time_resolution (which must be a valid “freq” string to build a DateTimeIndex) and defaults to “Y” (start of the year) or time_points integer argument, in which case the DateTimeIndex will have that many periods.

Note that most attribute like members are properties with their own docstring.

date_idx#

The date index for the different interpolated points between the two snapshots

Type:

pd.PeriodIndex

interpolation_strategy#

The approach used to interpolate impact matrices in between the two snapshots, linear by default.

Type:

InterpolationStrategy, optional

impact_computation_strategy#

The method used to calculate the impact from the (Haz,Exp,Vul) of the two snapshots. Defaults to ImpactCalc

Type:

ImpactComputationStrategy, optional

measure#

The measure to apply to both snapshots. Defaults to None.

Type:

Measure, optional

Notes

This class is intended for internal computation.

__init__(snapshot_start: Snapshot, snapshot_end: Snapshot, *, time_resolution: str, interpolation_strategy: ImpactInterpolationStrategy, impact_computation_strategy: ImpactComputationStrategy)[source]#

Initialize a new CalcRiskMetricsPeriod

This initializes and instantiate a new CalcRiskMetricsPeriod object. No computation is done at initialisation and only done “just in time”.

Parameters:
  • snapshot_start (Snapshot) – The Snapshot at the start of the risk period.

  • snapshot_end (Snapshot) – The Snapshot at the end of the risk period.

  • time_resolution (str, optional) – One of pandas date offset strings or corresponding objects. See pandas.period_range().

  • time_points (int, optional) – Number of periods to generate for the PeriodIndex.

  • interpolation_strategy (InterpolationStrategy, optional) – The approach used to interpolate impact matrices in between the two snapshots, linear by default.

  • impact_computation_strategy (ImpactComputationStrategy, optional) – The method used to calculate the impact from the (Haz,Exp,Vul) of the two snapshots. Defaults to ImpactCalc

property snapshot_start: Snapshot#

The Snapshot at the start of the risk period.

property snapshot_end: Snapshot#

The Snapshot at the end of the risk period.

property date_idx: PeriodIndex#

The pandas PeriodIndex representing the time dimension of the risk period.

property time_points: int#

The numbers of different time points (periods) in the risk period.

property time_resolution: str#

The time resolution of the risk periods, expressed as a pandas period frequency string.

property interpolation_strategy: ImpactInterpolationStrategy#

The approach used to interpolate impact matrices in between the two snapshots.

property impact_computation_strategy: ImpactComputationStrategy#

The method used to calculate the impact from the (Haz,Exp,Vul) of the two snapshots.

apply_measure(measure: Measure) → CalcRiskMetricsPeriod[source]#

Creates a new CalcRiskMetricsPeriod object with a measure.

The given measure is applied to both snapshot of the risk period.

Parameters:

measure (Measure) – The measure to apply.

Returns:

The risk period with given measure applied.

Return type:

CalcRiskPeriod

property E0H0V0#
property E1H0V0#
property E0H1V0#
property E1H1V0#
property E0H0V1#
property E1H0V1#
property E0H1V1#
property E1H1V1#
property per_date_eai#
property per_date_aai#
calc_eai_gdf() → DataFrame[source]#

Convenience function returning a DataFrame from per_date_eai.

This dataframe can easily be merged with one of the snapshot exposure geodataframe.

Notes

The DataFrame from the starting snapshot is used as a basis (notably for value and group_id).

calc_aai_metric() → DataFrame[source]#

Compute a DataFrame of the AAI at each dates of the risk period (including changes in exposure, hazard and vulnerability).

calc_aai_per_group_metric() → DataFrame | None[source]#

Compute a DataFrame of the AAI distinguised per group id in the exposures, at each dates of the risk period (including changes in exposure, hazard and vulnerability).

Notes

If group ids changes between starting and ending snapshots of the risk period, the AAIs are linearly interpolated (with a warning for transparency).

calc_return_periods_metric(return_periods: list[int]) → DataFrame[source]#

Compute a DataFrame of the estimated impacts for a list of return periods, at each dates of the risk period (including changes in exposure, hazard and vulnerability).

Parameters:

return_periods (list of int) – The return periods to estimate impacts for.

Notes

Computing return period impacts normally requires ordering events by their impact magnitude. This method instead interpolates impacts at the specified return period directly, which is an approximation.

This may be improved in the future by building concatenated hazard and impacts matrix corresponding to all possible cases.

calc_risk_contributions_metric() → DataFrame[source]#

Compute a DataFrame of the individual contributions of risk (impact), at each dates of the risk period (including changes in exposure, hazard and vulnerability).

climada.trajectories.calc_risk_metrics.calc_per_date_aais(per_date_eai_exp: ndarray) → ndarray[source]#

Calculate per_date aggregate annual impact (AAI) values resulting from a list arrays corresponding to EAI at different dates (with possible changes along exposure, hazard and vulnerability).

Parameters:

per_date_eai_exp (np.ndarray) – EAIs arrays.

Returns:

1D array of AAI (0D) for each dates.

Return type:

np.ndarray

climada.trajectories.calc_risk_metrics.calc_per_date_eais(imp_mats: list[csr_matrix], frequency: ndarray) → ndarray[source]#

Calculate expected average impact (EAI) values from a list of impact matrices corresponding to impacts at different dates (with possible changes along exposure, hazard and vulnerability).

Parameters:
  • imp_mats (list of np.ndarray) – List of impact matrices.

  • frequency (np.ndarray) – Hazard frequency values.

Returns:

2D array of EAI (1D) for each dates.

Return type:

np.ndarray

climada.trajectories.calc_risk_metrics.calc_per_date_rps(imp_mats: list[csr_matrix], frequency: ndarray, frequency_unit: str, return_periods: list[int]) → ndarray[source]#

Calculate per date return period impact values from a list of impact matrices corresponding to impacts at different dates (with possible changes along exposure, hazard and vulnerability).

Parameters:
  • imp_mats (list of scipy.crs_matrix) – List of impact matrices.

  • frequency (np.ndarray) – Frequency values.

  • return_periods (list of int) – Return periods to calculate impact values for.

Returns:

2D array of impacts per return periods (1D) for each dates.

Return type:

np.ndarray

climada.trajectories.calc_risk_metrics.calc_freq_curve(imp_mat_intrpl, frequency, frequency_unit, return_per=None) → ImpactFreqCurve[source]#

Calculate the estimated impacts for given return periods.

Parameters:
  • imp_mat_intrpl (scipy.csr_matrix) – An impact matrix.

  • frequency (np.ndarray) – The frequency of the hazard.

  • return_per (np.ndarray) – The return periods to compute impacts for.

Returns:

The estimated impacts for the different return periods.

Return type:

np.ndarray

climada.trajectories.constants module#

climada.trajectories.constants.DEFAULT_RP = (20, 50, 100)#

Default return periods to use when computing return period impact estimates.

climada.trajectories.constants.DEFAULT_ALLGROUP_NAME = 'All'#

Default string to use to define the exposure subgroup containing all exposure points.

climada.trajectories.impact_calc_strat module#

class climada.trajectories.impact_calc_strat.ImpactCalcComputation[source]#

Bases: ImpactComputationStrategy

Default impact computation strategy using the core engine of climada.

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

compute_impacts(exp: Exposures, haz: Hazard, vul: ImpactFuncSet) → Impact[source]#

Calculates the impact.

Parameters:
  • exp (Exposures) – The exposure data.

  • haz (Hazard) – The hazard data.

  • vul (ImpactFuncSet) – The set of vulnerability functions.

Returns:

The final impact object.

Return type:

Impact

climada.trajectories.interpolated_trajectory module#

class climada.trajectories.interpolated_trajectory.InterpolatedRiskTrajectory(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), time_resolution: str = 'Y', risk_disc_rates: DiscRates | None = None, interpolation_strategy: ImpactInterpolationStrategy | None = None, impact_computation_strategy: ImpactComputationStrategy | None = None)[source]#

Bases: RiskTrajectory

This class implements interpolated risk trajectories, objects that regroup impacts computations for multiple dates, and interpolate risk metrics in between.

This class computes risk metrics over a series of snapshots, optionally applying risk discounting. It interpolate risk between each pair of snapshots and provides dataframes of risk metric on a given time resolution.

POSSIBLE_METRICS = ['eai', 'aai', 'return_periods', 'risk_contributions', 'aai_per_group']#

Class variable listing the risk metrics that can be computed.

Currently:

  • eai, expected impact (per exposure point within a period of 1/frequency unit of the hazard object)

  • aai, average annual impact (aggregated eai over the whole exposure)

  • aai_per_group, average annual impact per exposure subgroup (defined from the exposure geodataframe)

  • return_periods, estimated impacts aggregated over the whole exposure for different return periods

  • risk_contributions, estimated contribution part of, respectively exposure, hazard, vulnerability and their interaction to the change in risk over the considered period

__init__(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), time_resolution: str = 'Y', risk_disc_rates: DiscRates | None = None, interpolation_strategy: ImpactInterpolationStrategy | None = None, impact_computation_strategy: ImpactComputationStrategy | None = None)[source]#

Initialize a new InterpolatedRiskTrajectory.

Parameters:
  • snapshot_list (list[Snapshot]) – The list of Snapshot object to compute risk from.

  • return_periods (list[int], optional) – The return periods to use when computing the return_periods_metric. Defaults to DEFAULT_RP ([20, 50, 100]).

  • time_resolution (str, optional) – The time resolution to use for interpolation. It must be a valid pandas string used to define periods, e.g., “Y” for years, “M” for months, “3M” for trimester, etc. Defaults to DEFAULT_TIME_RESOLUTION (“Y”).

  • risk_disc_rates (DiscRates, optional) – The discount rate to apply to future risk. Defaults to None.

  • interpolation_strategy (ImpactInterpolationStrategy, optional) – The interpolation strategy to use when interpolating. Defaults to AllLinearStrategy

  • impact_computation_strategy (ImpactComputationStrategy, optional) – The method used to calculate the impact from the (Haz,Exp,Vul) of the two snapshots. Defaults to ImpactCalcComputation.

property interpolation_strategy: ImpactInterpolationStrategy#

The approach used to interpolate impact matrices in between the two snapshots.

property impact_computation_strategy: ImpactComputationStrategy#

The method used to calculate the impact from the (Haz,Exp,Vul) triplets.

property time_resolution: str#

The time resolution to use when interpolating.

It must be a valid pandas string used to define periods, e.g., “Y” for years, “M” for months, “3M” for trimester, etc.

See here

Notes

Changing its value resets the corresponding metric.

eai_metrics(**kwargs) → DataFrame[source]#

Return the estimated annual impacts at each exposure point for each date.

This method computes and return a DataFrame with eai metric (for each exposure point) for each date.

Notes

This computation may become quite expensive for big areas with high resolution.

aai_metrics(**kwargs) → DataFrame[source]#

Return the average annual impacts for each date.

This method computes and return a DataFrame with aai metric for each date.

return_periods_metrics(**kwargs) → DataFrame[source]#

Return the estimated impacts for different return periods.

Return periods to estimate impacts for are defined by self.return_periods.

aai_per_group_metrics(**kwargs) → DataFrame[source]#

Return the average annual impacts for each exposure group ID.

This method computes and return a DataFrame with aai metric for each of the exposure group defined by a group id, for each date.

risk_contributions_metrics(**kwargs) → DataFrame[source]#

Return the “contributions” of change in future risk (Exposure and Hazard)

This method returns the contributions of the change in risk at each date:

  • The ‘base risk’, i.e., the risk without change in hazard or exposure, compared to trajectory’s earliest date.

  • The ‘exposure contribution’, i.e., the additional risks due to change in exposure (only)

  • The ‘hazard contribution’, i.e., the additional risks due to change in hazard (only)

  • The ‘vulnerability contribution’, i.e., the additional risks due to change in vulnerability (only)

  • The ‘interaction contribution’, i.e., the additional risks due to the interaction term

per_date_risk_metrics(metrics: Iterable[str] | None = None) → DataFrame[source]#

Returns a DataFrame of risk metrics for each dates

This methods collects (and if needed computes) the metrics (Defaulting to AAI_METRIC_NAME, RETURN_PERIOD_METRIC_NAME and AAI_PER_GROUP_METRIC_NAME).

Parameters:
  • metrics (list[str], optional) – The list of metrics to return (defaults to [AAI_METRIC_NAME,RETURN_PERIOD_METRIC_NAME,AAI_PER_GROUP_METRIC_NAME])

  • return_periods (list[int], optional) – The return periods to consider for the return periods metric (default to the value of the .default_rp attribute)

Returns:

A tidy DataFrame with metrics value for all possible dates.

Return type:

pd.DataFrame | pd.Series

per_period_risk_metrics(metrics: Iterable[str] = ('aai', 'return_periods', 'aai_per_group'), colname: str | list[str] = 'risk', aggfunc: str | Callable = 'mean') → DataFrame[source]#

Return a tidy dataframe of risk metrics aggregated over periods.

By default, aggregate by computing the “mean” of the metric over the period.

Parameters:
  • metrics (iterable of str, optional)

  • freq (str, optional) – Pandas frequency string for aggregation bins (e.g. "2Y"). If None, bins correspond to intervals between consecutive snapshots.

  • colname (str or list of str, optional)

  • aggfunc (str or callable, optional) – Aggregation function. Default is "mean".

Notes

If freq is given, periods are left inclusing, right excluding, meaning for instance, “2018-01-01 to 2024-01-01” is the average risk from 2018-01-01 included to 2023-12-31 included.

If the last date is at odd with the frequency given, the aggfunc is still applied over the “whole” bin inclunding the date, for instance if the last date is 2025-01-01, and bins are 3Y starting at 2022-01-01, 2025-01-01 falls in the 2025-01-01 to 2028-01-01, meaning it will be averaged over 3 years but with two years without data.

plot_time_waterfall(ax=None, figsize=(12, 6))[source]#

Plot a waterfall chart of risk contributions over a specified date range.

This method generates a stacked bar chart to visualize the risk contributions.

Parameters:

ax (matplotlib.axes.Axes, optional) – The matplotlib axes on which to plot. If None, a new figure and axes are created.

Returns:

The matplotlib axes with the plotted waterfall chart.

Return type:

matplotlib.axes.Axes

plot_waterfall(ax=None)[source]#

Plot a waterfall chart of risk contributions between two dates.

This method generates a waterfall plot to visualize the changes in risk contributions.

Parameters:

ax (matplotlib.axes.Axes, optional) – The matplotlib axes on which to plot. If None, a new figure and axes are created.

Returns:

The matplotlib axes with the plotted waterfall chart.

Return type:

matplotlib.axes.Axes

climada.trajectories.interpolation module#

class climada.trajectories.interpolation.AllLinearStrategy[source]#

Bases: ImpactInterpolationStrategy

Linear interpolation strategy over all dimensions.

__init__() → None[source]#
class climada.trajectories.interpolation.ExponentialExposureStrategy[source]#

Bases: ImpactInterpolationStrategy

Exponential interpolation strategy for exposure and linear for Hazard and Vulnerability.

__init__() → None[source]#
climada.trajectories.interpolation.linear_convex_combination(arr_start: ndarray, arr_end: ndarray) → ndarray[source]#

Performs a linear convex combination between two n x m NumPy arrays over their first dimension (n rows).

This function interpolates each metric (column) linearly across the time steps (rows), including both the start and end states.

Parameters:
  • arr_start (numpy.ndarray) – The starting array of metrics. The first dimension (rows) is assumed to represent the interpolation steps (e.g., dates/time points).

  • arr_end (numpy.ndarray) – The ending array of metrics. Must have the exact same shape as arr_start.

Returns:

An array with the same shape as arr_start and arr_end. The values in the first dimension transition linearly from those in arr_start to those in arr_end.

Return type:

numpy.ndarray

Raises:

ValueError – If arr_start and arr_end do not have the same shape.

Example

>>> arr_start = [ [ 1, 1], [1, 2], [10, 20] ]
>>> arr_end = [ [2, 2], [5, 6], [10, 30] ]
>>> linear_interp_arrays(arr_start, arr_end)
>>> [[1, 1], [3, 4], [10, 30]]

Notes

The interpolation is performed element-wise along the first dimension (axis 0). For each row $i$ and proportion $p_i$, the result $R_i$ is calculated as:

$$R_i = arr_start_i cdot (1 - p_i) + arr_end_i cdot p_i$$

where $p_i$ is generated by $text{np.linspace}(0, 1, n)$ and $n$ is the size of the first dimension ($text{arr_start.shape}[0]$).

climada.trajectories.interpolation.linear_interp_matrix_elemwise(mat_start: csr_matrix, mat_end: csr_matrix, number_of_interpolation_points: int) → List[csr_matrix][source]#

Linearly interpolates between two sparse impact matrices.

Creates a sequence of matrices representing a linear transition from a starting matrix to an ending matrix. The interpolation includes both the start and end points.

Parameters:
  • mat_start (scipy.sparse.csr_matrix) – The starting impact matrix. Must have a shape compatible with mat_end for arithmetic operations.

  • mat_end (scipy.sparse.csr_matrix) – The ending impact matrix. Must have a shape compatible with mat_start for arithmetic operations.

  • number_of_interpolation_points (int) – The total number of matrices to return, including the start and end points. Must be $ge 2$.

Returns:

A list of matrices, where the first element is mat_start and the last element is mat_end. The total length of the list is number_of_interpolation_points.

Return type:

list of scipy.sparse.csr_matrix

Notes

The formula used for interpolation at proportion $p$ is: $$M_p = M_{start} cdot (1 - p) + M_{end} cdot p$$ The proportions $p$ range from 0 to 1, inclusive.

climada.trajectories.interpolation.exponential_convex_combination(arr_start: ndarray, arr_end: ndarray) → ndarray[source]#

Performs exponential convex combination between two NumPy arrays over their first dimension.

This function achieves an exponential-like transition by performing linear interpolation in the logarithmic space.

Parameters:
  • arr_start (numpy.ndarray) – The starting array of metrics. Values must be positive.

  • arr_end (numpy.ndarray) – The ending array of metrics. Must have the exact same shape as arr_start.

Returns:

An array with the same shape as arr_start and arr_end. The values in the first dimension transition exponentially from those in arr_start to those in arr_end.

Return type:

numpy.ndarray

Raises:

ValueError – If arr_start and arr_end do not have the same shape.

See also

linear_interp_arrays

linear version of the interpolation.

Notes

The interpolation is performed by transforming the arrays to a logarithmic domain, linearly interpolating, and then transforming back.

The formula for the interpolated result $R$ at proportion $text{prop}$ is: $$ R = exp left(

ln(A_{start}) cdot (1 - text{prop}) + ln(A_{end}) cdot text{prop}

right) $$ where $A_{start}$ and $A_{end}$ are the input arrays (with $epsilon$ added to prevent $ln(0)$) and $text{prop}$ ranges from 0 to 1.

climada.trajectories.interpolation.exponential_interp_matrix_elemwise(mat_start: csr_matrix, mat_end: csr_matrix, number_of_interpolation_points: int) → List[csr_matrix][source]#

Exponentially interpolates between two “impact matrices”.

This function performs interpolation in a logarithmic space, effectively achieving an exponential-like transition between mat_start and mat_end. It is designed for objects that wrap NumPy arrays and expose them via a .data attribute.

Parameters:
  • mat_start (object) – The starting matrix object. Must have a .data attribute that is a NumPy array of positive values.

  • mat_end (object) – The ending matrix object. Must have a .data attribute that is a NumPy array of positive values and have a compatible shape with mat_start.

  • number_of_interpolation_points (int) – The total number of matrix objects to return, including the start and end points. Must be $ge 2$.

Returns:

A list of interpolated matrix objects. The first element corresponds to mat_start and the last to mat_end (after the conversion/reversion). The list length is number_of_interpolation_points.

Return type:

list of object

Notes

The interpolation is achieved by:

  1. Mapping the matrix data to a transformed logarithmic space: $$M’_{i} = ln(M_{i})}$$ (where $ln$ is the natural logarithm, and $epsilon$ is added to $M_{i}$ to prevent $ln(0)$).

  2. Performing standard linear interpolation on the transformed matrices $M’_{start}$ and $M’_{end}$ to get $M’_{interp}$: $$M’_{interp} = M’_{start} cdot (1 - text{ratio}) + M’_{end} cdot text{ratio}$$

  3. Mapping the result back to the original domain: $$M_{interp} = exp(M’_{interp}$$

climada.trajectories.snapshot module#

class climada.trajectories.snapshot.Snapshot(*, exposure: Exposures, hazard: Hazard, impfset: ImpactFuncSet, date: date | str | Timestamp, measure: Measure | None = None, ref_only: bool = False)[source]#

Bases: object

A snapshot of exposure, hazard, and impact function at a specific date.

Parameters:
  • exposure (Exposures)

  • hazard (Hazard)

  • impfset (ImpactFuncSet)

  • date (datetime.date | str | pd.Timestamp) – The date of the Snapshot, it can be an string representing a year, a datetime object or a string representation of a datetime object.

  • measure (Measure | None, default None.) – Measure associated with the Snapshot. The measure object is not applied to the other parameters of the object (Exposure, Hazard, Impfset). To create a Snapshot with a measure use apply_measure() instead (see notes). The use of anything but None should be reserved for advanced users.

  • ref_only (bool, default False) – Should the Snapshot contain deep copies of the Exposures, Hazard and Impfset (False) or references only (True).

date#

Date of the snapshot.

Type:

datetime

measure#

A possible measure associated with the snapshot.

Type:

Measure | None

Notes

Providing a measure to the init assumes that the (Exposure, Hazard, Impfset) triplet already corresponds to the triplet once the measure is applied. Measure objects contain “the changes to apply”. Creating a consistent Snapshot with a measure should be done by first creating a Snapshot with the “baseline” (Exposure, Hazard, Impfset) triplet and calling <Snapshot>.apply_measure(<measure>), which returns a new Snapshot object with the measure applied.

Instantiating a Snapshot with a measure directly does not garantee the consistency between the triplet and the measure, and should be avoided.

If ref_only is True (default) the object creates deep copies of the exposure, hazard, and impact function set.

Also note that exposure, hazard and impfset are read-only properties. Consider snapshots as immutable objects.

__init__(*, exposure: Exposures, hazard: Hazard, impfset: ImpactFuncSet, date: date | str | Timestamp, measure: Measure | None = None, ref_only: bool = False) → None[source]#
property exposure: Exposures#

Exposure data for the snapshot.

property hazard: Hazard#

Hazard data for the snapshot.

property impfset: ImpactFuncSet#

Impact function set data for the snapshot.

property measure: Measure | None#

(Adaptation) Measure data for the snapshot.

property date: Timestamp#

Date of the snapshot.

property impact_calc_kwargs: dict#

Convenience function for ImpactCalc class.

apply_measure(measure: Measure) → Snapshot[source]#

Create a new snapshot by applying a Measure object.

This method creates a new Snapshot object by applying a measure on the current one.

Parameters:

measure (Measure) – The measure to be applied to the snapshot.

Return type:

The Snapshot with the measure applied.

climada.trajectories.static_trajectory module#

class climada.trajectories.static_trajectory.StaticRiskTrajectory(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), risk_disc_rates: DiscRates | None = None, impact_computation_strategy: ImpactComputationStrategy | None = None)[source]#

Bases: RiskTrajectory

This class implements static risk trajectories: objects that regroup impacts computations for multiple dates.

This class computes risk metrics over a series of Snapshot objects, optionally applying risk discounting, and offers access to the results in tidy formatted pandas DataFrames.

Contrary to InterpolatedRiskTrajectories, it does not interpolate risk between the snapshot and only provides results at each snapshot specific date.

POSSIBLE_METRICS = ['eai', 'aai', 'return_periods', 'aai_per_group']#

Class variable listing the risk metrics that can be computed.

Currently:

  • eai, expected impact (per exposure point within a period of 1/frequency

unit of the hazard object) - aai, average annual impact (aggregated eai over the whole exposure) - aai_per_group, average annual impact per exposure subgroup (defined from the exposure geodataframe) - return_periods, estimated impacts aggregated over the whole exposure for different return periods

__init__(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), risk_disc_rates: DiscRates | None = None, impact_computation_strategy: ImpactComputationStrategy | None = None)[source]#

Initialize a new StaticRiskTrajectory.

Parameters:
  • snapshots_list (list[Snapshot]) – The list of Snapshot object to compute risk from.

  • return_periods (list[int], optional) – The return periods to use when computing the return_periods_metric. Defaults to DEFAULT_RP ([20, 50, 100]).

  • risk_disc_rates (DiscRates, optional) – The discount rate to apply to future risk. Defaults to None.

  • impact_computation_strategy (ImpactComputationStrategy, optional) – The method used to calculate the impact from the (Haz,Exp,Vul) for each snapshot. Defaults to ImpactCalcComputation.

property impact_computation_strategy: ImpactComputationStrategy#

The approach or strategy used to calculate the impact from the snapshots.

eai_metrics(**kwargs) → DataFrame[source]#

Return the estimated annual impacts at each exposure point for each date.

This method computes and return a DataFrame with eai metric (for each exposure point) for each date.

Notes

This computation may become quite expensive for exposures with many points (e.g., big areas with high resolution).

aai_metrics(**kwargs) → DataFrame[source]#

Return the average annual impacts for each date.

This method computes and return a DataFrame with aai metric for each date.

return_periods_metrics(**kwargs) → DataFrame[source]#

Return the estimated impacts for different return periods.

Return periods to estimate impacts for are defined by self.return_periods.

aai_per_group_metrics(**kwargs) → DataFrame[source]#

Return the average annual impacts for each exposure group ID.

This method computes and return a DataFrame with aai metric for each of the exposure group defined by a group id, for each date.

per_date_risk_metrics(metrics: list[str] | None = None) → DataFrame | Series[source]#

Returns a DataFrame of risk metrics for each dates.

This methods collects (and if needed computes) the metrics (Defaulting to AAI_METRIC_NAME, RETURN_PERIOD_METRIC_NAME and AAI_PER_GROUP_METRIC_NAME).

Parameters:

metrics (list[str], optional) – The list of metrics to return (defaults to [AAI_METRIC_NAME,RETURN_PERIOD_METRIC_NAME,AAI_PER_GROUP_METRIC_NAME])

Returns:

A tidy DataFrame with metric values for all possible dates.

Return type:

pd.DataFrame | pd.Series

climada.trajectories.trajectory module#

class climada.trajectories.trajectory.RiskTrajectory(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), risk_disc_rates: DiscRates | None = None)[source]#

Bases: ABC

Base abstract class for risk trajectory objects.

See concrete implementation StaticRiskTrajectory and InterpolatedRiskTrajectory for more details.

POSSIBLE_METRICS = []#

Class variable listing the risk metrics that can be computed.

__init__(snapshots_list: Iterable[Snapshot], *, return_periods: Iterable[int] = (20, 50, 100), risk_disc_rates: DiscRates | None = None)[source]#
property return_periods: Iterable[int]#

The return period values to use when computing risk period metrics.

Notes

Changing its value resets the corresponding metric.

property risk_disc_rates: DiscRates | None#

The discount rate applied to compute net present values. None means no discount rate.

Notes

Changing its value resets all the metrics.

classmethod npv_transform(metric_df: DataFrame, risk_disc_rates: DiscRates) → DataFrame[source]#

Apply provided discount rate to the provided metric DataFrame.

Parameters:
  • metric_df (pd.DataFrame) – The DataFrame of the metric to discount.

  • risk_disc_rates (DiscRate) – The discount rate to apply.

Returns:

The discounted risk metric.

Return type:

pd.DataFrame