Skip to content

fix: depth-align user horizon data in global rank (#368)#370

Merged
johannesparty merged 3 commits into
mainfrom
fix/368-global-depth-interval-misalignment
Jun 24, 2026
Merged

fix: depth-align user horizon data in global rank (#368)#370
johannesparty merged 3 commits into
mainfrom
fix/368-global-depth-interval-misalignment

Conversation

@johannesparty

Copy link
Copy Markdown
Contributor

Fixes #368 — user-entered soil horizons were silently dropped/misaligned in the global ranking path when the horizons had a gap or did not start at depth 0.

Stacked on #369 (base = chore/wrb-description-snapshots) — review/merge that first. This PR's own diff is just the two commits below.

The bug

rank_soils_global packed user horizon values into a contiguous list (p_sandpct_intpl etc.) and then filtered that list by depth index (index.isin(pedon_slice_index)). When the user's horizons had a gap or a non-zero start, list position no longer equalled depth, so data below the gap (or shifted by the non-zero start) was read as NaN and dropped from the similarity match.

The fix (9b5b914)

Build the property arrays indexed by true depth so list position == depth and the index filter aligns. This mirrors us_soil.rank_soils, which was already depth-indexed — so this is a global-only fix; the US path was never affected and needs no change here.

Snapshots (6f8942c)

Two global test locations change because their input horizons exercise the bug:

  • [37.33333,-5.4] — gap from 25→125 cm
  • [-2.06972,37.29] — first horizon starts at 37 cm

The diffs are rank/score changes (the previously-dropped horizon now contributes). The other 12 locations (contiguous-from-0) are unchanged.

Scope notes

  • Global only. US (us_soil.rank_soils) was already depth-aligned; no pending US work for this bug.
  • Separate, deferred: lifting the 200 cm depth cap (US-relevant) — see docs/soil-depth-200cm-analysis.md, not part of this PR.

🤖 Generated with Claude Code

@johannesparty johannesparty requested review from garobrik and knipec June 24, 2026 05:39
Comment thread soil_id/global_soil.py
Base automatically changed from chore/wrb-description-snapshots to main June 24, 2026 20:58
johannesparty and others added 3 commits June 24, 2026 14:01
rank_soils_global packed user-entered horizon values into a contiguous
list (p_sandpct_intpl/p_claypct_intpl/p_cfg_intpl) with no depth
alignment, then filtered that list by depth index via
`index.isin(pedon_slice_index)`. When the user's horizons had a gap or
did not start at depth 0, the packed list positions no longer matched
the depth indices, so any data below a gap (or shifted by a non-zero
start) was silently read as NaN and dropped from the similarity match.

Build the property arrays indexed by true depth (0..199) instead, so
list position == depth and the index filter aligns. This mirrors the
approach already used in us_soil.rank_soils, which is why the US path
was not affected.

Verified on a live global lookup: with identical geometry but the deep
post-gap horizon set to clay vs sand, the rankings now differ
(previously identical because the deep horizon was dropped).

Global snapshots will change for any test pedon with a gap or non-zero
start; these are regenerated in a follow-up commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The depth-alignment fix in rank_soils_global changes the ranking for the
two global test pedons whose user horizons are gapped or do not start at
0:
  - [37.33333,-5.4]  (gap 25..125 cm)
  - [-2.06972,37.29] (first horizon starts at 37 cm)

Previously these pedons silently dropped the post-gap / shifted horizon
data; the snapshots now reflect the corrected rankings. The other 12
global pedons are contiguous-from-0 and are unchanged.

Regenerated on top of the WRB description resync, so these diffs are
rank/score only (no description text).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The #368 depth-alignment fix removed its only callers in rank_soils_global
(user property arrays are now built depth-indexed). Comment it out rather
than delete, in case the fixed-length pad/truncate is wanted again.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@johannesparty johannesparty force-pushed the fix/368-global-depth-interval-misalignment branch from 4af60ec to 96bb996 Compare June 24, 2026 21:01
@johannesparty johannesparty merged commit 129134a into main Jun 24, 2026
4 checks passed
@johannesparty johannesparty deleted the fix/368-global-depth-interval-misalignment branch June 24, 2026 21:16
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.

Investigate: Claude claims soil-id-algorithm may drop depth interval data

2 participants