climada.entity.measures package#

climada.entity.measures.base module#

class climada.entity.measures.base.Measure(name: str = '', haz_type: str = '', cost: float = 0, hazard_set: str = 'nil', hazard_freq_cutoff: float = 0, exposures_set: str = 'nil', imp_fun_map: str = 'nil', hazard_inten_imp: Tuple[float, float] = (1, 0), mdd_impact: Tuple[float, float] = (1, 0), paa_impact: Tuple[float, float] = (1, 0), exp_region_id: list | None = None, risk_transf_attach: float = 0, risk_transf_cover: float = 0, risk_transf_cost_factor: float = 1, color_rgb: ndarray | None = None)[source]#

Bases: object

Contains the definition of one measure.

name#

name of the measure

Type:

str

haz_type#

related hazard type (peril), e.g. TC

Type:

str

color_rgb#

integer array of size 3. Color code of this measure in RGB

Type:

np.array

cost#

discounted cost (in same units as assets)

Type:

float

hazard_set#

file name of hazard to use (in h5 format)

Type:

str

hazard_freq_cutoff#

hazard frequency cutoff

Type:

float

exposures_set#

file name of exposure to use (in h5 format) or Exposure instance

Type:

str or climada.entity.Exposure

imp_fun_map#

change of impact function id of exposures, e.g. ‘1to3’

Type:

str

hazard_inten_imp#

parameter a and b of hazard intensity change

Type:

tuple(float, float)

mdd_impact#

parameter a and b of the impact over the mean damage degree

Type:

tuple(float, float)

paa_impact#

parameter a and b of the impact over the percentage of affected assets

Type:

tuple(float, float)

exp_region_id#

region id of the selected exposures to consider ALL the previous parameters

Type:

int

risk_transf_attach#

risk transfer attachment

Type:

float

risk_transf_cover#

risk transfer cover

Type:

float

risk_transf_cost_factor#

factor to multiply to resulting insurance layer to get the total cost of risk transfer

Type:

float

__init__(name: str = '', haz_type: str = '', cost: float = 0, hazard_set: str = 'nil', hazard_freq_cutoff: float = 0, exposures_set: str = 'nil', imp_fun_map: str = 'nil', hazard_inten_imp: Tuple[float, float] = (1, 0), mdd_impact: Tuple[float, float] = (1, 0), paa_impact: Tuple[float, float] = (1, 0), exp_region_id: list | None = None, risk_transf_attach: float = 0, risk_transf_cover: float = 0, risk_transf_cost_factor: float = 1, color_rgb: ndarray | None = None)[source]#

Initialize a Measure object with given values.

Parameters:
  • name (str, optional) – name of the measure

  • haz_type (str, optional) – related hazard type (peril), e.g. TC

  • cost (float, optional) – discounted cost (in same units as assets)

  • hazard_set (str, optional) – file name of hazard to use (in h5 format)

  • hazard_freq_cutoff (float, optional) – hazard frequency cutoff

  • exposures_set (str or climada.entity.Exposure, optional) – file name of exposure to use (in h5 format) or Exposure instance

  • imp_fun_map (str, optional) – change of impact function id of exposures, e.g. ‘1to3’

  • hazard_inten_imp (tuple(float, float), optional) – parameter a and b of hazard intensity change

  • mdd_impact (tuple(float, float), optional) – parameter a and b of the impact over the mean damage degree

  • paa_impact (tuple(float, float), optional) – parameter a and b of the impact over the percentage of affected assets

  • exp_region_id (int, optional) – region id of the selected exposures to consider ALL the previous parameters

  • risk_transf_attach (float, optional) – risk transfer attachment

  • risk_transf_cover (float, optional) – risk transfer cover

  • risk_transf_cost_factor (float, optional) – factor to multiply to resulting insurance layer to get the total cost of risk transfer

  • color_rgb (np.array, optional) – integer array of size 3. Color code of this measure in RGB. Default is None (corresponds to black).

check()[source]#

Check consistent instance data.

Raises:

ValueError

calc_impact(exposures, imp_fun_set, hazard, assign_centroids=True)[source]#

Apply measure and compute impact and risk transfer of measure implemented over inputs.

Parameters:
  • exposures (climada.entity.Exposures) – exposures instance

  • imp_fun_set (climada.entity.ImpactFuncSet) – impact function set instance

  • hazard (climada.hazard.Hazard) – hazard instance

  • assign_centroids (bool, optional) – indicates whether centroids are assigned to the self.exposures object. Centroids assignment is an expensive operation; set this to False to save computation time if the hazards’ centroids are already assigned to the exposures object. Default: True

Returns:

resulting impact and risk transfer of measure

Return type:

climada.engine.Impact

apply(exposures, imp_fun_set, hazard)[source]#

Implement measure with all its defined parameters.

Parameters:
  • exposures (climada.entity.Exposures) – exposures instance

  • imp_fun_set (climada.entity.ImpactFuncSet) – impact function set instance

  • hazard (climada.hazard.Hazard) – hazard instance

Returns:

  • new_exp (climada.entity.Exposure) – Exposure with implemented measure with all defined parameters

  • new_ifs (climada.entity.ImpactFuncSet) – Impact function set with implemented measure with all defined parameters

  • new_haz (climada.hazard.Hazard) – Hazard with implemented measure with all defined parameters

climada.entity.measures.measure_set module#

class climada.entity.measures.measure_set.MeasureSet(measure_list: List[Measure] | None = None)[source]#

Bases: object

Contains measures of type Measure. Loads from files with format defined in FILE_EXT.

_data#

Contains Measure objects. This attribute is not suppossed to be accessed directly. Use the available methods instead.

Type:

dict

__init__(measure_list: List[Measure] | None = None)[source]#

Initialize a new MeasureSet object with specified data.

Parameters:

measure_list (list of Measure objects, optional) – The measures to include in the MeasureSet

Examples

Fill MeasureSet with values and check consistency data:

>>> act_1 = Measure(
...     name='Seawall',
...     color_rgb=np.array([0.1529, 0.2510, 0.5451]),
...     hazard_intensity=(1, 0),
...     mdd_impact=(1, 0),
...     paa_impact=(1, 0),
... )
>>> meas = MeasureSet([act_1])
>>> meas.check()

Read measures from file and checks consistency data:

>>> meas = MeasureSet.from_excel(ENT_TEMPLATE_XLS)
clear(_data: dict | None = None)[source]#

Reinitialize attributes.

Parameters:

_data (dict, optional) – A dict containing the Measure objects. For internal use only: It’s not suppossed to be set directly. Use the class methods instead.

append(meas)[source]#

Append an Measure. Override if same name and haz_type.

Parameters:

meas (Measure) – Measure instance

Raises:

ValueError

remove_measure(haz_type=None, name=None)[source]#

Remove impact function(s) with provided hazard type and/or id. If no input provided, all impact functions are removed.

Parameters:
  • haz_type (str, optional) – all impact functions with this hazard

  • name (str, optional) – measure name

get_measure(haz_type=None, name=None)[source]#

Get ImpactFunc(s) of input hazard type and/or id. If no input provided, all impact functions are returned.

Parameters:
  • haz_type (str, optional) – hazard type

  • name (str, optional) – measure name

Returns:

  • Measure (if haz_type and name),

  • list(Measure) (if haz_type or name),

  • {Measure.haz_type ({Measure.name : Measure}} (if None))

get_hazard_types(meas=None)[source]#

Get measures hazard types contained for the name provided. Return all hazard types if no input name.

Parameters:

name (str, optional) – measure name

Return type:

list(str)

get_names(haz_type=None)[source]#

Get measures names contained for the hazard type provided. Return all names for each hazard type if no input hazard type.

Parameters:

haz_type (str, optional) – hazard type from which to obtain the names

Returns:

  • list(Measure.name) (if haz_type provided),

  • {Measure.haz_type (list(Measure.name)} (if no haz_type))

size(haz_type=None, name=None)[source]#

Get number of measures contained with input hazard type and /or id. If no input provided, get total number of impact functions.

Parameters:
  • haz_type (str, optional) – hazard type

  • name (str, optional) – measure name

Return type:

int

check()[source]#

Check instance attributes.

Raises:

ValueError

extend(meas_set)[source]#

Extend measures of input MeasureSet to current MeasureSet. Overwrite Measure if same name and haz_type.

Parameters:

impact_funcs (MeasureSet) – ImpactFuncSet instance to extend

Raises:

ValueError

classmethod from_mat(file_name, var_names=None)[source]#

Read MATLAB file generated with previous MATLAB CLIMADA version.

Parameters:
  • file_name (str) – absolute file name

  • description (str, optional) – description of the data

  • var_names (dict, optional) – name of the variables in the file

Returns:

meas_set – Measure Set from matlab file

Return type:

climada.entity.MeasureSet()

read_mat(*args, **kwargs)[source]#

This function is deprecated, use MeasureSet.from_mat instead.

classmethod from_excel(file_name, var_names=None)[source]#

Read excel file following template and store variables.

Parameters:
  • file_name (str) – absolute file name

  • description (str, optional) – description of the data

  • var_names (dict, optional) – name of the variables in the file

Returns:

meas_set – Measures set from Excel

Return type:

climada.entity.MeasureSet

read_excel(*args, **kwargs)[source]#

This function is deprecated, use MeasureSet.from_excel instead.

write_excel(file_name, var_names=None)[source]#

Write excel file following template.

Parameters:
  • file_name (str) – absolute file name to write

  • var_names (dict, optional) – name of the variables in the file