src.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
Task that switches state to FAILURE if an exception occurs |
|
Represents the depths over time for a particular pixel location in a raster. |
Functions
|
Creates a model for the area using series of chained (sequential) sub-tasks. |
|
Task to ensure static base data for the given area is added to the database |
|
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. |
|
Transforms a WKT string polygon into a GeoDataFrame |
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
- src.tasks.message_broker_url
- src.tasks.app
- src.tasks.log
- class src.tasks.OnFailureStateTask
Bases:
app
Task that switches state to FAILURE if an exception occurs
- on_failure(exc, _task_id, _args, _kwargs, _einfo)
- class src.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]
- src.tasks.create_model_for_area(selected_polygon_wkt: str, scenario_options: Dict[str, str | float | int | bool]) celery.result.GroupResult
Creates 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[str, Union[str, float, int, bool]]) – Options for scenario modelling inputs, coming from JSON body.
- 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
- src.tasks.add_base_data_to_db(selected_polygon_wkt: str) None
Task to ensure static base data for the given area is added to the database
- Parameters:
selected_polygon_wkt (str) – The polygon defining the selected area to add base data for. Defined in WKT form.
- Returns:
This task does not return anything
- Return type:
None
- src.tasks.process_dem(selected_polygon_wkt: str)
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.
- Returns:
This task does not return anything
- Return type:
None
- src.tasks.generate_rainfall_inputs(selected_polygon_wkt: str)
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.
- Returns:
This task does not return anything
- Return type:
None
- src.tasks.generate_tide_inputs(selected_polygon_wkt: str, scenario_options: Dict[str, str | float | int | bool])
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[str, Union[str, float, int, bool]]) – Options for scenario modelling inputs, coming from JSON body.
- Returns:
This task does not return anything
- Return type:
None
- src.tasks.generate_river_inputs(selected_polygon_wkt: str)
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.
- Returns:
This task does not return anything
- Return type:
None
- src.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
- src.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
- Returns:
This task does not return anything
- Return type:
None
- src.tasks.wkt_to_gdf(wkt: str) geopandas.GeoDataFrame
Transforms a WKT string polygon into a GeoDataFrame
- Parameters:
wkt (str) – The WKT form of the polygon to be transformed. In WGS84 CRS (epsg:4326).
- Returns:
The GeoDataFrame form of the polygon after being transformed.
- Return type:
gpd.GeoDataFrame
- src.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
- src.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:
- src.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
- src.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]]]
- src.tasks.validate_slr_parameters(scenario_options: Dict[str, str | float | int | bool]) src.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: