floodresilience.tasks
Runs backend tasks using Celery. Allowing for multiple long-running tasks to complete in the background. Allows the frontend to send tasks and retrieve status later.
Attributes
Classes
Represents the depths over time for a particular pixel location in a raster. |
Functions
|
Initialise database, runs when Celery instance is ready. |
|
Create a model for the area using series of chained (sequential) sub-tasks. |
|
Task to ensure hydrologically-conditioned DEM is processed for the given area and added to the database. |
|
Task to ensure rainfall input data for the given area is added to the database and model input files are created. |
|
Task to ensure tide input data for the given area is added to the database and model input files are created. |
|
Task to ensure river input data for the given area is added to the database and model input files are created. |
|
Task to run flood model using input data from previous tasks. |
|
Web-scrapes OpenTopography metadata to create the datasets table containing links to LiDAR data sources. |
Check if LiDAR datasets table is initialised. |
|
Task to query the database and find the filepath for the model output for the model_id. |
|
|
Task to query a point in a flood model output and return the list of depths and times. |
|
Task to find the bounding box of a given model output. |
Task to get information on valid tide and sea-level-rise parameters based on the valid values in the database. |
|
Task to validate each of the sea-level-rise parameters. |
Module Contents
- floodresilience.tasks.log
- class floodresilience.tasks.DepthTimePlot
Bases:
NamedTuple
Represents the depths over time for a particular pixel location in a raster. Uses tuples and lists instead of Arrays or Dataframes because it needs to be easily serializable when communicating over message_broker.
- depths
A list of all of the depths in m for the pixel. Parallels the times list
- Type:
List[float]
- times
A list of all of the times in s for the pixel. Parallels the depts list
- Type:
List[float]
- depths: List[float]
- times: List[float]
- floodresilience.tasks.on_startup(sender: celery.worker.consumer.Consumer, **_kwargs: None) None
Initialise database, runs when Celery instance is ready.
- Parameters:
sender (Consumer) – The Celery worker node instance
- floodresilience.tasks.create_model_for_area(selected_polygon_wkt: str, scenario_options: dict) celery.result.GroupResult
Create a model for the area using series of chained (sequential) sub-tasks.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to run the model for. Defined in WKT form.
scenario_options (dict) – Options for scenario modelling inputs.
- Returns:
The task result for the long-running group of tasks. The task ID represents the final task in the group.
- Return type:
result.GroupResult
- floodresilience.tasks.process_dem(selected_polygon_wkt: str) None
Task to ensure hydrologically-conditioned DEM is processed for the given area and added to the database.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to process the DEM for. Defined in WKT form.
- floodresilience.tasks.generate_rainfall_inputs(selected_polygon_wkt: str) None
Task to ensure rainfall input data for the given area is added to the database and model input files are created.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to add rainfall data for. Defined in WKT form.
- floodresilience.tasks.generate_tide_inputs(selected_polygon_wkt: str, scenario_options: dict) None
Task to ensure tide input data for the given area is added to the database and model input files are created.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to add tide data for. Defined in WKT form.
scenario_options (dict) – Options for scenario modelling inputs.
- floodresilience.tasks.generate_river_inputs(selected_polygon_wkt: str) None
Task to ensure river input data for the given area is added to the database and model input files are created.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to add river data for. Defined in WKT form.
- floodresilience.tasks.run_flood_model(selected_polygon_wkt: str) int
Task to run flood model using input data from previous tasks.
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to run the flood model for. Defined in WKT form.
- Returns:
The database ID of the flood model that has been run.
- Return type:
int
- floodresilience.tasks.refresh_lidar_datasets() None
Web-scrapes OpenTopography metadata to create the datasets table containing links to LiDAR data sources. Takes a long time to run but needs to be run periodically so that the datasets are up to date.
- floodresilience.tasks.ensure_lidar_datasets_initialised() None
Check if LiDAR datasets table is initialised. This table holds URLs to data sources for LiDAR. If it is not initialised, then it initialises it by web-scraping OpenTopography which takes a long time.
- floodresilience.tasks.get_model_output_filepath_from_model_id(model_id: int) str
Task to query the database and find the filepath for the model output for the model_id.
- Parameters:
model_id (int) – The database id of the model output to query.
- Returns:
Serialized posix-style str version of the filepath.
- Return type:
str
- floodresilience.tasks.get_depth_by_time_at_point(model_id: int, lat: float, lng: float) DepthTimePlot
Task to query a point in a flood model output and return the list of depths and times.
- Parameters:
model_id (int) – The database id of the model output to query.
lat (float) – The latitude of the point to query.
lng (float) – The longitude of the point to query.
- Returns:
Tuple of depths list and times list for the pixel in the output nearest to the point.
- Return type:
- floodresilience.tasks.get_model_extents_bbox(model_id: int) str
Task to find the bounding box of a given model output.
- Parameters:
model_id (int) – The database id of the model output to query.
- Returns:
The bounding box in ‘x1,y1,x2,y2’ format.
- Return type:
str
- floodresilience.tasks.get_valid_parameters_based_on_confidence_level() Dict[str, Dict[str, str | int]]
Task to get information on valid tide and sea-level-rise parameters based on the valid values in the database. These parameters are mostly dependent on the “confidence_level” parameter, so that is the key in the returned dict.
- Returns:
Dictionary with confidence_level as the key, and 2nd level dict with allowed values for dependent values.
- Return type:
Dict[str, Dict[str, Union[str, int]]]
- floodresilience.tasks.validate_slr_parameters(scenario_options: Dict[str, str | float | int | bool]) floodresilience.dynamic_boundary_conditions.tide.main_tide_slr.ValidationResult
Task to validate each of the sea-level-rise parameters.
- Parameters:
scenario_options (Dict[str, Union[str, float, int, bool]]) – Options for scenario modelling inputs, coming from JSON body.
- Returns:
Result of the validation, with validation failure reason if applicable
- Return type: