Report the real cause when a vertical plane is queried without depth - #109
Merged
Conversation
coordinate_length was forced to 3 whenever dip == 90, regardless of the input's dimensionality, so a 2D (lat, lon) query against a vertical plane produced a broadcast ValueError. Fault's per-plane loop caught that and re-raised "Given coordinates are not on fault" -- for a point that is on the fault. A plane dipping 84 degrees handled the same query fine, so only the exactly-vertical case failed, and dip == 90 is common in NZ fault models. Sizes the slices from the input alone, and raises a specific error for the vertical-without-depth case: a vertical plane projects onto a line in plan view, so a (lat, lon) pair maps to every depth on the plane and the dip coordinate is genuinely undetermined. Fabricating one would trade a confusing error for a silently wrong answer. Adds CoordinatesNotOnPlaneError (a ValueError subclass, so external callers catching ValueError are unaffected) for the genuine off-plane miss, so Fault's loop only swallows real misses and the undetermined-dip error surfaces to the caller instead of being reported as a geometric one. Fixes #85 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #85
Problem
coordinate_lengthwas forced to 3 wheneverdip == 90, regardless of the input's dimensionality:A 2D
(lat, lon)query against a vertical plane then sliced 3 components fromself.boundsbut only 2 from the input, producingValueError: operands could not be broadcast together with shapes (2,) (3,).Fault.wgs_depth_coordinates_to_fault_coordinatescaught that with a bareexcept ValueErrorand re-raised"Given coordinates are not on fault."— for a point that is on the fault.A plane dipping 84 degrees handled the identical query fine, so only the exactly-vertical case failed, and
dip == 90is common in NZ fault models.What this does not do
The obvious one-line fix — size from the input shape alone — is not enough, and I did not do only that. A vertical plane projects onto a line in plan view, so a
(lat, lon)pair maps to every depth on the plane: the dip coordinate is genuinely undetermined. With the slicing merely fixed, the 2x2 system is rank-deficient andlstsqreturns a least-norm solution, i.e. a fabricated dip coordinate of roughly 0 that passes the[0, 1]bounds check. That trades a confusing error for a silently wrong answer, which is worse.So this PR keeps the operation an error, but an honest one. What the correct answer should be — reject, or return a documented convention such as the top edge — is a design question I have left on the issue rather than deciding here.
Changes
coordinate_lengthis derived from the input shape alone.ValueErrornaming the real cause.CoordinatesNotOnPlaneError(ValueError)for the genuine off-plane miss.Fault's per-plane loop now catches only that, so the undetermined-dip error surfaces to the caller instead of being reported as a geometric miss. It subclassesValueError, so any external caller doingexcept ValueErroris unaffected.Raisessection updated; the "not passing depth is supported" note now records that vertical planes are the exception.Behaviour
[0.5, 0.5][0.5, 0.5]broadcast shapes (2,) (3,)Depth is required to locate coordinates on a vertical plane...Faultof that plane, 2DGiven coordinates are not on fault.Depth is required...[0.5, 0.5][0.5, 0.5]Given coordinates are not on fault.Given coordinates are not on fault.Verification
test_vertical_plane_without_depth_reports_the_real_causefails without the fix.test_sources.py).ruff check,ruff format,numpydoc lintclean.🤖 Generated with Claude Code