Fix strike direction for nstk == 1 SRF segments (degrees used as radians) - #101
Merged
Merged
Conversation
The along-strike offset in SrfFile.planes was built from np.cos(strike_nztm)/np.sin(strike_nztm), but great_circle_bearing_to_nztm_bearing returns degrees, so the bearing was interpreted as radians and the plane pointed in an unrelated direction. Measured error in the recovered strike before this change: 87 degrees at stk=0, 30 degrees at stk=20, 96 degrees at stk=200. The existing test_planes_nstk_1_ndip_gt_1 did not catch it because it uses stk=45, which is an accidental near-fixed-point of the confusion (0.06 degrees of error there). Adds a parametrized regression test over eight bearings, using a fixture whose point column is genuinely consistent with the header strike. Fixes #84 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 #84
Problem
SrfFile.planesbuilds the along-strike offset for single-strike-point segments from a bearing returned byqcore.coordinates.great_circle_bearing_to_nztm_bearing, which is in degrees, but passed it straight tonp.cos/np.sin:The bearing was therefore interpreted as radians and the resulting plane pointed in an essentially arbitrary direction.
Measured impact
Recovered
plane.strikefrom a syntheticnstk == 1segment, before this change:stkAfter the change every bearing tested recovers the header strike to within 0.05 degrees.
Why CI never caught this
test_planes_nstk_1_ndip_gt_1exercises exactly this branch, but withstk=45— which turns out to be an accidental near-fixed-point of the degrees/radians confusion (44.758 radreduces to44.44 degmod 2*pi, 0.3 degrees from the true value). The assertionplane.strike == approx(45, abs=1)passed on a coincidence. That blind spot is why the new test is parametrized over eight bearings rather than tightening the existing one.Changes
source_modelling/srf.py— wrapstrike_nztminnp.radians, matching the convention already used atfsp.py:124-125.tests/test_srf.py— addtest_planes_nstk_1_strike_recovered, parametrized over 0/20/45/90/135/200/270/330 degrees.The new test needed a fixture whose point column is genuinely consistent with the header strike (the down-dip column generated along
stk + 90). The pre-existing fixture hardcodes a southeast-dipping point column, so for strikes like 200 the header and the point geometry contradict each other andPlanereorders the corners, flipping the reported strike by 180 degrees — unrelated to this bug, but it makes the old fixture unusable for a strike sweep.Verification
pytest tests/test_srf.py— 24 passed.ruff check,ruff format --check,numpydoc lintclean.Only line 615 was affected; it is the sole trig call in
srf.py, and thendip == 1branch delegates toPlane.from_centroid_strike_dip, which converts internally.🤖 Generated with Claude Code