warningdata module¶
Framework to import, cache, and use flood warning and corresponding data.
-
warningdata.
build_regions_geojson
(warnings, file=None)¶ Create geoJSON FeatureCollection object to plot flood warnings on a map.
- Parameters
warnings (list[FloodWarning]) – List of flood warnings.
file (string, optional) – For debug purposes, saves parameters data to a file, without any coordinates if file is a non-None string. The default is None.
- Returns
data – The geoJSON object containing the regions of all the warnings in warnings.
- Return type
dict
-
warningdata.
build_severity_dataframe
(warnings)¶ Build dataframe with warnings data, used to colour the map regions.
- Parameters
warnings (list[FloodWarning]) – list of flood warnings.
- Returns
df – Pandas DataFrame with the relevant data for each warning
- Return type
pandas.DataFrame
-
warningdata.
build_warning_list
(severity, use_pickle_caches=True, progress_bar=False)¶ Fetch warnings from the API and create a list of warnings.
Also updates caches for flood regions for any new warnings.
- Parameters
severity (int) – warnings above this minimum severity value (ie of lower numerical value) will be returned.
use_pickle_caches (bool, optional) – If true, then cached data regarding flood regions is used - the flood warnings are still the most recent pulled from the API. The default is True.
progress_bar (bool, optional) – If supplied, creates a bar in the terminal and updates as the warning list is built. The defualt is False
- Returns
warnings – The list of FloodWarning objects of severity greater than or equal to severity.
- Return type
list[FloodWarning]
-
warningdata.
retrieve_pickle_cache
(filename)¶ Read a cached pickle file and returns the result.
- Parameters
filename (string) – The name of the pickle file to be read. This file must be in the cache directory.
- Returns
The python variables read from the pickle file..
- Return type
pickle_variables
-
warningdata.
save_to_pickle_cache
(filename, data)¶ Save data to a pickle cache file.
- Parameters
filename (string) – The name of the pickle file to be saved. The file is placed in the cache directory.
data – The data to be saved to a pickle file. Any Python variable type may be used.
- Returns
- Return type
None.
-
warningdata.
update_poly_area_caches
(warnings, poly_cache='warning_polys.pk', area_cache='warning_areas.pk', overwrite=False)¶ Create updated lists of polygons/areas pertaining to any new warnings.
If previous cached data is available, and overwrite is false the new data is appended to this. polygon data is stored as a list of lists containing four attributes for each warning: [[geojson, region, is_poly_simplified, simplified_geojson], …]
area data is stored as a list of json objects obtained from the API for each warning: [[area_json], …]
- Parameters
warnings (list[FLoodWarnings]) – The list of FloodWarning objects of severity greater than or equal to severity.
poly_cache (string, optional) – The name of the polygon cache file. The default is ‘warning_polys.pk’.
area_cache (string, optional) – The name of the area cache file. The default is ‘warning_areas.pk’.
overwrite (bool, optional) –
- If True, previously cached data is overwritten and only current data is
added to the cache files. The default is False.
- Returns
- Return type
None.