Skip to content

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

Merged
lachlangrose merged 8 commits into
masterfrom
fix/fold-fault-features
Nov 26, 2026
Merged

lachlangrose merged 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>
@lachlangrose
lachlangrose merged commit a942177 into master Nov 26, 2026
37 checks passed
@lachlangrose
lachlangrose deleted the fix/fold-fault-features branch November 26, 2026 02:51
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…ormance

#421 changes the gradient near faults: only the tetrahedra that cross a
fault are made smaller (at most 10 times), and a point whose tetrahedron
still crosses a fault has a NaN gradient. The conflict is in the
refinement loop of GeologicalFeature.evaluate_gradient: take the loop
of master and keep its fault-side check inside probe_points().

On the 21 golden models the branch gives the same bits as master
a942177 for all 97 outputs that master can compute. The other 2
(cutting_faults gradients) fail on master too; #424 fixes that. The
golden references and the batch-count tests are updated in the next
commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
#424 (open against master) stops fillnan='nearest' from sending points
with a NaN coordinate to the KD-tree, which made cutting_faults gradients
fail after #421. It is the same commit as on the PR branch, so the later
master merge has no conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…changed (C-021)

Master #421 changes fault gradients near faults, fault_pitch and fold
rotation angles. 60 outputs of 17 golden models change (mostly
gradients; cutting_faults also some values, restored points and one
model id). The new references come from master a942177 with the fix of
#424, captured at the stored reference points. Evidence:

- the spec 003 branch gives the same bits as that code for all 970
  arrays of the 21 golden models;
- in each updated model, every array that #421 does not change is
  bit-identical to the old reference.

The manifest records the code, the reason and the changed keys under
provenance.reference_updates, with the new sha256 and summaries.

The gradient batch tests replay the refinement of #421: only the
tetrahedra that cross a fault are made smaller, at most 10 times, and a
point whose tetrahedron still crosses a fault is NaN. cutting_faults
group_0 now has 29 distinct (fault, batch) calls (25 before #421; the
refinement probes the crossing subset at each step) and still no
duplicate. A gradient has one scope slot for each probe size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…baseline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…NaN (#424)

Since #413 a point with a NaN coordinate gives NaN. evaluate_value with
fillnan='nearest' then sent those points to the KD-tree query, which
raised "'x' must be finite". After #421 the fault-side check of a
gradient reaches this path, so evaluate_model_gradient of a model with
cutting faults failed.

Only points with finite coordinates get the nearest value; a point with
a NaN coordinate has no nearest point and stays NaN. A call with no
known value also stays NaN.


Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
lachlangrose added a commit that referenced this pull request Nov 26, 2026
#425 (open against master) keeps a step direction where a cutting fault
leaves no frame gradient after #421, so a point on a cutting fault is no
longer moved to NaN. The conflict is in apply_to_points: the branch takes
the frame gradient from _evaluate_frame; the fallback of #425 follows it.
A cut frame always takes the legacy member path, where the NaN comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…me gradient (#425)

Since #421 a gradient whose tetrahedron still crosses a fault after the
refinement is NaN. A fault whose frame is cut by younger faults takes the
step direction of apply_to_points from that gradient, so a point on a
cutting fault was moved to NaN. A builder that restores a regular grid
through such a fault then failed with "Cannot resize the grid" (seen with
a chain of cuts: D cut by C, C by B, B by A; 215 of 10890 grid points of D
were NaN).

Where the frame of a cut fault has a NaN gradient at a finite point, use
the gradient of the frame without the cutting faults there; a step only
needs a direction. A frame without cutting faults keeps a NaN gradient,
so its points stay NaN as before (test_fault_frame_validation). A point
with a NaN coordinate is not moved.


Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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