climada.hazard package

climada.hazard.base module

class climada.hazard.base.Hazard(haz_type, pool=None)[source]

Bases: object

Contains events of some hazard type defined at centroids. Loads from files with format defined in FILE_EXT.

tag

information about the source

Type

TagHazard

units

units of the intensity

Type

str

centroids

centroids of the events

Type

Centroids

event_id

id (>0) of each event

Type

np.array

event_name

name of each event (default: event_id)

Type

list(str)

date

integer date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1 (ordinal format of datetime library)

Type

np.array

orig

flags indicating historical events (True) or probabilistic (False)

Type

np.array

frequency

frequency of each event in years

Type

np.array

intensity

intensity of the events at centroids

Type

sparse.csr_matrix

fraction

fraction of affected exposures for each event at each centroid

Type

sparse.csr_matrix

intensity_thres = 10

Intensity threshold per hazard used to filter lower intensities. To be set for every hazard type

vars_oblig = {'centroids', 'event_id', 'fraction', 'frequency', 'intensity', 'tag', 'units'}

scalar, str, list, 1dim np.array of size num_events, scipy.sparse matrix of shape num_events x num_centroids, Centroids and Tag.

Type

Name of the variables needed to compute the impact. Types

vars_def = {'date', 'event_name', 'orig'}

Name of the variables used in impact calculation whose value is descriptive and can therefore be set with default values. Types: scalar, string, list, 1dim np.array of size num_events.

vars_opt = {}

Name of the variables that aren’t need to compute the impact. Types: scalar, string, list, 1dim np.array of size num_events.

__init__(haz_type, pool=None)[source]

Initialize values.

Parameters

haz_type (str, optional) – acronym of the hazard type (e.g. ‘TC’).

Examples

Fill hazard values by hand:

>>> haz = Hazard('TC')
>>> haz.intensity = sparse.csr_matrix(np.zeros((2, 2)))
>>> ...

Take hazard values from file:

>>> haz = Hazard('TC', HAZ_DEMO_MAT)
>>> haz.read_mat(HAZ_DEMO_MAT, 'demo')
clear()[source]

Reinitialize attributes.

check()[source]

Check dimension of attributes.

Raises

ValueError

set_raster(files_intensity, files_fraction=None, attrs={}, band=[1], src_crs=None, window=False, geometry=False, dst_crs=False, transform=None, width=None, height=None, resampling=<Resampling.nearest: 0>)[source]

Append intensity and fraction from raster file. 0s put to the masked values. File can be partially read using window OR geometry. Alternatively, CRS and/or transformation can be set using dst_crs and/or (transform, width and height).

Parameters
  • files_intensity (list(str)) – file names containing intensity

  • files_fraction (list(str)) – file names containing fraction

  • attrs (dict, optional) – name of Hazard attributes and their values

  • band (list(int), optional) – bands to read (starting at 1)

  • src_crs (crs, optional) – source CRS. Provide it if error without it.

  • window (rasterio.windows.Windows, optional) – window where data is extracted

  • geometry (shapely.geometry, optional) – consider pixels only in shape

  • dst_crs (crs, optional) – reproject to given crs

  • transform (rasterio.Affine) – affine transformation to apply

  • wdith (float) – number of lons for transform

  • height (float) – number of lats for transform

  • resampling (rasterio.warp,.Resampling optional) – resampling function used for reprojection to dst_crs

set_vector(files_intensity, files_fraction=None, attrs={}, inten_name=['intensity'], frac_name=['fraction'], dst_crs=None)[source]

Read vector files format supported by fiona. Each intensity name is considered an event.

Parameters
  • files_intensity (list(str)) – file names containing intensity

  • files_fraction (list(str)) – file names containing fraction

  • attrs (dict, optional) – name of Hazard attributes and their values

  • inten_name (list(str), optional) – name of variables containing the intensities of each event

  • frac_name (list(str), optional) – name of variables containing the fractions of each event

  • dst_crs (crs, optional) – reproject to given crs

reproject_raster(dst_crs=False, transform=None, width=None, height=None, resampl_inten=<Resampling.nearest: 0>, resampl_fract=<Resampling.nearest: 0>)[source]

Change current raster data to other CRS and/or transformation

Parameters
  • dst_crs (crs, optional) – reproject to given crs

  • transform (rasterio.Affine) – affine transformation to apply

  • wdith (float) – number of lons for transform

  • height (float) – number of lats for transform

  • resampl_inten (rasterio.warp,.Resampling optional) – resampling function used for reprojection to dst_crs for intensity

  • resampl_fract (rasterio.warp,.Resampling optional) – resampling function used for reprojection to dst_crs for fraction

reproject_vector(dst_crs, scheduler=None)[source]

Change current point data to a a given projection

Parameters
  • dst_crs (crs) – reproject to given crs

  • scheduler (str, optional) – used for dask map_partitions. “threads”, “synchronous” or “processes”

raster_to_vector()[source]

Change current raster to points (center of the pixels)

vector_to_raster(scheduler=None)[source]

Change current point data to a raster with same resolution

Parameters

scheduler (str, optional) – used for dask map_partitions. “threads”, “synchronous” or “processes”

read_mat(file_name, description='', var_names={'field_name': 'hazard', 'var_cent': {'field_names': ['centroids', 'hazard'], 'var_name': {'cen_id': 'centroid_ID', 'lat': 'lat', 'lon': 'lon'}}, 'var_name': {'comment': 'comment', 'datenum': 'datenum', 'ev_name': 'name', 'even_id': 'event_ID', 'frac': 'fraction', 'freq': 'frequency', 'inten': 'intensity', 'orig': 'orig_event_flag', 'per_id': 'peril_ID', 'unit': 'units'}})[source]

Read climada hazard generate with the MATLAB code.

Parameters
  • file_name (str) – absolute file name

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

  • var_names (dict, default) – name of the variables in the file, default: DEF_VAR_MAT constant

Raises

KeyError

read_excel(file_name, description='', var_names={'col_centroids': {'col_name': {'cen_id': 'centroid_id', 'lat': 'latitude', 'lon': 'longitude'}, 'sheet_name': 'centroids'}, 'col_name': {'cen_id': 'centroid_id/event_id', 'even_dt': 'event_date', 'even_id': 'event_id', 'even_name': 'event_name', 'freq': 'frequency', 'orig': 'orig_event_flag'}, 'sheet_name': {'freq': 'hazard_frequency', 'inten': 'hazard_intensity'}})[source]

Read climada hazard generate with the MATLAB code.

Parameters
  • file_name (str) – absolute file name

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

  • centroids (Centroids, optional) – provide centroids if not contained in the file

  • var_names (dict, default) – name of the variables in the file, default: DEF_VAR_EXCEL constant

Raises

KeyError

select(date=None, orig=None, reg_id=None, reset_frequency=False)[source]

Select events within provided date and/or (historical or synthetical) and/or region. Frequency of the events may need to be recomputed!

Parameters
  • date (tuple(str or int), optional) – (initial date, final date) in string ISO format (‘2011-01-02’) or datetime ordinal integer

  • orig (bool, optional) – select only historical (True) or only synthetic (False)

  • reg_id (int, optional) – region identifier of the centroids’s region_id attibute

  • reset_frequency (boolean) – change frequency of events proportional to difference between first and last year (old and new) default = False

Returns

Hazard or children

local_exceedance_inten(return_periods=25, 50, 100, 250)[source]

Compute exceedance intensity map for given return periods.

Parameters

return_periods (np.array) – return periods to consider

Returns

np.array

plot_rp_intensity(return_periods=25, 50, 100, 250, smooth=True, axis=None, **kwargs)[source]

Compute and plot hazard exceedance intensity maps for different return periods. Calls local_exceedance_inten.

Parameters
  • return_periods (tuple(int), optional) – return periods to consider

  • smooth (bool, optional) – smooth plot to plot.RESOLUTIONxplot.RESOLUTION

  • axis (matplotlib.axes._subplots.AxesSubplot, optional) – axis to use

  • kwargs (optional) – arguments for pcolormesh matplotlib function used in event plots

Returns

matplotlib.axes._subplots.AxesSubplot, np.ndarray (return_periods.size x num_centroids)

plot_intensity(event=None, centr=None, smooth=True, axis=None, **kwargs)[source]

Plot intensity values for a selected event or centroid.

Parameters
  • event (int or str, optional) – If event > 0, plot intensities of event with id = event. If event = 0, plot maximum intensity in each centroid. If event < 0, plot abs(event)-largest event. If event is string, plot events with that name.

  • centr (int or tuple, optional) – If centr > 0, plot intensity of all events at centroid with id = centr. If centr = 0, plot maximum intensity of each event. If centr < 0, plot abs(centr)-largest centroid where higher intensities are reached. If tuple with (lat, lon) plot intensity of nearest centroid.

  • smooth (bool, optional) – smooth plot to plot.RESOLUTIONxplot.RESOLUTION

  • axis (matplotlib.axes._subplots.AxesSubplot, optional) – axis to use

  • kwargs (optional) – arguments for pcolormesh matplotlib function used in event plots or for plot function used in centroids plots

Returns

matplotlib.axes._subplots.AxesSubplot

Raises

ValueError

plot_fraction(event=None, centr=None, smooth=True, axis=None, **kwargs)[source]

Plot fraction values for a selected event or centroid.

Parameters
  • event (int or str, optional) – If event > 0, plot fraction of event with id = event. If event = 0, plot maximum fraction in each centroid. If event < 0, plot abs(event)-largest event. If event is string, plot events with that name.

  • centr (int or tuple, optional) – If centr > 0, plot fraction of all events at centroid with id = centr. If centr = 0, plot maximum fraction of each event. If centr < 0, plot abs(centr)-largest centroid where highest fractions are reached. If tuple with (lat, lon) plot fraction of nearest centroid.

  • smooth (bool, optional) – smooth plot to plot.RESOLUTIONxplot.RESOLUTION

  • axis (matplotlib.axes._subplots.AxesSubplot, optional) – axis to use

  • kwargs (optional) – arguments for pcolormesh matplotlib function used in event plots or for plot function used in centroids plots

Returns

matplotlib.axes._subplots.AxesSubplot

Raises

ValueError

get_event_id(event_name)[source]

“Get an event id from its name. Several events might have the same name.

Parameters

event_name (str) – Event name

Returns

np.array(int)

get_event_name(event_id)[source]

“Get the name of an event id.

Parameters

event_id (int) – id of the event

Returns

str

Raises

ValueError

get_event_date(event=None)[source]

Return list of date strings for given event or for all events, if no event provided.

Parameters

event (str or int, optional) – event name or id.

Returns

list(str)

calc_year_set()[source]

From the dates of the original events, get number yearly events.

Returns

key are years, values array with event_ids of that year

Return type

dict

append(hazard)[source]

Append events and centroids in hazard.

Parameters

hazard (Hazard) – Hazard instance to append to current

Raises

ValueError

remove_duplicates()[source]

Remove duplicate events (events with same name and date).

property size

Returns number of events

write_raster(file_name, intensity=True)[source]

Write intensity or fraction as GeoTIFF file. Each band is an event

Parameters
  • file_name (str) – file name to write in tif format

  • intensity (bool) – if True, write intensity, otherwise write fraction

write_hdf5(file_name, todense=False)[source]

Write hazard in hdf5 format.

Parameters

file_name (str) – file name to write, with h5 format

read_hdf5(file_name)[source]

Read hazard in hdf5 format.

Parameters

file_name (str) – file name to read, with h5 format

climada.hazard.tag module

class climada.hazard.tag.Tag(haz_type='', file_name='', description='')[source]

Bases: object

Contain information used to tag a Hazard.

file_name

name of the source file(s)

Type

str or list(str)

haz_type

acronym defining the hazard type (e.g. ‘TC’)

Type

str

description

description(s) of the data

Type

str or list(str)

__init__(haz_type='', file_name='', description='')[source]

Initialize values.

Parameters
  • haz_type (str, optional) – acronym of the hazard type (e.g. ‘TC’).

  • file_name (str or list(str), optional) – file name(s) to read

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

append(tag)[source]

Append input Tag instance information to current Tag.

join_file_names()[source]

Get a string with the joined file names.

join_descriptions()[source]

Get a string with the joined descriptions.

climada.hazard.trop_cyclone module

class climada.hazard.trop_cyclone.TropCyclone(pool=None)[source]

Bases: climada.hazard.base.Hazard

Contains tropical cyclone events. .. attribute:: category

for every event, the TC category using the Saffir-Simpson scale:

-1 tropical depression

0 tropical storm 1 Hurrican category 1 2 Hurrican category 2 3 Hurrican category 3 4 Hurrican category 4 5 Hurrican category 5

type

np.array(int)

basin

basin where every event starts ‘NA’ North Atlantic ‘EP’ Eastern North Pacific ‘WP’ Western North Pacific ‘NI’ North Indian ‘SI’ South Indian ‘SP’ Southern Pacific ‘SA’ South Atlantic

Type

list(str)

intensity_thres = 17.5

intensity threshold for storage in m/s

vars_opt = {'category'}

Name of the variables that aren’t need to compute the impact.

__init__(pool=None)[source]

Empty constructor.

set_from_tracks(tracks, centroids=None, description='', model='H08', ignore_distance_to_coast=False)[source]

Clear and model tropical cyclone from input IBTrACS tracks. Parallel process. :Parameters: * tracks (TCTracks) – tracks of events

  • centroids (Centroids, optional) – Centroids where to model TC. Default: global centroids.

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

  • model (str, optional) – model to compute gust. Default Holland2008.

  • ignore_distance_to_coast (boolean, optional) – if True, centroids far from coast are not ignored. Default False

Raises

ValueError

set_climate_scenario_knu(ref_year=2050, rcp_scenario=45)[source]

Compute future events for given RCP scenario and year. RCP 4.5 from Knutson et al 2015. :Parameters: * ref_year (int) – year between 2000 ad 2100. Default: 2050

  • rcp_scenario (int) – 26 for RCP 2.6, 45 for RCP 4.5 (default), 60 for RCP 6.0 and 85 for RCP 8.5.

Returns

TropCyclone

static video_intensity(track_name, tracks, centroids, file_name=None, writer=<matplotlib.animation.PillowWriter object>, **kwargs)[source]

Generate video of TC wind fields node by node and returns its corresponding TropCyclone instances and track pieces.

Parameters
  • track_name (str) – name of the track contained in tracks to record

  • tracks (TCTracks) – tracks

  • centroids (Centroids) – centroids where wind fields are mapped

  • file_name (str, optional) – file name to save video, if provided

  • writer = (matplotlib.animation., optional*) – video writer. Default: pillow with bitrate=500

  • kwargs (optional) – arguments for pcolormesh matplotlib function used in event plots

Returns

list(TropCyclone), list(np.array)

Raises

ValueError

climada.hazard.tc_tracks module

climada.hazard.tc_tracks.SAFFIR_SIM_CAT = [34, 64, 83, 96, 113, 135, 1000]

Saffir-Simpson Hurricane Wind Scale in kn

class climada.hazard.tc_tracks.TCTracks(pool=None)[source]

Bases: object

Contains tropical cyclone tracks.

data

list of tropical cyclone tracks. Each track contains following attributes:

  • time (coords)

  • lat (coords)

  • lon (coords)

  • time_step

  • radius_max_wind

  • max_sustained_wind

  • central_pressure

  • environmental_pressure

  • max_sustained_wind_unit (attrs)

  • central_pressure_unit (attrs)

  • name (attrs)

  • sid (attrs)

  • orig_event_flag (attrs)

  • data_provider (attrs)

  • basin (attrs)

  • id_no (attrs)

  • category (attrs)

computed during processing:
  • on_land

  • dist_since_lf

Type

list(xarray.Dataset)

__init__(pool=None)[source]

Empty constructor. Read csv IBTrACS files if provided.

append(tracks)[source]

Append tracks to current.

Parameters

tracks (xarray.Dataset or list(xarray.Dataset)) – tracks to append.

get_track(track_name=None)[source]

Get track with provided name. Return all tracks if no name provided.

Parameters

track_name (str, optional) – name or sid (ibtracsID for IBTrACS) of track

Returns

xarray.Dataset or [xarray.Dataset]

read_ibtracs_netcdf(provider='usa', storm_id=None, year_range=1980, 2018, basin=None, file_name='IBTrACS.ALL.v04r00.nc', correct_pres=True)[source]

Fill from raw ibtracs v04. Removes nans in coordinates, central pressure and removes repeated times data. Fills nans of environmental_pressure and radius_max_wind. Checks environmental_pressure > central_pressure.

Parameters
  • provider (str) – data provider. e.g. usa, newdelhi, bom, cma, tokyo

  • storm_id (str or list(str), optional) – ibtracs if of the storm, e.g. 1988234N13299, [1988234N13299, 1989260N11316]

  • year_range (tuple, optional) – (min_year, max_year). Default: (1980, 2018)

  • basin (str, optional) – e.g. US, SA, NI, SI, SP, WP, EP, NA. if not provided, consider all basins.

  • file_name (str, optional) – name of netcdf file to be dowloaded or located at climada/data/system. Default: ‘IBTrACS.ALL.v04r00.nc’.

  • correct_pres (bool, optional) – correct central pressure if missing values. Default: False

read_processed_ibtracs_csv(file_names)[source]

Fill from processed ibtracs csv file.

Parameters

file_names (str or list(str)) – absolute file name(s) or folder name containing the files to read.

read_simulations_emanuel(file_names, hemisphere='S')[source]

Fill from Kerry Emanuel tracks.

Parameters
  • file_names (str or list(str)) – absolute file name(s) or folder name containing the files to read.

  • hemisphere (str, optional) – ‘S’, ‘N’ or ‘both’. Default: ‘S’

equal_timestep(time_step_h=1, land_params=False)[source]

Generate interpolated track values to time steps of min_time_step.

Parameters
  • time_step_h (float, optional) – time step in hours to which to interpolate. Default: 1.

  • land_params (bool, optional) – compute on_land and dist_since_lf at each node. Default: False.

calc_random_walk(ens_size=9, ens_amp0=1.5, max_angle=0.3141592653589793, ens_amp=0.1, seed=54, decay=True)[source]

Generate synthetic tracks. An ensamble of tracks is computed for every track contained.

Parameters
  • ens_size (int, optional) – number of ensamble per original track. Default 9.

  • ens_amp0 (float, optional) – amplitude of max random starting point shift degree longitude. Default: 1.5

  • max_angle (float, optional) – maximum angle of variation, =pi is like undirected, pi/4 means one quadrant. Default: pi/10

  • ens_amp (float, optional) – amplitude of random walk wiggles in degree longitude for ‘directed’. Default: 0.1

  • seed (int, optional) – random number generator seed. Put negative value if you don’t want to use it. Default: configuration file

  • decay (bool, optional) – compute land decay in probabilistic tracks. Default: True

property size

Get longitude from coord array

plot(axis=None, **kwargs)[source]

Track over earth. Historical events are blue, probabilistic black.

Parameters
  • axis (matplotlib.axes._subplots.AxesSubplot, optional) – axis to use

  • kwargs (optional) – arguments for LineCollection matplotlib, e.g. alpha=0.5

Returns

matplotlib.axes._subplots.AxesSubplot

write_netcdf(folder_name)[source]

Write a netcdf file per track with track.sid name in given folder.

Parameter:

folder_name (str): folder name where to write files

read_netcdf(folder_name)[source]

Read all netcdf files contained in folder and fill a track per file.

Parameters

folder_name (str) – folder name where to write files

climada.hazard.tc_tracks.set_category(max_sus_wind, max_sus_wind_unit, saffir_scale=None)[source]

Add storm category according to saffir-simpson hurricane scale

  • -1 tropical depression

  • 0 tropical storm

  • 1 Hurrican category 1

  • 2 Hurrican category 2

  • 3 Hurrican category 3

  • 4 Hurrican category 4

  • 5 Hurrican category 5

Parameters
  • max_sus_wind (np.array) – max sustained wind

  • max_sus_wind_unit (str) – units of max sustained wind

  • saffir_scale (list, optional) – Saffir-Simpson scale in same units as wind

Returns

double