pem.risk#
This is the complete API reference for the risk python module of the pem system.
See also
Learn how to derive the Habitat Risk Index in Tutorial: Habitat Risk Index.
- pem.risk.get_risk_index(folder_project, scenario, hra_benthic, hra_pelagic)[source]#
Calculate and normalize the total risk index by combining benthic and pelagic Habitat Risk Assessment (HRA) results.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
hra_benthic (str) – Path to the benthic HRA raster file
hra_pelagic (str) – Path to the pelagic HRA raster file
- Returns:
Path to the generated normalized risk raster
- Return type:
pathlib.Path
Extra notes
The function reprojects and resamples input HRA rasters to a common grid, sums the overlapping layers using raster calculation, and applies a normalization process to produce a final risk map.
Script example
# !WARNING: run this in QGIS Python Environment import importlib.util as iu # define the paths to the module file # ------------------------------------------------------ file = "path/to/risk.py" # change here # define the project folder # ------------------------------------------------------ folder = "path/to/folder" # change here # define scenario # ------------------------------------------------------ scenario = "baseline" # define paths to InVEST HRA outputs # ------------------------------------------------------ hra_benthic = "path/to/TOTAL_RISK_Ecosystem**_pelagic.tif" hra_pelagic = "path/to/TOTAL_RISK_Ecosystem**_pelagic.tif" # call the function # ------------------------------------------------------ # do not change here spec = iu.spec_from_file_location("module", file) module = iu.module_from_spec(spec) spec.loader.exec_module(module) ls_output = module.get_risk_index( folder_project=folder, scenario=scenario, hra_benthic=hra_benthic, hra_pelagic=hra_pelagic ) print(" ----- DONE -----")
- pem.risk.setup_hra_model(folder_project, scenario)[source]#
Execute the full configuration suite required to initialize an InVEST HRA model.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
- Returns:
Always returns
None- Return type:
None
Script example
# !WARNING: run this in QGIS Python Environment import importlib.util as iu # define the paths to the module file # ------------------------------------------------------ file = "path/to/risk.py" # change here # define the project folder # ------------------------------------------------------ folder = "path/to/folder" # change here # define scenario # ------------------------------------------------------ scenario = "baseline" # call the function # ------------------------------------------------------ # do not change here spec = iu.spec_from_file_location("module", file) module = iu.module_from_spec(spec) spec.loader.exec_module(module) ls_output = module.setup_hra_model( folder_project=folder, scenario=scenario ) print(" ----- DONE -----")
- pem.risk.setup_hra_scores(folder_project, scenario)[source]#
Generate the CSV scoring matrices for habitats and stressors based on project info tables.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
- Returns:
List of paths to the generated score CSV files
- Return type:
list
- pem.risk.setup_hra_info(folder_project, scenario, buffers=10000)[source]#
Create the HRA information tables linking habitat and stressor names to their respective file paths.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
buffers (int) – The buffer distance for stressors in meters. Default value = 10000
- Returns:
List of paths to the generated info CSV files
- Return type:
list
- pem.risk.setup_hra_json(folder_project, scenario)[source]#
Configure and save InVEST model parameter files in JSON format for the specified scenario.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
- Returns:
List of paths to the created JSON configuration files
- Return type:
list