Skip to content

Realisation config plumbing, and SW4 station coordinates - #136

Open
lispandfound wants to merge 2 commits into
pegasusfrom
nzvm/config-plumbing
Open

Realisation config plumbing, and SW4 station coordinates#136
lispandfound wants to merge 2 commits into
pegasusfrom
nzvm/config-plumbing

Conversation

@lispandfound

@lispandfound lispandfound commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Introduces and reverts some changes to allow further refactors. These are looking forward to an SW4 native workflow. The three changes here:

  1. Reinstating separate dt values for SRFs, high frequency and low frequency portions of the workflow. The original intentions of merging them was to remove the possibility of uncoupled it changes (SRF dt changed without lf dt). However, SW4 has dynamic time resolution and actually we often want a lower dt in HF anyway for size, efficiency concerns.
  2. SRF to SW4 utility. Very small, used to drive SW4 sources.
  3. Stations can now optionally be output in SW4 format. I've introduced the concept of a solver/format to a number of places in the workflow for flexible use with EMOD3D and SW4. This is just the first.

@lispandfound lispandfound changed the title nzvm/config plumbing Realisation config plumbing, and SW4 station coordinates Aug 31, 2026
Groups the behaviour-neutral housekeeping that later layers of this
stack depend on, so it can be reviewed in one pass:

- `realisations.path_serialiser`, wired into `write_to_realisation` and
  `migrate.print_diff`. Later config sections carry `Path` values, which
  `json` cannot serialise natively.
- `nshm2022_to_realisation` opens the NSHMDB inside a `with` block, as
  nshmdb 2026.08.3 requires. Bumps the floor accordingly.
- `srf-to-hdf5`, a thin wrapper over `srf.write_sw4_hdf5`.
- `dt` moves from `Resolution` onto `SRFConfig`. The SRF timestep is a
  property of the SRF discretisation, not of the simulation grid, and
  `realisation-to-srf` no longer reads `Resolution` at all. It is skipped
  when building the genslip command line, which takes `dt` explicitly.
- `stoch_dx`/`stoch_dy` move out of `HFConfig` into a new `StochConfig`.
  They size the stoch grid, which is an *input* to the high-frequency
  simulation rather than one of its parameters.
- `generate-station-coordinates` gains a `--format` flag. The EMOD3D
  path is unchanged, only lifted out of the command body into
  `write_emod3d_station_format` so a second writer can sit beside it,
  with the shared `.ll` list factored into
  `write_ascii_station_locations`. The SW4 writer emits the HDF5 station
  file `rechdf5` expects: one group per station holding an
  `STLA,STLO,STDP` triple.

Stations outside the domain are dropped by the SW4 writer rather than
clamped, because unlike EMOD3D's grid-point files there is no nearest
gridpoint to snap them to -- a station SW4 cannot place is not a
recording. The containment test is done in NZTM against the domain
polygon, matching how the domain itself is defined.

`h5py` becomes a declared dependency here: this is the first place
workflow code imports it directly rather than relying on it arriving
through `xarray[io]`.

No change to any computed result: the genslip command line and the
srf2stoch invocation are byte-identical to before, as is the EMOD3D
station output.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lispandfound
lispandfound marked this pull request as ready for review September 2, 2026 20:28
Copilot AI lite review requested due to automatic review settings September 2, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are correctness/backwards-compatibility issues in the new JSON Path serializer and the new required srf.dt schema that can break existing realisations at runtime.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR extends the workflow’s configuration plumbing and I/O utilities to better support an SW4-native workflow, including splitting SRF timestep from other workflow timesteps and adding SW4-compatible outputs.

Changes:

  • Add SRF→SW4 SRF-HDF5 conversion stage and CLI entrypoint (srf-to-hdf5).
  • Move SRF timestep (dt) into SRFConfig, and split stoch grid sizing into a dedicated StochConfig.
  • Add optional SW4 station output (HDF5) alongside existing EMOD3D station outputs.
File summaries
File Description
workflow/scripts/srf_to_hdf5.py New CLI wrapper to write SW4 SRF-HDF5 sources from SRF input.
workflow/scripts/realisation_to_srf.py Switch SRF generation to use srf_config.dt/srf_config.resolution rather than Resolution.
workflow/scripts/nshm2022_to_realisation.py Use with db: context management for NSHM DB access.
workflow/scripts/migrate.py Use JSON default= to print diffs when configs contain Path values.
workflow/scripts/generate_stoch.py Read stoch grid sizing from new StochConfig.
workflow/scripts/generate_station_coordinates.py Introduce solver Format and add SW4 station HDF5 output option.
workflow/schemas.py Add srf.dt and introduce STOCH_CONFIG_SCHEMA.
workflow/realisations.py Add SRFConfig.dt, add StochConfig, and add a JSON Path serializer hook.
workflow/default_parameters/root/defaults.yaml Add defaults for srf.dt and new top-level stoch block.
uv.lock Add h5py to locked dependencies.
tests/test_realisation.py Update SRF config example to include dt.
tests/test_realisation_to_srf.py Update SRF config construction to include dt.
tests/test_hf.py Remove stoch dx/dy from HF test setup (now in StochConfig).
pyproject.toml Add h5py dependency and register srf-to-hdf5 script entrypoint.
Review details
  • Files reviewed: 13/14 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread workflow/realisations.py
Comment thread workflow/schemas.py
Comment thread workflow/scripts/generate_station_coordinates.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@claudio525

Copy link
Copy Markdown
Contributor

@lispandfound Thoughts on adding the claude-review action to this PR (or a separate one), so it can be used to reviewing this large stack of PRs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants