From 723c133638064a0559b38b8f9721d17a18c94f69 Mon Sep 17 00:00:00 2001 From: Andrew Ridden-Harper Date: Tue, 1 Sep 2026 22:35:14 +1200 Subject: [PATCH 1/5] Support nshmdb's fault_system-scoped rupture/fault lookups nshmdb 2026.8.x merges Hikurangi/Puysegur/Crustal into one rupture_id space and requires fault_system alongside the NSHM id for get_rupture_faults/get_rupture_fault_info (NSHM2022DB PR pending -- see fix-fault-system-scoping-in-rupture-fault-lookups), and a 3rd positional arg on most_likely_fault. generate_realisation gains an optional fault_system option, defaulting to Crustal (this project's only fault system so far), threaded through all three call sites. Also calls db.connect() explicitly -- NSHMDB.connection() now raises unless the connection was opened via connect()/__enter__ first; the old package connected implicitly. Verified end-to-end against nshmdb_v2026.08.3.db (rupture 3): faults grouped and named correctly, rakes preserved. Co-Authored-By: Claude Sonnet 5 --- workflow/scripts/nshm2022_to_realisation.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/workflow/scripts/nshm2022_to_realisation.py b/workflow/scripts/nshm2022_to_realisation.py index 345f04d8..5ff09234 100755 --- a/workflow/scripts/nshm2022_to_realisation.py +++ b/workflow/scripts/nshm2022_to_realisation.py @@ -45,6 +45,7 @@ from scipy.cluster.hierarchy import DisjointSet from nshmdb import nshmdb +from nshmdb.nshmdb import FaultSystem from qcore import cli from qcore.uncertainties import distributions from source_modelling import magnitude_scaling, moment, rupture_propagation, sources @@ -187,6 +188,7 @@ def generate_realisation( DefaultsVersion, typer.Argument(), ], + fault_system: Annotated[FaultSystem, typer.Option()] = FaultSystem.Crustal, initial_fault: Annotated[ str | None, typer.Option(), @@ -252,6 +254,11 @@ def generate_realisation( Location to write out the realisation. defaults_version : DefaultsVersion Scientific default parameters version to use. + fault_system : FaultSystem, optional + The NSHM fault system rupture_id belongs to. Defaults to Crustal, + the only fault system this project has ever used -- rupture_id + is an NSHM id (nshmdb.nshmdb.FaultSystem), unique only within one + fault system, not a raw database primary key. initial_fault : str, optional The name of the fault to use as the initial fault for rupture propagation. If not specified, the initial fault will be drawn @@ -311,7 +318,8 @@ def generate_realisation( realisation_ffp, defaults_version ) db = nshmdb.NSHMDB(nshmdb_path) - faults = db.get_rupture_faults(rupture_id) + db.connect() + faults = db.get_rupture_faults(fault_system, rupture_id) faults = { fault_name: sources.simplify_fault(fault, srf_config.resolution) for fault_name, fault in faults.items() @@ -322,7 +330,7 @@ def generate_realisation( f"Initial fault '{initial_fault}' not found in rupture. Options are {', '.join(list(faults))}" ) raise typer.Exit(code=1) - faults_info = db.get_rupture_fault_info(rupture_id) + faults_info = db.get_rupture_fault_info(fault_system, rupture_id) seeds = Seeds.read_from_realisation_or_random(realisation_ffp) np.random.seed(seed=seeds.nshm_to_realisation_seed) random.seed(seeds.nshm_to_realisation_seed) @@ -354,7 +362,7 @@ def generate_realisation( else: # The ty ignore below can be removed once NSHM2022DB merges the change to # accept dict[str, BoldM] in most_likely_fault (branch support-BoldM-in-workflow). - mfds_rates = db.most_likely_fault(rupture_id, magnitudes) # ty: ignore[invalid-argument-type] + mfds_rates = db.most_likely_fault(fault_system, rupture_id, magnitudes) # ty: ignore[invalid-argument-type] mfds_probabilities = np.array(list(mfds_rates.values())) if np.allclose(mfds_probabilities, 0): mfds_probabilities = np.ones_like(mfds_probabilities) From 8a9cf0ce3a35a79706751194919ef3dd89b59d8c Mon Sep 17 00:00:00 2001 From: Andrew Ridden-Harper Date: Tue, 1 Sep 2026 23:03:13 +1200 Subject: [PATCH 2/5] Trim fault_system docstring wording Co-Authored-By: Claude Sonnet 5 --- workflow/scripts/nshm2022_to_realisation.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/workflow/scripts/nshm2022_to_realisation.py b/workflow/scripts/nshm2022_to_realisation.py index 5ff09234..3961e79e 100755 --- a/workflow/scripts/nshm2022_to_realisation.py +++ b/workflow/scripts/nshm2022_to_realisation.py @@ -255,10 +255,9 @@ def generate_realisation( defaults_version : DefaultsVersion Scientific default parameters version to use. fault_system : FaultSystem, optional - The NSHM fault system rupture_id belongs to. Defaults to Crustal, - the only fault system this project has ever used -- rupture_id - is an NSHM id (nshmdb.nshmdb.FaultSystem), unique only within one - fault system, not a raw database primary key. + The NSHM fault system rupture_id belongs to. Defaults to Crustal. + rupture_id is an NSHM id (nshmdb.nshmdb.FaultSystem), unique only + within one fault system, not a raw database primary key. initial_fault : str, optional The name of the fault to use as the initial fault for rupture propagation. If not specified, the initial fault will be drawn From eb001621b7e4bc6175f44d296ec070cefecda30c Mon Sep 17 00:00:00 2001 From: Andrew Ridden-Harper Date: Tue, 1 Sep 2026 23:05:26 +1200 Subject: [PATCH 3/5] Drop misplaced FaultSystem reference from fault_system docstring The parenthetical sat after "NSHM id", reading as if the id were a FaultSystem. The id is a plain int; FaultSystem is already the declared type of the parameter itself. Co-Authored-By: Claude Sonnet 5 --- workflow/scripts/nshm2022_to_realisation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/scripts/nshm2022_to_realisation.py b/workflow/scripts/nshm2022_to_realisation.py index 3961e79e..489a5270 100755 --- a/workflow/scripts/nshm2022_to_realisation.py +++ b/workflow/scripts/nshm2022_to_realisation.py @@ -256,8 +256,8 @@ def generate_realisation( Scientific default parameters version to use. fault_system : FaultSystem, optional The NSHM fault system rupture_id belongs to. Defaults to Crustal. - rupture_id is an NSHM id (nshmdb.nshmdb.FaultSystem), unique only - within one fault system, not a raw database primary key. + rupture_id is an NSHM id, unique only within one fault system, not + a raw database primary key. initial_fault : str, optional The name of the fault to use as the initial fault for rupture propagation. If not specified, the initial fault will be drawn From 4f1e5488e9f63c20deeca9bd5cc628b3170c051f Mon Sep 17 00:00:00 2001 From: Andrew Ridden-Harper Date: Tue, 1 Sep 2026 23:11:12 +1200 Subject: [PATCH 4/5] Drop "raw" from fault_system docstring Co-Authored-By: Claude Sonnet 5 --- workflow/scripts/nshm2022_to_realisation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/scripts/nshm2022_to_realisation.py b/workflow/scripts/nshm2022_to_realisation.py index 489a5270..49b756b0 100755 --- a/workflow/scripts/nshm2022_to_realisation.py +++ b/workflow/scripts/nshm2022_to_realisation.py @@ -257,7 +257,7 @@ def generate_realisation( fault_system : FaultSystem, optional The NSHM fault system rupture_id belongs to. Defaults to Crustal. rupture_id is an NSHM id, unique only within one fault system, not - a raw database primary key. + a database primary key. initial_fault : str, optional The name of the fault to use as the initial fault for rupture propagation. If not specified, the initial fault will be drawn From 5c46c722439bdca9dae9239d63c7cfec306cbff7 Mon Sep 17 00:00:00 2001 From: Andrew Ridden-Harper Date: Wed, 2 Sep 2026 12:31:22 +1200 Subject: [PATCH 5/5] bump NSHM2022DB version to 2026.09.1 --- pyproject.toml | 2 +- uv.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index db3da6e0..4f8a013c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ # UCGMSim Dependencies "im-calculation>=2025.12.5", "velocity-modelling>=2026.2.1", - "nshmdb>=2025.12.1", + "nshmdb>=2026.09.1", "oq_wrapper>=2025.12.3", "qcore-utils>=2025.12.2", "source_modelling>=2026.08.1", diff --git a/uv.lock b/uv.lock index af7694cb..e1bae7b4 100644 --- a/uv.lock +++ b/uv.lock @@ -1731,7 +1731,7 @@ wheels = [ [[package]] name = "nshmdb" -version = "2026.8.3" +version = "2026.9.1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "duckdb" }, @@ -1746,9 +1746,9 @@ dependencies = [ { name = "source-modelling" }, { name = "typer" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/30/0c/dbcac49e61d6a4e8f0dd460d3dab376c3978a79f003294e7b47d8b153c11/nshmdb-2026.8.3.tar.gz", hash = "sha256:0fb515ba8c6c8410084a14632faa9339a90082f90d60c6cecd7dfb33adf582f9", size = 200264, upload-time = "2026-08-20T04:34:39.836Z" } +sdist = { url = "https://files.pythonhosted.org/packages/66/5b/e6ea2fd119b58a2b1aa3a4616de0ee34356ac62dece7887398f6f7603260/nshmdb-2026.9.1.tar.gz", hash = "sha256:c89ed5c351d71000a0486515d9c0ffe94083a41b299a566119e44b20d1c3ca6b", size = 200270, upload-time = "2026-09-02T00:28:32.238Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/a6/19/0636161438be7f33ef107f475470981831d303fae2ecd33a20101cffbd7b/nshmdb-2026.8.3-py3-none-any.whl", hash = "sha256:f919ecffe74de270534e3c42455de2ce89f8826f48bf27c3dd33ca91821d8a8d", size = 20998, upload-time = "2026-08-20T04:34:38.378Z" }, + { url = "https://files.pythonhosted.org/packages/d0/3c/da88ebde8c67962ced54ca49f9c66ae6cd059b58418051d79a1b9fab4cdc/nshmdb-2026.9.1-py3-none-any.whl", hash = "sha256:afb2055836fb89eb6ded94daf6c618cba9777d628cf85e289d46242da3d6dea0", size = 20998, upload-time = "2026-09-02T00:28:30.803Z" }, ] [[package]] @@ -3517,7 +3517,7 @@ requires-dist = [ { name = "geopandas" }, { name = "hypothesis", extras = ["numpy"], marker = "extra == 'test'", specifier = ">=6.0.0" }, { name = "im-calculation", specifier = ">=2025.12.5" }, - { name = "nshmdb", specifier = ">=2025.12.1" }, + { name = "nshmdb", specifier = ">=2026.9.1" }, { name = "numpy" }, { name = "numpydoc", marker = "extra == 'dev'" }, { name = "oq-wrapper", specifier = ">=2025.12.3" },