From d56aaeef398c24089ab450982f65c6222ebe0e09 Mon Sep 17 00:00:00 2001 From: ftong Date: Wed, 9 Jul 2025 11:25:55 +0200 Subject: [PATCH 1/5] Update src/seismic_hazard_forecasting.py --- src/seismic_hazard_forecasting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index 2213c35..825e0cd 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -462,7 +462,7 @@ verbose: {verbose}") imls = [dask.delayed(compute_IMT_exceedance)(rx_lat[i], rx_lon[i], distances[i].flatten(), fr, p, lambdas, forecast_len, lambdas_perc, m_range, m_pdf, m_cdf, model, log_level=logging.DEBUG, imt=imt, IMT_min=0.0, IMT_max=2.0, rx_label=i, - rtol=0.1, use_cython=False) for i in iter] + rtol=0.1, use_cython=True) for i in iter] iml = dask.compute(*imls) iml_grid_raw.append(list(iml)) @@ -474,7 +474,7 @@ verbose: {verbose}") for i in iter: iml_i = compute_IMT_exceedance(rx_lat[i], rx_lon[i], distances[i].flatten(), fr, p, lambdas, forecast_len, lambdas_perc, m_range, m_pdf, m_cdf, model, imt=imt, IMT_min = 0.0, - IMT_max = 2.0, rx_label = i, rtol = 0.1, use_cython=False) + IMT_max = 2.0, rx_label = i, rtol = 0.1, use_cython=True) iml.append(iml_i) logger.info(f"Estimated {imt} at rx {i} is {iml_i}") iml_grid_raw.append(iml) From 5b25b93090bfd58472901e7407a2f71fbd99b75b Mon Sep 17 00:00:00 2001 From: ftong Date: Wed, 9 Jul 2025 13:15:04 +0200 Subject: [PATCH 2/5] convert custom activity rate from list to numpy array of type 'double' to satisfy cython input --- src/seismic_hazard_forecasting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index 825e0cd..a5c43ac 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -320,8 +320,8 @@ verbose: {verbose}") lambdas = [None] if custom_rate != None and forecast_select: logger.info(f"Using activity rate specified by user: {custom_rate} per {time_unit}") - lambdas = [custom_rate] - lambdas_perc = [1] + lambdas = np.array([custom_rate], dtype='d') + lambdas_perc = np.array([1], dtype='d') elif rate_select: logger.info(f"Activity rate modeling selected") From dd84829b6d20500728bfb623526154fe039847b8 Mon Sep 17 00:00:00 2001 From: ftong Date: Wed, 9 Jul 2025 13:27:44 +0200 Subject: [PATCH 3/5] define m_max when magnitude distribution estimation is not enabled; take from user's m_file --- src/seismic_hazard_forecasting.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index a5c43ac..6fc5d73 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -81,6 +81,7 @@ def main(catalog_file, mc_file, pdf_file, m_file, m_select, mag_label, mc, m_max m_range = [None] else: m_range = read_mat_m(m_file) + m_max = m_range[-1] # take m_max from the m_file if verbose: logger.setLevel(logging.DEBUG) From 2906af69189d212f108b231d4a99ee4ba387722f Mon Sep 17 00:00:00 2001 From: ftong Date: Wed, 9 Jul 2025 15:09:44 +0200 Subject: [PATCH 4/5] improve error message when user provides magnitude file incompatible with ground motion model --- src/seismic_hazard_forecasting.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index 6fc5d73..100a651 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -378,8 +378,11 @@ verbose: {verbose}") # validate m_max against the grond motion model models_anthro_limited = ['Lasocki2013', 'Atkinson2015', 'ConvertitoEtAl2012Geysers'] # these models require that m_max<=4.5 - if m_max > 4.5 and model in models_anthro_limited: - msg = f"Selected ground motion model {model} is only valid up to a maximum magnitude of 4.5. Please try again with a lower maximum magnitude." + if m_max > 4.5 and model in models_anthro_limited: + if m_file is None: + msg = f"Selected ground motion model {model} is only valid up to a maximum magnitude of 4.5. Please try again with a lower maximum magnitude." + else: + msg = f"Selected ground motion model {model} is only valid up to a maximum magnitude of 4.5. The magnitude file provided has a range up to {m_max}." logger.error(msg) raise Exception(msg) From e06f4a5a056fb56173e54a1538b849d80aeb99b5 Mon Sep 17 00:00:00 2001 From: ftong Date: Wed, 9 Jul 2025 15:23:42 +0200 Subject: [PATCH 5/5] edit error message for clarity --- src/seismic_hazard_forecasting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/seismic_hazard_forecasting.py b/src/seismic_hazard_forecasting.py index 100a651..9761726 100644 --- a/src/seismic_hazard_forecasting.py +++ b/src/seismic_hazard_forecasting.py @@ -380,9 +380,9 @@ verbose: {verbose}") models_anthro_limited = ['Lasocki2013', 'Atkinson2015', 'ConvertitoEtAl2012Geysers'] # these models require that m_max<=4.5 if m_max > 4.5 and model in models_anthro_limited: if m_file is None: - msg = f"Selected ground motion model {model} is only valid up to a maximum magnitude of 4.5. Please try again with a lower maximum magnitude." + msg = f"The selected ground motion model {model} is only valid for magnitudes up to 4.5. Please select a lower maximum magnitude." else: - msg = f"Selected ground motion model {model} is only valid up to a maximum magnitude of 4.5. The magnitude file provided has a range up to {m_max}." + msg = f"The selected ground motion model {model} is only valid for magnitudes up to 4.5, but the provided magnitude file includes values up to {m_max}. Please adjust the magnitude range in the file accordingly." logger.error(msg) raise Exception(msg)