climada.entity.measures package#
Note
This package implements the new way of defining measures. For the previous way, see climada.entity._legacy_measures
climada.entity.measures.measure_config module#
- class climada.entity.measures.measure_config.HazardModifierConfig(haz_type: str, haz_int_mult: float | None = 1.0, haz_int_add: float | None = 0.0, haz_freq_mult: float | None = 1.0, haz_freq_add: float | None = 0.0, new_hazard_path: str | None = None, impact_rp_cutoff: float | None = None)[source]#
Bases:
ModifierConfigConfiguration for modifications to a hazard.
Supports scaling or shifting hazard intensity, applying a return-period frequency cutoff, and replacement of the hazard, loaded from a file path. If both a new file path and modifier values are provided, modifiers are applied after the replacement.
- Parameters:
haz_type (str) – Hazard type identifier (e.g.
"TC") that this modifier targets.haz_int_mult (float, optional) – Multiplicative factor applied to hazard intensity. Default is
1.0(no change).haz_int_add (float, optional) – Additive offset applied to hazard intensity after multiplication. Default is
0.0.new_hazard_path (str, optional) – Path to an HDF5 file containing a replacement hazard. If provided alongside modifier values, a warning is issued and modifiers are applied after loading the new hazard.
impact_rp_cutoff (float, optional) – Return period (in years) below which hazard events are discarded. If
None, no cutoff is applied.
- Warns:
UserWarning – If
new_hazard_pathis set alongside any non-default modifier values or a non-Noneimpact_rp_cutoff.
- haz_type: str#
- haz_int_mult: float | None = 1.0#
- haz_int_add: float | None = 0.0#
- haz_freq_mult: float | None = 1.0#
- haz_freq_add: float | None = 0.0#
- new_hazard_path: str | None = None#
- impact_rp_cutoff: float | None = None#
- __init__(haz_type: str, haz_int_mult: float | None = 1.0, haz_int_add: float | None = 0.0, haz_freq_mult: float | None = 1.0, haz_freq_add: float | None = 0.0, new_hazard_path: str | None = None, impact_rp_cutoff: float | None = None) None#
- class climada.entity.measures.measure_config.ExposuresModifierConfig(reassign_impf_id: Dict[str, Dict[int | str, int | str]] | None = None, set_to_zero: list[int] | None = None, new_exposures_path: str | None = None)[source]#
Bases:
ModifierConfigConfiguration for modifications to an exposures object.
Supports remapping impact function IDs, zeroing out selected regions, and replacement of the exposures from a new file. If both a new file path and modifier values are provided, modifiers are applied after the replacement.
- Parameters:
reassign_impf_id (dict of {str: dict of {int or str: int or str}}, optional) – Nested mapping
{haz_type: {old_id: new_id}}used to reassign impact function IDs in the exposures. IfNone, no remapping is performed.set_to_zero (list of int, optional) – Region IDs for which exposure values are set to zero. If
None, no zeroing is applied.new_exposures_path (str, optional) – Path to an HDF5 file containing replacement exposures. If provided alongside modifier values, a warning is issued and modifiers are applied after loading the new exposures.
- Warns:
UserWarning – If
new_exposures_pathis set alongside any non-Nonemodifier values.
- reassign_impf_id: Dict[str, Dict[int | str, int | str]] | None = None#
- set_to_zero: list[int] | None = None#
- new_exposures_path: str | None = None#
- __init__(reassign_impf_id: Dict[str, Dict[int | str, int | str]] | None = None, set_to_zero: list[int] | None = None, new_exposures_path: str | None = None) None#
- class climada.entity.measures.measure_config.ImpfsetModifierConfig(haz_type: str, impf_ids: int | str | list[int | str] | None = None, impf_mdd_mult: float = 1.0, impf_mdd_add: float = 0.0, impf_paa_mult: float = 1.0, impf_paa_add: float = 0.0, impf_int_mult: float = 1.0, impf_int_add: float = 0.0, new_impfset_path: str | None = None)[source]#
Bases:
ModifierConfigConfiguration for modifications to an impact function set.
Supports scaling or shifting MDD, PAA, and intensity curves, as well as replacement of the impact function set, loaded from a file path. If both a new file path and modifier values are provided, modifiers are applied after the replacement (and a warning is issued).
- Parameters:
haz_type (str) – Hazard type identifier (e.g.
"TC") that this modifier targets.impf_ids (int or str or list of int or str, optional) – Impact function ID(s) to which modifications are applied. If
None, all impact functions are affected.impf_mdd_mult (float, optional) – Multiplicative factor applied to the mean damage degree (MDD) curve. Default is
1.0(no change).impf_mdd_add (float, optional) – Additive offset applied to the MDD curve after multiplication. Default is
0.0.impf_paa_mult (float, optional) – Multiplicative factor applied to the percentage of affected assets (PAA) curve. Default is
1.0.impf_paa_add (float, optional) – Additive offset applied to the PAA curve after multiplication. Default is
0.0.impf_int_mult (float, optional) – Multiplicative factor applied to the intensity axis. Default is
1.0.impf_int_add (float, optional) – Additive offset applied to the intensity axis after multiplication. Default is
0.0.new_impfset_path (str, optional) – Path to an Excel file containing a replacement impact function set. If provided alongside modifier values, a warning is issued and modifiers are applied after loading the new set.
- Warns:
UserWarning – If
new_impfset_pathis set alongside any non-default modifier values.
- haz_type: str#
- impf_ids: int | str | list[int | str] | None = None#
- impf_mdd_mult: float = 1.0#
- impf_mdd_add: float = 0.0#
- impf_paa_mult: float = 1.0#
- impf_paa_add: float = 0.0#
- impf_int_mult: float = 1.0#
- impf_int_add: float = 0.0#
- new_impfset_path: str | None = None#
- __init__(haz_type: str, impf_ids: int | str | list[int | str] | None = None, impf_mdd_mult: float = 1.0, impf_mdd_add: float = 0.0, impf_paa_mult: float = 1.0, impf_paa_add: float = 0.0, impf_int_mult: float = 1.0, impf_int_add: float = 0.0, new_impfset_path: str | None = None) None#
- class climada.entity.measures.measure_config.CostIncomeConfig(mkt_price_year: int | None = <factory>, init_cost: float = 0.0, periodic_cost: float = 0.0, periodic_income: float = 0.0, cost_yearly_growth_rate: float = 0.0, income_yearly_growth_rate: float = 0.0, freq: str = 'Y', custom_cash_flows: list[dict] | None = None)[source]#
Bases:
ModifierConfigSerializable configuration for a
CostIncomeobject.Encodes all parameters required to construct a
CostIncomeinstance, including optional custom cash flow schedules.- Parameters:
mkt_price_year (int, optional) – Reference year for market prices. Defaults to the current year.
init_cost (float, optional) – One-time initial investment cost (positive value). Default is
0.0.periodic_cost (float, optional) – Recurring cost per period (positive value). Default is
0.0.periodic_income (float, optional) – Recurring income per period. Default is
0.0.cost_yearly_growth_rate (float, optional) – Annual growth rate applied to periodic costs. Default is
0.0.income_yearly_growth_rate (float, optional) – Annual growth rate applied to periodic income. Default is
0.0.freq (str, optional) – Pandas period alias defining the period length (e.g.
"Y"for yearly,"M"for monthly). Default is"Y". See [pandas documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#period-aliases).custom_cash_flows (list of dict, optional) – Explicit cash flow schedule as a list of records with at minimum a
"date"key (ISO 8601 string) and a value key. If provided, overrides the periodic cost/income logic.
- mkt_price_year: int | None#
- init_cost: float = 0.0#
- periodic_cost: float = 0.0#
- periodic_income: float = 0.0#
- cost_yearly_growth_rate: float = 0.0#
- income_yearly_growth_rate: float = 0.0#
- freq: str = 'Y'#
- custom_cash_flows: list[dict] | None = None#
- classmethod from_cost_income(cost_income: CostIncome) CostIncomeConfig[source]#
Construct a
CostIncomeConfigfrom a liveCostIncomeobject.- Parameters:
cost_income (CostIncome) – The live
CostIncomeinstance to serialise.- Returns:
The config instance equivalent to the
CostIncome.- Return type:
- __init__(mkt_price_year: int | None = <factory>, init_cost: float = 0.0, periodic_cost: float = 0.0, periodic_income: float = 0.0, cost_yearly_growth_rate: float = 0.0, income_yearly_growth_rate: float = 0.0, freq: str = 'Y', custom_cash_flows: list[dict] | None = None) None#
- class climada.entity.measures.measure_config.MeasureConfig(name: str, haz_type: str, impfset_modifier: ImpfsetModifierConfig, hazard_modifier: HazardModifierConfig, exposures_modifier: ExposuresModifierConfig, cost_income: CostIncomeConfig, implementation_duration: str | None = None, color_rgb: Tuple[float, float, float] | None = None)[source]#
Bases:
ModifierConfigTop-level serializable configuration for a single adaptation measure.
Aggregates all modifier sub-configs (hazard, impact functions, exposures, cost/income) into a single object that can be round-tripped through dict, YAML, or a legacy Excel row.
This class is the primary entry point for defining measures in a declarative, file-based workflow and serves as the serialization counterpart to
Measure.- Parameters:
name (str) – Unique name identifying this measure.
haz_type (str) – Hazard type identifier (e.g.
"TC") this measure is designed for.impfset_modifier (ImpfsetModifierConfig) – Configuration describing modifications to the impact function set.
hazard_modifier (HazardModifierConfig) – Configuration describing modifications to the hazard.
exposures_modifier (ExposuresModifierConfig) – Configuration describing modifications to the exposures.
cost_income (CostIncomeConfig) – Financial parameters associated with implementing this measure.
implementation_duration (str, optional) – Pandas period alias (e.g.
"2Y") representing the time before the measure is fully operational. IfNone, the measure takes effect immediately.color_rgb (tuple of float, optional) – RGB colour triple in the range
[0, 1]used for visualisation. IfNone, defaults to black(0, 0, 0).
- name: str#
- haz_type: str#
- impfset_modifier: ImpfsetModifierConfig#
- hazard_modifier: HazardModifierConfig#
- exposures_modifier: ExposuresModifierConfig#
- cost_income: CostIncomeConfig#
- implementation_duration: str | None = None#
- color_rgb: Tuple[float, float, float] | None = None#
- to_dict(omit_default: bool = True) dict[source]#
Serialize the measure configuration to a flat dictionary.
Sub-config dictionaries are merged into the top-level dict (i.e. their keys are inlined, not nested).
haz_typeis always included at the top level. Fields withNonevalues are preserved.- Returns:
Flat dictionary representation suitable for YAML or Excel serialization.
- Return type:
dict
- classmethod from_dict(kwargs_dict: dict) MeasureConfig[source]#
Instantiate a
MeasureConfigfrom a flat dictionary.Delegates sub-config construction to the respective
from_dictclassmethods. Unknown keys are silently discarded by each sub-config parser.- Parameters:
kwargs_dict (dict) – Flat dictionary, as produced by
to_dict()or read from a legacy Excel row. Must contain at minimum"name"and"haz_type".- Returns:
A fully populated configuration instance.
- Return type:
- to_yaml(path: str) None[source]#
Write this configuration to a YAML file.
The file is structured as
{"measures": [<this config as dict>]}, matching the expected format forfrom_yaml().- Parameters:
path (str) – Destination file path. Will be created or overwritten.
- classmethod from_yaml(path: str) MeasureConfig[source]#
Load a
MeasureConfigfrom a YAML file.Expects the file to contain a top-level
"measures"list; reads only the first entry.- Parameters:
path (str) – Path to the YAML file to read.
- Returns:
The configuration parsed from the first entry in
measures.- Return type:
- classmethod from_row(row: Series) MeasureConfig[source]#
Construct a
MeasureConfigfrom a legacy Excel row.Converts the row to a dictionary and delegates to
from_dict(). This is the primary migration path for measures currently stored in the legacy Excel-basedMeasureSetformat.- Parameters:
row (pd.Series) – A single row from a legacy measures Excel sheet, with column names matching the flat dictionary keys expected by
from_dict().- Returns:
A configuration instance populated from the row data.
- Return type:
- __init__(name: str, haz_type: str, impfset_modifier: ImpfsetModifierConfig, hazard_modifier: HazardModifierConfig, exposures_modifier: ExposuresModifierConfig, cost_income: CostIncomeConfig, implementation_duration: str | None = None, color_rgb: Tuple[float, float, float] | None = None) None#