climada.engine package

climada.engine.impact module

class climada.engine.impact.Impact[source]

Bases: object

Impact definition. Compute from an entity (exposures and impact functions) and hazard.

tag

dictionary of tags of exposures, impact functions set and hazard: {‘exp’: Tag(), ‘if_set’: Tag(), ‘haz’: TagHazard()}

Type

dict

event_id

id (>0) of each hazard event

Type

np.array

event_name

name of each hazard event

Type

list

date

date of events

Type

np.array

coord_exp

exposures coordinates [lat, lon] (in degrees)

Type

np.ndarray

eai_exp

expected annual impact for each exposure

Type

np.array

at_event

impact for each hazard event

Type

np.array

frequency

annual frequency of event

Type

np.arrray

tot_value

total exposure value affected

Type

float

aai_agg

average annual impact (aggregated)

Type

float

unit

value unit used (given by exposures unit)

Type

str

imp_mat

matrix num_events x num_exp with impacts. only filled if save_mat is True in calc()

Type

sparse.csr_matrix

__init__()[source]

Empty initialization.

calc_freq_curve(return_per=None)[source]

Compute impact exceedance frequency curve.

Parameters

return_per (np.array, optional) – return periods where to compute the exceedance impact. Use impact’s frequencies if not provided

Returns

ImpactFreqCurve

calc(exposures, impact_funcs, hazard, save_mat=False)[source]

Compute impact of an hazard to exposures.

Parameters
  • exposures (Exposures) – exposures

  • impact_funcs (ImpactFuncSet) – impact functions

  • hazard (Hazard) – hazard

  • self_mat (bool) – self impact matrix: events x exposures

Examples

Use Entity class:

>>> haz = Hazard('TC') # Set hazard
>>> haz.read_mat(HAZ_DEMO_MAT)
>>> haz.check()
>>> ent = Entity() # Load entity with default values
>>> ent.read_excel(ENT_TEMPLATE_XLS) # Set exposures
>>> ent.check()
>>> imp = Impact()
>>> imp.calc(ent.exposures, ent.impact_funcs, haz)
>>> imp.calc_freq_curve().plot()

Specify only exposures and impact functions:

>>> haz = Hazard('TC') # Set hazard
>>> haz.read_mat(HAZ_DEMO_MAT)
>>> haz.check()
>>> funcs = ImpactFuncSet()
>>> funcs.read_excel(ENT_TEMPLATE_XLS) # Set impact functions
>>> funcs.check()
>>> exp = Exposures(pd.read_excel(ENT_TEMPLATE_XLS)) # Set exposures
>>> exp.check()
>>> imp = Impact()
>>> imp.calc(exp, funcs, haz)
>>> imp.aai_agg
plot_hexbin_eai_exposure(mask=None, ignore_zero=True, pop_name=True, buffer=0.0, extend='neither', **kwargs)[source]

Plot hexbin expected annual impact of each exposure.

Parameters
  • mask (np.array, optional) – mask to apply to eai_exp plotted.
    • ignore_zero (bool, optional) – flag to indicate if zero and negative values are ignored in plot. Default: False

    • pop_name (bool, optional) – add names of the populated places

    • buffer (float, optional) – border to add to coordinates. Default: 1.0.

    • extend (str, optional) – extend border colorbar with arrows. [ ‘neither’ | ‘both’ | ‘min’ | ‘max’ ]

    • kwargs (optional) – arguments for hexbin matplotlib function

Returns:

matplotlib.figure.Figure, cartopy.mpl.geoaxes.GeoAxesSubplot

plot_scatter_eai_exposure(mask=None, ignore_zero=True, pop_name=True, buffer=0.0, extend='neither', **kwargs)[source]

Plot scatter expected annual impact of each exposure.

Parameters
  • mask (np.array, optional) – mask to apply to eai_exp plotted.
    • ignore_zero (bool, optional) – flag to indicate if zero and negative values are ignored in plot. Default: False

    • pop_name (bool, optional) – add names of the populated places

    • buffer (float, optional) – border to add to coordinates. Default: 1.0.

    • extend (str, optional) – extend border colorbar with arrows. [ ‘neither’ | ‘both’ | ‘min’ | ‘max’ ]

    • kwargs (optional) – arguments for hexbin matplotlib function

Returns:

matplotlib.figure.Figure, cartopy.mpl.geoaxes.GeoAxesSubplot

plot_raster_eai_exposure(res=None, raster_res=None, save_tiff=None, raster_f=<function Impact.<lambda>>, label='value (log10)', **kwargs)[source]

Plot raster expected annual impact of each exposure.

Parameters
  • res (float, optional) – resolution of current data in units of latitude

    and longitude, approximated if not provided.

    • raster_res (float, optional) – desired resolution of the raster

    • save_tiff (str, optional) – file name to save the raster in tiff format, if provided

    • raster_f (lambda function) – transformation to use to data. Default: log10 adding 1.

    • label (str) – colorbar label

    • kwargs (optional) – arguments for imshow matplotlib function

Returns:

matplotlib.figure.Figure, cartopy.mpl.geoaxes.GeoAxesSubplot

plot_basemap_eai_exposure(mask=None, ignore_zero=False, pop_name=True, buffer=0.0, extend='neither', zoom=10, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png', **kwargs)[source]

Plot basemap expected annual impact of each exposure.

Parameters
  • mask (np.array, optional) – mask to apply to eai_exp plotted.
    • ignore_zero (bool, optional) – flag to indicate if zero and negative values are ignored in plot. Default: False

    • pop_name (bool, optional) – add names of the populated places

    • buffer (float, optional) – border to add to coordinates. Default: 0.0.

    • extend (str, optional) – extend border colorbar with arrows. [ ‘neither’ | ‘both’ | ‘min’ | ‘max’ ]

    • zoom (int, optional) – zoom coefficient used in the satellite image

    • url (str, optional) – image source, e.g. ctx.sources.OSM_C

    • kwargs (optional) – arguments for scatter matplotlib function, e.g. cmap=’Greys’. Default: ‘Wistia’

Returns:

matplotlib.figure.Figure, cartopy.mpl.geoaxes.GeoAxesSubplot

write_csv(file_name)[source]

Write data into csv file. imp_mat is not saved.

Parameters

file_name (str) – absolute path of the file

write_excel(file_name)[source]

Write data into Excel file. imp_mat is not saved.

Parameters

file_name (str) – absolute path of the file

write_sparse_csr(file_name)[source]

Write imp_mat matrix in numpy’s npz format.

calc_impact_year_set(all_years=True)[source]

Calculate yearly impact from impact data.

Parameters
  • all_years (boolean) – return values for all years between first and

  • last year with event, including years without any events.

Returns

Impact year set of type numpy.ndarray with summed impact per year.

static read_sparse_csr(file_name)[source]

Read imp_mat matrix from numpy’s npz format.

Parameters

file_name (str) – file name

Returns

sparse.csr_matrix

read_csv(file_name)[source]

Read csv file containing impact data generated by write_csv.

Parameters

file_name (str) – absolute path of the file

read_excel(file_name)[source]

Read excel file containing impact data generated by write_excel.

Parameters

file_name (str) – absolute path of the file

class climada.engine.impact.ImpactFreqCurve[source]

Bases: object

Impact exceedence frequency curve.

tag

dictionary of tags of exposures, impact functions set and hazard: {‘exp’: Tag(), ‘if_set’: Tag(), ‘haz’: TagHazard()}

Type

dict

return_per

return period

Type

np.array

impact

impact exceeding frequency

Type

np.array

unit

value unit used (given by exposures unit)

Type

str

label

string describing source data

Type

str

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

plot()[source]

Plot impact frequency curve.

Returns

matplotlib.figure.Figure, [matplotlib.axes._subplots.AxesSubplot]

plot_compare(ifc)[source]

Plot current and input impact frequency curves in a figure.

Returns

matplotlib.figure.Figure, [matplotlib.axes._subplots.AxesSubplot]

climada.engine.cost_benefit module

climada.engine.cost_benefit.risk_aai_agg(impact)[source]

Risk measurement as average annual impact aggregated.

Parameters

impact (Impact) – an Impact instance

Returns

float

climada.engine.cost_benefit.risk_rp_100(impact)[source]

Risk measurement as exceedance impact at 100 years return period.

Parameters

impact (Impact) – an Impact instance

Returns

float

climada.engine.cost_benefit.risk_rp_250(impact)[source]

Risk measurement as exceedance impact at 250 years return period.

Parameters

impact (Impact) – an Impact instance

Returns

float

class climada.engine.cost_benefit.CostBenefit[source]

Bases: object

Impact definition. Compute from an entity (exposures and impact functions) and hazard.

present_year

present reference year

Type

int

future_year

future year

Type

int

tot_climate_risk

total climate risk without measures

Type

float

unit

unit used for impact

Type

str

color_rgb

color code RGB for each measure. Key: measure name (‘no measure’ used for case without measure), Value: np.array

Type

dict

benefit

benefit of each measure. Key: measure name, Value: float benefit

Type

dict

cost_ben_ratio

cost benefit ratio of each measure. Key: measure name, Value: float cost benefit ratio

Type

dict

imp_meas_future

impact of each measure at future or default. Key: measure name (‘no measure’ used for case without measure), Value: dict with:

‘cost’ (float): cost measure, ‘risk’ (float): risk measurement, ‘risk_transf’ (float): annual expected risk transfer, ‘efc’ (ImpactFreqCurve): impact exceedance freq

(optional) ‘impact’ (Impact): impact instance

Type

dict

imp_meas_present

impact of each measure at present. Key: measure name (‘no measure’ used for case without measure), Value: dict with:

‘cost’ (float): cost measure, ‘risk’ (float): risk measurement, ‘risk_transf’ (float): annual expected risk transfer, ‘efc’ (ImpactFreqCurve): impact exceedance freq

(optional) ‘impact’ (Impact): impact instance

Type

dict

__init__()[source]

Initilization

calc(hazard, entity, haz_future=None, ent_future=None, future_year=2050, risk_func=<function risk_aai_agg>, imp_time_depen=1, save_imp=False)[source]

Compute cost-benefit ratio for every measure provided current and future conditions. Present and future measures need to have the same name. The measures costs need to be discounted by the user. If present and future entity provided, only the costs of the measures of the future and the discount rates of the present will be used.

Parameters
  • hazard (Hazard) – hazard

  • entity (Entity) – entity

  • haz_future (Hazard) – hazard in the future (future year provided at ent_future)

  • ent_future (Entity) – entity in the future

  • future_year (int) – future year to consider if no ent_future provided

  • risk_func (func, optional) – function describing risk measure given an Impact. Default: average annual impact (aggregated).

  • imp_time_depen (float, optional) – parameter which represent time evolution of impact. Default: 1 (linear).

  • save_imp (bool, optional) – activate if Impact of each measure is saved. Default: False.

plot_cost_benefit(cb_list=None)[source]

Plot cost-benefit graph. Call after calc().

Parameters

cb_list (lsit(CostBenefit), optional) – if other CostBenefit provided, overlay them all. Used for uncertainty visualization.

Returns

matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot

plot_event_view(return_per=(10, 25, 100))[source]

Plot averted damages for return periods. Call after calc().

Returns

matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot

plot_waterfall(hazard, entity, haz_future, ent_future, risk_func=<function risk_aai_agg>)[source]

Plot waterfall graph with given risk metric. Can be called before and after calc().

Parameters
  • hazard (Hazard) – hazard

  • entity (Entity) – entity

  • haz_future (Hazard) – hazard in the future (future year provided at ent_future)

  • ent_future (Entity) – entity in the future

  • risk_func (func, optional) – function describing risk measure given an Impact. Default: average annual impact (aggregated).

Returns

matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot

plot_waterfall_accumulated(hazard, entity, haz_future, ent_future, risk_func=<function risk_aai_agg>, imp_time_depen=1, plot_arrow=True)[source]

Plot waterfall graph with accumulated values from present to future year. Call after calc(). Provide same risk_func and imp_time_depen as in calc.

Parameters
  • hazard (Hazard) – hazard

  • entity (Entity) – entity

  • haz_future (Hazard) – hazard in the future (future year provided at ent_future)

  • ent_future (Entity) – entity in the future

  • risk_func (func, optional) – function describing risk measure given an Impact. Default: average annual impact (aggregated).

  • imp_time_depen (float, optional) – parameter which represent time evolution of impact. Default: 1 (linear).

  • plot_arrow (bool, optional) – plot adaptation arrow

Returns

matplotlib.figure.Figure, matplotlib.axes._subplots.AxesSubplot