3. Utils¶
-
gmtra.utils.
clean_fluvial_dirs
(hazard_path)[source]¶ Remove all the data we do not use.
- Arguments:
- hazard_path : file path to location of all hazard data.
-
gmtra.utils.
load_osm_data
(data_path, country)[source]¶ Load osm data for an entire country.
- Arguments:
data_path : file path to location of all data.
country : unique ID of the country for which we want to extract data from OpenStreetMap. Must be matching with the country ID used for saving the .osm.pbf file.
-
gmtra.utils.
load_osm_data_region
(data_path, region)[source]¶ Load osm data for a specific region.
- Arguments:
data_path : file path to location of all data.
region : unique ID of the region for which we want to extract data from OpenStreetMap. Must be matching with the region ID used for saving the .osm.pbf file.
-
gmtra.utils.
load_hazard_map
(hzd_path)[source]¶ Load specific hazard map.
- Arguments:
- hzd_path : file path to location of the hazard map.
-
gmtra.utils.
load_ssbn_hazard
(hazard_path, country_full, country_ISO2, flood_type, flood_type_abb, rp)[source]¶ Function to load a SSBN hazard map.
- Arguments:
hazard_path : Path to location of all hazard data.
country_full : Full name of country. Obtained from create_folder_lookup.
country_ISO2 : ISO2 country code of the country.
flood_type : Specifies whether it is a pluvial or fluvial flood.
flood_type_abb : Abbrevated code of the flood type. FU for river flooding, PU for surface flooding.
rp : Return period of the flood map we want to extract.
- Returns:
array: NumPy Array with the raster values.
affine : Affine of the array.
-
gmtra.utils.
gdf_clip
(gdf, clip_geom)[source]¶ Function to clip a GeoDataFrame with a shapely geometry.
- Arguments:
gdf : geopandas GeoDataFrame that we want to clip.
clip_geom : shapely geometry of region for which we do the calculation.
- Returns:
- gdf : clipped geopandas GeoDataframe
-
gmtra.utils.
sum_tuples
(l)[source]¶ Function to sum a list of tuples.
- Arguments:
- l : list of tuples.
- Returns:
- tuple : a tuple with the sum of the list of tuples.
-
gmtra.utils.
set_prot_standard
(x, prot_lookup, events)[source]¶ Function to set all values to zero below protection standard.
- Arguments:
x : row in a GeoDataFrame that represents an unique infrastructure asset.
prot_lookup : dictionary with protection standards for each region.
events : A list with the unique hazard events in row x.
- Returns:
- x : row in a GeoDataFrame that represents an unique infrastructure asset with zero values for no flooding.
-
gmtra.utils.
sensitivity_risk
(RPS, loss_list, events, param_length)[source]¶ Function to estimate the monetary risk for a particular hazard within the sensitivity analysis.
- Arguments:
RPS : list of return periods in floating probabilities (i.e. [1/10,1/20,1/50]).
loss_list : list of lists with a monetary value per return period within each inner list.
- Returns:
- collect_risks : a list of all risks for each inner list of the input list.
-
gmtra.utils.
monetary_risk
(RPS, x, events)[source]¶ Function to estimate the monetary risk for a particular hazard.
- Arguments:
RPS : list of return periods in floating probabilities (i.e. [1/10,1/20,1/50]).
x : list of lists with a monetary value per return period within each inner list.
events : list of events that correspond with the return periods in the inner lists of x.
- Returns:
- collect_risks : a list of all risks for each inner list of the input list.
-
gmtra.utils.
exposed_length_risk
(x, hzd, RPS)[source]¶ Function to estimate risk in terms of exposed kilometers.
- Arguments:
x : row in a GeoDataFrame that represents an unique infrastructure asset.
hzd : abbrevation of the hazard we want to intersect. EQ for earthquakes, Cyc for cyclones, FU for river flooding, PU for surface flooding and CF for coastal flooding.
RPS : list of return periods in floating probabilities (i.e. [1/10,1/20,1/50]). Should match with the hazard we are considering.
- Returns:
- risk value : a floating number which represents the annual exposed kilometers of infrastructure.
-
gmtra.utils.
total_length_risk
(x, RPS)[source]¶ Function to estimate risk if all assets would have been exposed.
- Arguments:
x : row in a GeoDataFrame that represents an unique infrastructure asset.
RPS : list of return periods in floating probabilities (i.e. [1/10,1/20,1/50]). Should match with the hazard we are considering.
-
gmtra.utils.
square_m2_cost_range
(x)[source]¶ Function to specify the range of possible costs for a bridge.
- Arguments:
- x : row in a GeoDataFrame that represents an unique bridge asset.
- Returns:
- list: a list with the range of possible bridge costs.
-
gmtra.utils.
extract_value_from_gdf
(x, gdf_sindex, gdf, column_name)[source]¶ - Arguments:
x : row in a geopandas GeoDataFrame. gdf_sindex : spatial index of dataframe of which we want to extract the value.
gdf : GeoDataFrame of which we want to extract the value.
column_name : column that contains the value we want to extract.
- Returns:
- extracted value from other GeoDataFrame
-
gmtra.utils.
create_folder_lookup
()[source]¶ Function to create a dictionary in which we can lookup the folder path where the surface and river flood maps are located for a country.
-
gmtra.utils.
map_roads
()[source]¶ Mapping function to create a dictionary with an aggregated list of road types.
- Returns:
- dictionary : A dictionary with road types and their aggregated equivalent
-
gmtra.utils.
map_railway
()[source]¶ Mapping function to create a dictionary with an aggregated list of railway types.
- Returns:
- dictionary : A dictionary with road types and their aggregated equivalent
-
gmtra.utils.
line_length
(line, ellipsoid='WGS-84')[source]¶ Length of a line in meters, given in geographic coordinates
- Arguments:
- line : a shapely LineString object with WGS-84 coordinates
- Optional Arguments:
- ellipsoid : string name of an ellipsoid that geopy understands (see http://geopy.readthedocs.io/en/latest/#module-geopy.distance)
- Returns:
- Length of line in meters