climada_petals.engine package#
climada_petals.engine.supplychain module#
- class climada_petals.engine.supplychain.SupplyChain[source]#
Bases:
object
SupplyChain class.
The SupplyChain class provides methods for loading Multi-Regional Input-Output Tables (MRIOT) and computing direct, indirect and total impacts.
- mriot_data#
The input-output table data.
- Type:
np.array
- mriot_reg_names#
Names of regions considered in the input-output table.
- Type:
np.array
- sectors#
Sectors considered in the input-output table.
- Type:
np.array
- total_prod#
Countries’ total production.
- Type:
np.array
- mriot_type#
Type of the adopted input-output table.
- Type:
str
- reg_pos#
Regions’ positions within the input-output table and impact arrays.
- Type:
dict
- reg_dir_imp#
Regions undergoing direct impacts.
- Type:
list
- years#
Years of the considered hazard events for which impact is calculated.
- Type:
np.array
- direct_impact#
Direct impact array.
- Type:
np.array
- direct_aai_agg#
Average annual direct impact array.
- Type:
np.array
- indirect_impact#
Indirect impact array.
- Type:
np.array
- indirect_aai_agg#
Average annual indirect impact array.
- Type:
np.array
- total_impact#
Total impact array.
- Type:
np.array
- total_aai_agg#
Average annual total impact array.
- Type:
np.array
- io_data#
Dictionary with the coefficients, inverse and risk_structure matrixes and the selected input-output modeling approach.
- Type:
dict
- read_wiod16(year=2014, range_rows=(5, 2469), range_cols=(4, 2468), col_iso3=2, col_sectors=1)[source]#
Read multi-regional input-output tables of the 2016 release of the WIOD project: http://www.wiod.org/database/wiots16
- Parameters:
year (int) – Year of WIOD table to use. Valid years go from 2000 to 2014. Default year is 2014.
range_rows (tuple) – initial and end positions of data along rows. Default is (5,2469).
range_cols (tuple) – initial and end positions of data along columns. Default is (4,2468).
col_iso3 (int) – column with countries names in ISO3 codes. Default is 2.
col_sectors (int) – column with sector names. Default is 1.
References
[1] Timmer, M. P., Dietzenbacher, E., Los, B., Stehrer, R. and de Vries, G. J. (2015), “An Illustrated User Guide to the World Input–Output Database: the Case of Global Automotive Production”, Review of International Economics., 23: 575–605
- calc_sector_direct_impact(hazard, exposure, imp_fun_set, selected_subsec='service')[source]#
Calculate direct impacts.
- Parameters:
hazard (Hazard) – Hazard object for impact calculation.
exposure (Exposures) – Exposures object for impact calculation. For WIOD tables, exposure.region_id must be country names following ISO3 codes.
imp_fun_set (ImpactFuncSet) – Set of impact functions.
selected_subsec (str or list) – Positions of the selected sectors. These positions can be either defined by the user by passing a list of values, or by using built-in sectors’ aggregations for the WIOD data passing a string with possible values being “service”, “manufacturing”, “agriculture” or “mining”. Default is “service”.
- calc_indirect_impact(io_approach='ghosh')[source]#
Calculate indirect impacts according to the specified input-output appraoch. This function needs to be run after calc_sector_direct_impact.
- Parameters:
io_approach (str) – The adopted input-output modeling approach. Possible approaches are ‘leontief’, ‘ghosh’ and ‘eeioa’. Default is ‘gosh’.
References
[1] W. W. Leontief, Output, employment, consumption, and investment, The Quarterly Journal of Economics 58, 1944. [2] Ghosh, A., Input-Output Approach in an Allocation System, Economica, New Series, 25, no. 97: 58-64. doi:10.2307/2550694, 1958. [3] Kitzes, J., An Introduction to Environmentally-Extended Input-Output Analysis, Resources, 2, 489-503; doi:10.3390/resources2040489, 2013.
climada_petals.engine.warn module#
- climada_petals.engine.warn.dilation(bin_map, size)[source]#
Dilate binary input map. The operation is based on a convolution. During translation of the filter, a point is included to the region (changed or kept to 1), if one or more elements correspond with the filter. Else, it is 0. This results in more and larger regions of interest. Larger filter sizes - more area of interest. For more information: https://scikit-image.org/docs/stable/auto_examples/applications/plot_morphology.html
- Parameters:
bin_map (np.ndarray) – Rectangle 2d map of values which are used to generate the warning.
size (int) – Size of filter.
- Returns:
Generated binary map with enlarged regions of interest.
- Return type:
np.ndarray
- climada_petals.engine.warn.erosion(bin_map, size)[source]#
Erode binary input map. The operation is based on a convolution. During translation of the filter, a point is included to the region (changed or kept to 1), if all elements correspond with the filter. Else, it is 0. This results in less and smaller regions of interest and reduces heterogeneity in map. Larger sizes - more reduction. For more information: https://scikit-image.org/docs/stable/auto_examples/applications/plot_morphology.html
- Parameters:
bin_map (np.ndarray) – Rectangle 2d map of values which are used to generate the warning.
size (int) – Size of filter.
- Returns:
Generated binary map with reduced regions of interest.
- Return type:
np.ndarray
- climada_petals.engine.warn.median_filtering(bin_map, size)[source]#
Smooth binary input map. The operation is based on a convolution. During translation of the filter, a point is included to the region (changed or kept to 1), if the median of the filter is 1. Else, it is 0. This results in smoother regions of interest and reduces heterogeneity in map. Larger sizes - smoother regions.
- Parameters:
bin_map (np.ndarray) – Rectangle 2d map of values which are used to generate the warning.
size (int) – Size of filter.
- Returns:
Generated binary map with smoothed regions of interest.
- Return type:
np.ndarray
- class climada_petals.engine.warn.Operation(value)[source]#
Bases:
Enum
Available Operations. Links operations to functions. More operations can be added.
- dilation#
Links to dilation operation.
- Type:
function
- erosion#
Links to erosion operation.
- Type:
function
- median_filtering#
Links to median filtering operation.
- Type:
function
- dilation = functools.partial(<function dilation>)#
- erosion = functools.partial(<function erosion>)#
- median_filtering = functools.partial(<function median_filtering>)#
- class climada_petals.engine.warn.Warn(warning, coord, warn_params)[source]#
Bases:
object
Warn definition. Generate a warning, i.e., 2D map of coordinates with assigned warn levels. Operations, their order, and their influence (filter sizes) can be selected to generate the warning. Further properties can be chosen which define the warning generation. The functionality of reducing heterogeneity in a map can be applied to different inputs, e.g. MeteoSwiss windstorm data (COSMO data), TCs, impacts, etc.
- warning#
Warning generated by warning generation algorithm. Warn level for every coordinate of map.
- Type:
np.ndarray
- coord#
Coordinates of warning map.
- Type:
np.ndarray
- warn_levels#
Warn levels that define the bins in which the input_map will be classified in. E.g., for windspeeds: [0, 10, 40, 80, 150, 200.0]
- Type:
list
- class WarnParameters(warn_levels: ~typing.List[float], operations: ~typing.List[~typing.Tuple[~climada_petals.engine.warn.Operation, int]] = <factory>, gradual_decr: bool = False, change_sm: bool = False)[source]#
Bases:
object
WarnParameters data class definition. It stores the relevant information needed during the warning generation. The operations and its sizes, as well as the algorithms properties $(gradual decrease of warning levels and changing of small warning regions formed) are saved.
- warn_levels#
Warn levels that define the bins in which the input_map will be classified in.
- Type:
list
- operations#
Tuples saving operations and their filter sizes to be applied in filtering algorithm.
- Type:
list
- gradual_decr#
Defines whether the highest warn levels should be gradually decreased by its neighboring regions (if True) to the lowest level (e.g., level 3, 2, 1, 0) or larger steps are allowed (e.g., from warn level 5 directly to 1).
- Type:
bool
- change_sm#
If strictly larger than 1, the levels of too small regions are changed to its surrounding levels. If 0 or None, the levels are not changed.
- Type:
int
- warn_levels: List[float]#
- gradual_decr: bool = False#
- change_sm: bool = False#
- __init__(warn_levels: ~typing.List[float], operations: ~typing.List[~typing.Tuple[~climada_petals.engine.warn.Operation, int]] = <factory>, gradual_decr: bool = False, change_sm: bool = False) None #
- __init__(warning, coord, warn_params)[source]#
Initialize Warn.
- Parameters:
warning (np.ndarray) – Warn level for every coordinate of input map.
coord (np.ndarray) – Coordinates of warning map.
warn_params (WarnParameters) – Contains information on how to generate the warning (operations and details).
- classmethod from_map(input_map, coord, warn_params)[source]#
Generate Warn object from map (value (e.g., windspeeds at coordinates).
- Parameters:
input_map (np.ndarray) – Rectangle 2d map of values which are used to generate the warning.
coord (np.ndarray) – Coordinates of warning map. For every value of the map exactly one coordinate is needed.
warn_params (WarnParameters) – Contains information on how to generate the warning (operations and details).
- Returns:
warn – Generated Warn object including warning, coordinates, warn levels, and metadata.
- Return type:
- classmethod wind_from_cosmo(path_to_cosmo, warn_params, lead_time, quant_nr=0.7)[source]#
Generate Warn object from COSMO windspeed data. The warn object is computed for the given date and time. The ensemble members of that date and time are grouped together to a single windspeed map.
- Parameters:
path_to_cosmo (string) – Path including name to cosmo file.
warn_params (WarnParameters) – Contains information on how to generate the warning (operations and details).
lead_time (datetime) – Lead time when warning should be generated.
quant_nr (float) – Quantile number to group ensemble members of COSMO wind speeds.
- Returns:
warn – Generated Warn object including warning, coordinates, warn levels, and metadata.
- Return type:
- classmethod from_hazard(hazard, warn_params)[source]#
Generate Warn object from hazard object. The intensity map is used therefore. It needs to be transferable to a dense matrix, else the computation of the warning is impossible.
- Parameters:
hazard (Hazard) – Contains the information of which to generate a warning from.
warn_params (WarnParameters) – Contains information on how to generate the warning (operations and details).
- Returns:
warn – Generated Warn object including warning, coordinates, warn levels, and metadata.
- Return type:
- static bin_map(input_map, levels)[source]#
Bin every value of input map into given levels.
- Parameters:
input_map (np.ndarray) – Array containing data to generate binned map of.
levels (list) – List with levels to bin input map.
- Returns:
binned_map – Map of binned values in levels, same shape as input map.
- Return type:
np.ndarray
- static zeropadding(lat, lon, val, res_rel_error=0.01)[source]#
Produces a rectangular shaped map from a non-rectangular map (e.g., country). For this, a regular grid is created in the rectangle enclosing the non-rectangular map. The values are mapped onto the regular grid according to their coordinates. The regular gird is filled with zeros where no values are defined. are defined. This only works if the lat lon values of the non-rectangular map can be accurately represented on a grid with a regular resolution.
- Parameters:
lat (list) – Latitudes of values of map.
lon (list) – Longitudes of values of map.
val (list) – Values of quantity of interest at every coordinate given.
res_rel_error (float) – defines the relative error in terms of grid resolution by which the lat lon values of the returned coord_rec can maximally differ from the provided lat lon values. Default: 0.01
- Returns:
map_rec (np.ndarray) – Rectangular map with a value for every grid point. Padded with zeros where no values in input map.
coord_rec (np.ndarray) – Longitudes and Latitudes of every value of the map.
- plot_warning(var_name='Warn Levels', title='Categorical Warning Map', cat_name=None, adapt_fontsize=True, **kwargs)[source]#
Map plots for categorical data defined in array(s) over input coordinates. The categories must be a finite set of unique values as can be identified by np.unique() (mix of int, float, strings, …).
The categories are shared among all subplots, i.e. are obtained from np.unique(array_sub). Eg.:
>>> array_sub = [[1, 2, 1.0, 2], [1, 2, 'a', 'a']] >>> -> category mapping is [[0, 2, 1, 2], [0, 2, 3, 3]]
Same category: 1 and ‘1’ Different categories: 1 and 1.0
This method wraps around util.geo_scatter_from_array and uses all its args and kwargs.
- Parameters:
var_name (str or list(str)) – label to be shown in the colorbar. If one provided, the same is used for all subplots. Otherwise provide as many as subplots in array_sub.
title (str or list(str)) – subplot title. If one provided, the same is used for all subplots. Otherwise provide as many as subplots in array_sub.
cat_name (dict, optional) – Categories name for the colorbar labels. Keys are all the unique values in array_sub, values are their labels. The default is labels = unique values.
adapt_fontsize (bool, optional) – If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise the default matplotlib font size is used. Default is True.
**kwargs – Arbitrary keyword arguments for hexbin matplotlib function
- Return type:
cartopy.mpl.geoaxes.GeoAxesSubplot
- plot_warning_meteoswiss_style(var_name='Warn Levels', title='Categorical Warning Map', cat_name=None, adapt_fontsize=True)[source]#
Map plots for categorical data defined in array(s) over input coordinates. The MeteoSwiss coloring scheme is used, therefore only 5 warn levels are allowed.
This method wraps around util.geo_scatter_from_array and uses all its args and kwargs.
- Parameters:
var_name (str or list(str)) – label to be shown in the colorbar. If one provided, the same is used for all subplots. Otherwise provide as many as subplots in array_sub.
title (str or list(str)) – subplot title. If one provided, the same is used for all subplots. Otherwise provide as many as subplots in array_sub.
cat_name (dict, optional) – Categories name for the colorbar labels. Keys are all the unique values in array_sub, values are their labels. The default is labels = unique values.
adapt_fontsize (bool, optional) – If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise the default matplotlib font size is used. Default is True.
**kwargs – Arbitrary keyword arguments for hexbin matplotlib function
- Return type:
cartopy.mpl.geoaxes.GeoAxesSubplot