From e579718d2f96a1666ec421fe486e92656a9f91a0 Mon Sep 17 00:00:00 2001 From: Mattia Amadio <44863827+matamadio@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:42:51 +0200 Subject: [PATCH] fix bug, add env --- Top-down/parallelization/.env | 10 ++++++++++ Top-down/parallelization/README.md | 9 +++++++++ Top-down/parallelization/main.py | 2 +- Top-down/parallelization/runAnalysis.py | 3 --- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 Top-down/parallelization/.env diff --git a/Top-down/parallelization/.env b/Top-down/parallelization/.env new file mode 100644 index 00000000..ed4c26df --- /dev/null +++ b/Top-down/parallelization/.env @@ -0,0 +1,10 @@ +# Environment variables for the CCDR Hazard analysis notebooks + +# Specify working directory, location of data files +# Use absolute paths, and keep the trailing slash +DATA_DIR = C:/Work/data + +# Location to store downloaded rasters and other data +# for the analysis notebooks +CACHE_DIR = ${DATA_DIR}/cache +OUTPUT_DIR = ${DATA_DIR}/output \ No newline at end of file diff --git a/Top-down/parallelization/README.md b/Top-down/parallelization/README.md index c96d744b..2372ba39 100644 --- a/Top-down/parallelization/README.md +++ b/Top-down/parallelization/README.md @@ -102,3 +102,12 @@ Example of `main.py` running flood analysis (`haz_cat`) over Cambodia (`country` class_edges = [0.05, 0.25, 0.50, 1.00, 2.00] save_check_raster = False ``` + +## Running the analysis + +```bash +$ python main.py +``` + +The analysis runs on all selected exposed categories, in sequence. Depending on the number of cores, the size and resolution of the data, and power of CPU, the analysis can take from less than a minute to few minutes. +E.g. for Bangladesh on a i9-12900KF (16 cores), 64 Gb RAM: below 100 seconds. diff --git a/Top-down/parallelization/main.py b/Top-down/parallelization/main.py index d61bf240..b22cb011 100644 --- a/Top-down/parallelization/main.py +++ b/Top-down/parallelization/main.py @@ -11,7 +11,7 @@ def main(): haz_cat = 'FL' #'FL' for floods; 'HS' for heat stress; 'DR' for drought; 'LS' for landslide return_periods = [5, 10, 20, 50, 75, 100, 200, 250, 500, 1000] # FL [5, 10, 20, 50, 75, 100, 200, 250, 500, 1000] # TC [10, 20, 50, 100, 200, 500] # add here as will min_haz_slider = 0.05 # FL 0.05 # TC 25.0 # ASI 0.01 - exp_cat_list = ['pop', 'BU', 'AGR'] # ['pop', 'builtup', 'agri'] + exp_cat_list = ['POP', 'BU', 'AGR'] # ['POP', 'BU', 'AGR'] exp_nam_list = ['POP', 'BU', 'AGR'] # if None, the default applies: 'Population':'POP', 'Built-up':'BU', 'Agricultural land':'AGR' - If not None, expect a list of same length of exp_cat_list adm = 'ADM3' #['ADM1', 'ADM2', 'ADM3'] analysis_app = 'Function' #['Classes', 'Function'] diff --git a/Top-down/parallelization/runAnalysis.py b/Top-down/parallelization/runAnalysis.py index 5bd8ff12..08a80a64 100644 --- a/Top-down/parallelization/runAnalysis.py +++ b/Top-down/parallelization/runAnalysis.py @@ -67,9 +67,6 @@ def run_analysis(country: str, haz_cat: str, valid_RPs: list[int], bin_seq = class_edges + [np.inf] num_bins = len(bin_seq) - # Testing data file locations - # TODO: Temp data store, to be replaced with a config spec (.env file?) before deployment - # Checking which kind of exposed category is being considered... # If the exposed category is population... if exp_cat == 'POP':