Skip to content

fix(features): fold rotation angles, fault gradients near faults, fault_pitch, faultfunction setter - #421

Open
lachlangrose wants to merge 8 commits into
masterfrom
fix/fold-fault-features
Open

lachlangrose wants to merge 8 commits into
masterfrom
fix/fold-fault-features

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Fixes five fold and fault problems found in a repo audit. Each has a regression test that fails without the fix.

  • The fold axis rotation angle was biased by the limb dip. A projected vector of length cos(limb) went into arccos without being normalised. A true angle of 30° came out as 20.7° with a 45° limb, and 9.85° with a 70° limb. It is now normalised, as the limb function already was, and the cosine is clipped to [-1, 1] so rounding cannot give NaN.
  • One NaN made the fold profile fit fail silently. The NaN mask used logical_or where it needed logical_and. curve_fit raised, the error was swallowed, and the profile kept its initial guess.
  • The gradient of a faulted feature crashed or hung at points on a fault. The refinement loop halved the tetrahedra of all points with no limit, and ended in LinAlgError (or looped forever when gx was exactly 0). Now only the tetrahedra that straddle a fault shrink, with at most 10 halvings. Points still straddling after that get a NaN gradient, because the field jumps there. On a 52k-point faulted model this is faster (4.8 s against 6.3 s), and more accurate away from the fault, because before, one near-fault point shrank every tetrahedron.
    • A follow-up keeps that NaN out of an older fault's apply_to_points: points on a younger fault are not moved, instead of becoming NaN. On master, the same call hung.
  • fault_pitch always crashed. The code rotated the normal about itself. Pitch is now the angle in the fault plane from strike, so 90 is the down-dip slip vector (a reverse fault with positive displacement). The docstring says this. A horizontal fault plane with a pitch raises a clear ValueError.
  • The faultfunction setter rejected plain functions and accepted any object. It is now one if/elif chain: named profiles, any callable, otherwise ValueError.

Overlap with #391: #391 changes the line just after the refinement loop in _geological_feature.py (_apply_faults to _restore_points). Expect a small text conflict there: keep this loop and use #391's call. The logic does not conflict.

Behaviour change: points within about step/10/1024 of a fault get a NaN gradient. The fold rotation-angle and constraint callers already drop NaN rows.

Tests: 43 passed in the fold/fault unit tests (including the new file and test_fault_block_fields). 75 passed in tests/integration/test_fold_models.py, tests/unit/validation/test_fold_frame_coordinate1.py and test_fault_frame_analytic.py. The review also ran 534 passing fold/fault tests. Reviewed by a second agent: no regressions. Its medium finding and two nits are fixed in the last commit.

Not changed (already on master): TrigoFoldRotationAngleProfile.fit always fails, with a missing-argument error.

🤖 Generated with Claude Code

lachlangrose and others added 8 commits November 25, 2026 21:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er 10 halvings

A point that stays on the fault gets a NaN gradient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rccos, document fault_pitch

A point on a younger fault now has a NaN gradient of that fault. An older
fault's apply_to_points added that NaN to the point, so the restored
point became NaN. Do not move points with a non-finite gradient.
Clip the cosine of the fold axis rotation angle to [-1, 1], so rounding
does not give NaN. Say in the fault_pitch docstring that pitch is
measured from strike and that 90 is the down-dip slip vector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_zero_gradient_protection_remains_effective pins that a NaN gradient
gives a NaN point. The model-level block evaluation already handles
points on a younger fault, so keep that contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant