From 8e98cd27cf82377f81e7c2e62bfccead8c825c33 Mon Sep 17 00:00:00 2001 From: bretth Date: Thu, 2 Apr 2026 16:46:20 +0200 Subject: [PATCH 1/5] creating a play based risk assessment test --- tests/test_play_based_risk.py | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/test_play_based_risk.py diff --git a/tests/test_play_based_risk.py b/tests/test_play_based_risk.py new file mode 100644 index 0000000..901a6ac --- /dev/null +++ b/tests/test_play_based_risk.py @@ -0,0 +1,117 @@ +import numpy as np +from matplotlib import pyplot as plt + + +def smooth_logit(x, midpoint=7.5, k=1.5): + return 1 / (1 + np.exp(-k * (x - midpoint))) + + +def test_play_based_risk_single_location(): + # sigmoid functions + temp_midpoint, temp_k = 80, 0.1 + perm_midpoint, perm_k = 250, 0.01 + thick_midpoint, thick_k = 50, 0.01 + ntg_midpoint, ntg_k = 0.5, 10 + + temp_range = (0, 200) + perm_range = (0, 500) + thick_range = (0, 500) + ntg_range = (0, 1) + + + n_samples = 1000 + + temperature = np.random.normal(100, 5, n_samples) + permeability = np.random.normal(300, 50, n_samples) + thickness = np.random.normal(200, 20, n_samples) + ntg = np.random.normal(0.8, 0.1, n_samples) + + # chance of success factors + temperature_cos = smooth_logit(temperature, midpoint=temp_midpoint, k=temp_k) + permeability_cos = smooth_logit(permeability, midpoint=perm_midpoint, k=perm_k) + thickness_cos = smooth_logit(thickness, midpoint=thick_midpoint, k=thick_k) + ntg_cos = smooth_logit(ntg, midpoint=ntg_midpoint, k=ntg_k) + + # combined chance of success + combined_cos = temperature_cos * permeability_cos * thickness_cos * ntg_cos + + # plot Alles + fig, axd = plt.subplot_mosaic( + [ + ["temp", "temp_sig", "temp_cos", "combined"], + ["perm", "perm_sig", "perm_cos", "combined"], + ["thick", "thick_sig", "thick_cos", "combined"], + ["ntg", "ntg_sig", "ntg_cos", "combined"], + ], + figsize=(30, 10), + constrained_layout=True, + ) + + # temperature + axd["temp"].set_title("Temperature samples [C]") + axd["temp"].hist(temperature, bins=20) + + axd["temp_sig"].set_title("Temperature Sigmoid") + axd["temp_sig"].plot( + np.linspace(temp_range[0], temp_range[1]), + smooth_logit( + np.linspace(temp_range[0], temp_range[1]), midpoint=temp_midpoint, k=temp_k + ), + ) + + axd["temp_cos"].set_title("Temperature COS") + axd["temp_cos"].hist(temperature_cos, bins=20) + + # thickness + axd["thick"].set_title("thick samples [m]") + axd["thick"].hist(thickness, bins=20) + + axd["thick_sig"].set_title("Thickness Sigmoid") + axd["thick_sig"].plot( + np.linspace(thick_range[0], thick_range[1]), + smooth_logit( + np.linspace(thick_range[0], thick_range[1]), + midpoint=thick_midpoint, + k=thick_k, + ), + ) + + axd["thick_cos"].set_title("Thickness COS") + axd["thick_cos"].hist(thickness_cos, bins=20) + + # permeability + axd["perm"].set_title("permeability samples [mD]") + axd["perm"].hist(permeability, bins=20) + + axd["perm_sig"].set_title("Permeability Sigmoid") + axd["perm_sig"].plot( + np.linspace(perm_range[0], perm_range[1]), + smooth_logit( + np.linspace(perm_range[0], perm_range[1]), midpoint=perm_midpoint, k=perm_k + ), + ) + + axd["perm_cos"].set_title("Permeability COS") + axd["perm_cos"].hist(permeability_cos, bins=20) + + # ntg + + axd["ntg"].set_title("ntg samples [0-1]") + axd["ntg"].hist(ntg, bins=20) + + axd["ntg_sig"].set_title("ntg Sigmoid") + axd["ntg_sig"].plot( + np.linspace(ntg_range[0], ntg_range[1]), + smooth_logit( + np.linspace(ntg_range[0], ntg_range[1]), midpoint=ntg_midpoint, k=ntg_k + ), + ) + + axd["ntg_cos"].set_title("ntg COS") + axd["ntg_cos"].hist(ntg_cos, bins=20) + + # combined cos + axd["combined"].set_title("Combined COS") + axd["combined"].hist(combined_cos, bins=20) + + plt.show() -- GitLab From c261621a65799c8d228161b0b2815a9373aa1e84 Mon Sep 17 00:00:00 2001 From: bretth Date: Thu, 2 Apr 2026 16:47:05 +0200 Subject: [PATCH 2/5] updating gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e385dce..c41961e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ dist tests/resources/test_output -/pythermogis/resources/JVM17 +src/pythermogis/jvm **/test_output/** \ No newline at end of file -- GitLab From 3a61db4f1620ef9e52b149ebdd492d0acb7d5f26 Mon Sep 17 00:00:00 2001 From: bretth Date: Thu, 2 Apr 2026 17:01:43 +0200 Subject: [PATCH 3/5] adding a chance of success test with maps --- tests/test_play_based_risk.py | 56 ++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/test_play_based_risk.py b/tests/test_play_based_risk.py index 901a6ac..156c787 100644 --- a/tests/test_play_based_risk.py +++ b/tests/test_play_based_risk.py @@ -1,24 +1,30 @@ +from pathlib import Path + import numpy as np from matplotlib import pyplot as plt +from pygridsio import read_grid, plot_grid +from tqdm import tqdm +import copy + +test_files_path = Path(__file__).parent / "resources" +test_input = test_files_path / "test_input" / "example_data" +# sigmoid functions +temp_midpoint, temp_k = 80, 0.1 +perm_midpoint, perm_k = 250, 0.01 +thick_midpoint, thick_k = 50, 0.01 +ntg_midpoint, ntg_k = 0.5, 10 def smooth_logit(x, midpoint=7.5, k=1.5): return 1 / (1 + np.exp(-k * (x - midpoint))) - def test_play_based_risk_single_location(): - # sigmoid functions - temp_midpoint, temp_k = 80, 0.1 - perm_midpoint, perm_k = 250, 0.01 - thick_midpoint, thick_k = 50, 0.01 - ntg_midpoint, ntg_k = 0.5, 10 temp_range = (0, 200) perm_range = (0, 500) thick_range = (0, 500) ntg_range = (0, 1) - n_samples = 1000 temperature = np.random.normal(100, 5, n_samples) @@ -115,3 +121,39 @@ def test_play_based_risk_single_location(): axd["combined"].hist(combined_cos, bins=20) plt.show() + +def test_cos_grid(): + aquifer = "ROSL_ROSLU" + ntg = read_grid(test_input / f"{aquifer}__ntg.zmap") + ln_perm = np.log(read_grid(test_input / f"{aquifer}__perm.zmap")) + ln_perm_sd = read_grid(test_input / f"{aquifer}__ln_perm_sd.zmap") + top = read_grid(test_input / f"{aquifer}__top.zmap") + thick = read_grid(test_input / f"{aquifer}__thick.zmap") + thick_sd = read_grid(test_input / f"{aquifer}__thick_sd.zmap") + + n_samples = 10 + + cos_grids = [] + cos_mean_grid = copy.deepcopy(ntg) + cos_sd_grid = copy.deepcopy(ntg) + for _ in tqdm(range(n_samples)): + ntg_sample = np.random.normal(ntg.data, 0.1) + perm_sample = np.exp(np.random.normal(ln_perm.data, ln_perm_sd.data)) + top_sample = np.random.normal(top.data, thick_sd.data) + temp_sample = 8 + 0.032 * top_sample + thick_sample = np.random.normal(thick.data, thick_sd.data) + + temp_sig = smooth_logit(temp_sample, midpoint=temp_midpoint, k=temp_k) + thick_sig = smooth_logit(thick_sample, midpoint=thick_midpoint, k=thick_k) + perm_sig = smooth_logit(perm_sample, midpoint=perm_midpoint, k=perm_k) + ntg_sig = smooth_logit(ntg_sample, midpoint=ntg_midpoint, k=ntg_k) + + cos_sample = temp_sig * thick_sig * perm_sig * ntg_sig + cos_grids.append(copy.deepcopy(cos_sample)) + + # plot the mean and SD COS grid + cos_mean_grid.data = np.mean(cos_grids, axis=0) + cos_sd_grid.data = np.std(cos_grids, axis=0) + + plot_grid(cos_mean_grid, add_netherlands_shapefile=True, show=True) + plot_grid(cos_sd_grid, add_netherlands_shapefile=True, show=True) \ No newline at end of file -- GitLab From 8980311ced5fd842ae5a81ffb2622a4c04c5fc0e Mon Sep 17 00:00:00 2001 From: bretth Date: Thu, 2 Apr 2026 17:09:18 +0200 Subject: [PATCH 4/5] adding a chance of success test with maps --- tests/test_play_based_risk.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_play_based_risk.py b/tests/test_play_based_risk.py index 156c787..25ae220 100644 --- a/tests/test_play_based_risk.py +++ b/tests/test_play_based_risk.py @@ -69,7 +69,7 @@ def test_play_based_risk_single_location(): axd["temp_cos"].hist(temperature_cos, bins=20) # thickness - axd["thick"].set_title("thick samples [m]") + axd["thick"].set_title("Thickness samples [m]") axd["thick"].hist(thickness, bins=20) axd["thick_sig"].set_title("Thickness Sigmoid") @@ -86,7 +86,7 @@ def test_play_based_risk_single_location(): axd["thick_cos"].hist(thickness_cos, bins=20) # permeability - axd["perm"].set_title("permeability samples [mD]") + axd["perm"].set_title("Permeability samples [mD]") axd["perm"].hist(permeability, bins=20) axd["perm_sig"].set_title("Permeability Sigmoid") @@ -102,10 +102,10 @@ def test_play_based_risk_single_location(): # ntg - axd["ntg"].set_title("ntg samples [0-1]") + axd["ntg"].set_title("NTG samples [0-1]") axd["ntg"].hist(ntg, bins=20) - axd["ntg_sig"].set_title("ntg Sigmoid") + axd["ntg_sig"].set_title("NTG Sigmoid") axd["ntg_sig"].plot( np.linspace(ntg_range[0], ntg_range[1]), smooth_logit( @@ -113,7 +113,7 @@ def test_play_based_risk_single_location(): ), ) - axd["ntg_cos"].set_title("ntg COS") + axd["ntg_cos"].set_title("NTG COS") axd["ntg_cos"].hist(ntg_cos, bins=20) # combined cos @@ -131,7 +131,7 @@ def test_cos_grid(): thick = read_grid(test_input / f"{aquifer}__thick.zmap") thick_sd = read_grid(test_input / f"{aquifer}__thick_sd.zmap") - n_samples = 10 + n_samples = 1000 cos_grids = [] cos_mean_grid = copy.deepcopy(ntg) @@ -155,5 +155,12 @@ def test_cos_grid(): cos_mean_grid.data = np.mean(cos_grids, axis=0) cos_sd_grid.data = np.std(cos_grids, axis=0) - plot_grid(cos_mean_grid, add_netherlands_shapefile=True, show=True) - plot_grid(cos_sd_grid, add_netherlands_shapefile=True, show=True) \ No newline at end of file + fig, ax = plt.subplots(nrows=1, ncols = 2, figsize=(20, 10)) + + plot_grid(cos_mean_grid, axes=ax[0], add_netherlands_shapefile=True) + plot_grid(cos_sd_grid, axes=ax[1], add_netherlands_shapefile=True) + + ax[0].set_title("Mean COS") + ax[1].set_title("SD COS") + + plt.show() \ No newline at end of file -- GitLab From d19877e1cf15fdf3f3466836bcfa8735954657ad Mon Sep 17 00:00:00 2001 From: bretth Date: Fri, 3 Apr 2026 09:11:35 +0200 Subject: [PATCH 5/5] adding a chance of success test with maps --- tests/test_play_based_risk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_play_based_risk.py b/tests/test_play_based_risk.py index 25ae220..cd90a4d 100644 --- a/tests/test_play_based_risk.py +++ b/tests/test_play_based_risk.py @@ -12,7 +12,7 @@ test_input = test_files_path / "test_input" / "example_data" # sigmoid functions temp_midpoint, temp_k = 80, 0.1 perm_midpoint, perm_k = 250, 0.01 -thick_midpoint, thick_k = 50, 0.01 +thick_midpoint, thick_k = 50, 0.1 ntg_midpoint, ntg_k = 0.5, 10 def smooth_logit(x, midpoint=7.5, k=1.5): -- GitLab