From aa8bd2eff115552d0ede93cfa0933232e0ea7d87 Mon Sep 17 00:00:00 2001 From: Jake Faulkner Date: Wed, 17 Dec 2025 13:34:08 +1300 Subject: [PATCH 1/2] refactor(generate-velocity-model-parameters): Expose `generate_velocity_model_parameters` so that you do not have to write to realisation --- .../generate_velocity_model_parameters.py | 125 +++++++++++++----- 1 file changed, 93 insertions(+), 32 deletions(-) diff --git a/workflow/scripts/generate_velocity_model_parameters.py b/workflow/scripts/generate_velocity_model_parameters.py index 790240f..6e4504e 100644 --- a/workflow/scripts/generate_velocity_model_parameters.py +++ b/workflow/scripts/generate_velocity_model_parameters.py @@ -426,45 +426,57 @@ def pgv_target( ) -@cli.from_docstring(app) -@log_utils.log_call() def generate_velocity_model_parameters( - realisation_ffp: Annotated[Path, typer.Argument()], -) -> None: - """Generate velocity model parameters for a given realisation file. - - This function reads the source and rupture propagation information and computes: - - 1. The size of the simulation domain, - 2. The simulation duration. - - Both of these values are written to the realisation using `VelocityModelParameters`. + source_config: SourceConfig, + velocity_model_parameters: VelocityModelParameters, + rupture_propagation: RupturePropagationConfig, + rakes: Rakes, + magnitudes: Magnitudes, +) -> DomainParameters: + """Generate model domain extents, maximum depth, and simulation duration for a realisation. Parameters ---------- - realisation_ffp : Path - The path to the realisation file from which to read configurations and to which - the generated velocity model parameters will be written. + source_config : SourceConfig + Source configuration containing a mapping of fault/source geometries. + velocity_model_parameters : VelocityModelParameters + Velocity-model configuration and controls. Used to compute + the PGV target for rrup bounding polygons. + rupture_propagation : RupturePropagationConfig + Rupture propagation settings. + rakes : Rakes + Mapping of fault identifiers to rake angles (degrees). Used in + the GMPE that estimates domain parameters. + magnitudes : Magnitudes + Mapping of fault identifiers to magnitudes (Mw). Used to compute the + total rupture magnitude and rrup bounding polygons. Returns ------- - None - The function does not return any value. It writes the computed parameters to - the specified realisation file. + DomainParameters + The domain geometry for simulation. + + See Also + -------- + total_magnitude + pgv_target + get_max_depth + find_rrup_bounding_polygon + bounding_box.minimum_area_bounding_box_for_polygons_masked + estimate_simulation_duration + + Notes + ----- + - Fault polygons are buffered by 2,000 meters and must be fully included + in the final domain. + - Rrup bounding polygons represent areas within rupture distance of any + source-geometry corner; they may be included when they overlap land. + - The domain computation is masked by the New Zealand outline `utils.get_nz_outline_polygon`, + ensuring only land areas are considered for optional inclusion. + - Depth is computed from the total rupture magnitude and the initial fault's + bottom depth. """ - metadata = RealisationMetadata.read_from_realisation(realisation_ffp) - source_config = SourceConfig.read_from_realisation(realisation_ffp) - velocity_model_parameters = ( - VelocityModelParameters.read_from_realisation_or_defaults( - realisation_ffp, metadata.defaults_version - ) - ) - rupture_propagation = RupturePropagationConfig.read_from_realisation( - realisation_ffp - ) - magnitudes = Magnitudes.read_from_realisation(realisation_ffp) - rakes = Rakes.read_from_realisation(realisation_ffp) rupture_magnitude = total_magnitude(np.array(list(magnitudes.magnitudes.values()))) realisation_pgv_target = pgv_target(magnitudes, velocity_model_parameters) @@ -483,7 +495,6 @@ def generate_velocity_model_parameters( shapely.buffer(fault.geometry, 2000) for fault in source_config.source_geometries.values() ] - rakes = Rakes.read_from_realisation(realisation_ffp) # This polygon includes all areas within rrup distance of any # corner in the source geometries. # These may be in the domain where they are over land. @@ -516,10 +527,60 @@ def generate_velocity_model_parameters( velocity_model_parameters.s_wave_velocity, ) - domain_parameters = DomainParameters( + return DomainParameters( domain=model_domain, depth=max_depth, duration=sim_duration, ) + + +@cli.from_docstring(app) +@log_utils.log_call() +def main( + realisation_ffp: Annotated[Path, typer.Argument()], +) -> None: + """Generate velocity model parameters for a given realisation file. + + This function reads the source and rupture propagation information and computes: + + 1. The size of the simulation domain, + 2. The simulation duration. + + Both of these values are written to the realisation using `VelocityModelParameters`. + + Parameters + ---------- + realisation_ffp : Path + The path to the realisation file from which to read configurations and to which + the generated velocity model parameters will be written. + + Returns + ------- + None + The function does not return any value. It writes the computed parameters to + the specified realisation file. + """ + metadata = RealisationMetadata.read_from_realisation(realisation_ffp) + source_config = SourceConfig.read_from_realisation(realisation_ffp) + velocity_model_parameters = ( + VelocityModelParameters.read_from_realisation_or_defaults( + realisation_ffp, metadata.defaults_version + ) + ) + + rupture_propagation = RupturePropagationConfig.read_from_realisation( + realisation_ffp + ) + magnitudes = Magnitudes.read_from_realisation(realisation_ffp) + rakes = Rakes.read_from_realisation(realisation_ffp) + + domain_parameters = generate_velocity_model_parameters( + source_config=source_config, + velocity_model_parameters=velocity_model_parameters, + rupture_propagation=rupture_propagation, + magnitudes=magnitudes, + rakes=rakes, + ) + domain_parameters.write_to_realisation(realisation_ffp) realisations.append_log_entry(realisation_ffp) From 0b5b8520cfa710870bc8fb7969a6cad01abecc47 Mon Sep 17 00:00:00 2001 From: Jake Faulkner Date: Wed, 17 Dec 2025 13:45:02 +1300 Subject: [PATCH 2/2] docs(generate-velocity-model-parameters): correct docstring Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- workflow/scripts/generate_velocity_model_parameters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/scripts/generate_velocity_model_parameters.py b/workflow/scripts/generate_velocity_model_parameters.py index 6e4504e..175984c 100644 --- a/workflow/scripts/generate_velocity_model_parameters.py +++ b/workflow/scripts/generate_velocity_model_parameters.py @@ -546,7 +546,7 @@ def main( 1. The size of the simulation domain, 2. The simulation duration. - Both of these values are written to the realisation using `VelocityModelParameters`. + Both of these values are written to the realisation using `DomainParameters`. Parameters ----------