Add validate-sfile, a checker for SW4 velocity models - #137
Open
lispandfound wants to merge 6 commits into
Open
Conversation
lispandfound
force-pushed
the
nzvm/sfile-validator
branch
from
September 2, 2026 02:23
b01c0eb to
5664a7d
Compare
lispandfound
force-pushed
the
nzvm/sfile-validator
branch
3 times, most recently
from
September 8, 2026 22:56
5bb11e3 to
9d5f569
Compare
Contributor
Author
|
@claude review |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
Author
|
@claude review |
|
Claude finished @lispandfound's task in 2m 35s —— View job Review complete
Findings: 2 (High: 2, Medium: 0, Low: 0)
|
An sfile that SW4 accepts at load time can still crash it thousands of
steps in, or -- worse -- run to completion having quietly solved the
wrong problem. The failures that cost the most time are all detectable
up front from the file alone:
Structure required groups/attributes, dataset counts match ngrids
Attributes types, value ranges, NaN/Inf
Z_interfaces strict monotonicity at every (i, j), zero/negative
thickness layers (which trigger an hv=0 division in
SW4), large topographic gradients, agreement between the
Min/max depth attribute and the data
Material Rho > 0 (zero density is the most common SW4 crash),
Cp > 0, Cs >= 0, Qp/Qs > 0 under attenuation, Vp/Vs >= 1,
nk >= 2 (nk=1 gives 0*inf=NaN in SW4's interpolation)
Boundaries grid corners in geographic coordinates
Interfaces stored at different resolutions are nearest-resampled onto a
common grid rather than skipped, because crossed and pinched layers
cluster at exactly the grid-refinement boundaries where the resolutions
differ. Nearest, not bilinear: it preserves every stored node value, so
a crossing sitting on a single coarse node is never smoothed away.
Material datasets are scanned in row chunks -- they do not fit in
memory for any real domain.
Standalone: imports nothing from `workflow`, and exits non-zero if any
check reports an error, so it can gate a run.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lispandfound
force-pushed
the
nzvm/sfile-validator
branch
from
September 9, 2026 00:09
9d5f569 to
26a0b4a
Compare
Contributor
Author
|
@claude review |
|
Claude finished @lispandfound's task in 2m 18s —— View job Review complete
The file has been substantially rewritten since the last review (798 → 1668 lines). Both previously flagged issues are resolved:
New findings: 1 (High: 1)
Posted as an inline comment with a suggested fix. |
The tests hand read_sfile a synthetic tree -- a dict carrying an attrs mapping, with numpy arrays for datasets -- rather than an HDF5 file, since that is the whole surface the validator uses. One test writes the same trees out with h5py and checks both routes report the same findings, so the stand-in cannot quietly drift. Files are grouped by what the validator owes the user: BROKEN models must be rejected, SUSPICIOUS ones must warn without being rejected, and INCOMPLETE ones must be skipped rather than crashed on. Assertions are on severity, never on message wording, which is rendering rather than contract. _describe_corners only guarded the forward projection. A non-finite azimuth, or a non-finite grid spacing via the extent, projects an origin fine but gives NaN corners, which nztm_to_wgs_depth rejects -- so the ValueError escaped the check and validate_path reported it as "cannot read sfile", losing every other finding. Both projections are now inside the try, and the skip covers it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T1bWi7ju7iw669gKEqkcDT
lispandfound
marked this pull request as ready for review
September 10, 2026 20:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an sfile validator, which runs a number of checks over an SW4 velocity model, namely:
ngridcount matches the number of supplied grids.