pem.conflict#
This is the complete API reference for the conflict python module of the pem system.
- pem.conflict.get_conflict_index(folder_project, scenario)[source]#
Calculate the spatial conflict index by performing weighted pairwise overlaps between user activity rasters.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
- Returns:
A list containing the path to the final normalized conflict raster
- Return type:
list
Extra notes
The function identifies all unique pairs of user activities and computes their intersection using raster multiplication. Each resulting overlap is normalized and then weighted based on a conflict matrix (CSV) before being aggregated into a final, normalized conflict 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/conflict.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) output = module.get_conflict_index( folder_project=folder, scenario=scenario ) print(" ----- DONE -----")
- pem.conflict.setup_conflict_matrix(folder_project, scenario)[source]#
Initialize a blank lower-triangular conflict matrix CSV for all user activity rasters in a scenario.
- Parameters:
folder_project (str) – Path to the root project directory
scenario (str) – Name of the simulation scenario
- Returns:
Path to the generated conflict matrix CSV
- Return type:
pathlib.Path
Extra notes
This utility scans the scenario directory for raster files and creates a square symmetric-ready CSV. The lower triangle is initialized with
1and the rest with0, serving as a template for users to define conflict weights between activities.Script example
# !WARNING: run this in QGIS Python Environment import importlib.util as iu # define the paths to the module file # ------------------------------------------------------ file = "path/to/conflict.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) output = module.setup_conflict_matrix( folder_project=folder, scenario=scenario ) print(" ----- DONE -----")