Realisation config plumbing, and SW4 station coordinates - #136
Realisation config plumbing, and SW4 station coordinates#136lispandfound wants to merge 2 commits into
Conversation
e02ff56 to
4883702
Compare
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>
4883702 to
ee798c7
Compare
There was a problem hiding this comment.
🟡 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) intoSRFConfig, and split stoch grid sizing into a dedicatedStochConfig. - 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@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? |
Introduces and reverts some changes to allow further refactors. These are looking forward to an SW4 native workflow. The three changes here: