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:
RiskTrajectoryThis 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.static_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:
RiskTrajectoryThis 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
AllLinearStrategyimpact_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'), **kwargs) DataFrame[source]#
Return a tidy dataframe of the risk metrics with the total for each different period (pair of snapshots).
- 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.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:
ABCBase abstract class for risk trajectory objects.
See concrete implementation
StaticRiskTrajectoryandInterpolatedRiskTrajectoryfor 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