Skip to content

fix(modelling): correct unit ranges from stratigraphic column dicts and return unit ids from evaluate_model - #412

Merged
lachlangrose merged 5 commits into
masterfrom
fix/strat-column-ids
Nov 25, 2026
Merged

lachlangrose merged 5 commits into
masterfrom
fix/strat-column-ids

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Fixes two problems found in a repo audit. Together they gave every model built with from_processor (ProcessInputData or map2loop) a wrong block model and missing surfaces.

Unit ranges and group names

  • The basal unit from ProcessInputData has range (-inf, 0), so its thickness is infinite. update_unit_values stacked thicknesses from 0, so every unit above it got (inf, inf). On the shipped load_geological_map_data example, every point above 0 was labelled as the basal unit, and get_stratigraphic_surfaces gave only one surface.
  • Fix, at the root in update_unit_values: an infinite first unit of a group gets (-inf, 0), and the stack above it starts at 0. This survives a later add_unit, a thickness change, and from_dict. get_isovalues recomputes before it reads.
  • With 2 or more groups, group_mapping was built in dict order but get_groups() counts from the top, so each unit was evaluated against the other group's field. Groups are now mapped by their position in the built column.

evaluate_model ids

  • It returned a running counter (top-first, skipping groups without a feature) instead of unit.id, so ids disagreed with stratigraphic_ids() and cmap(). It now returns unit.id, or -1 where no unit is assigned.
  • cmap() now orders its colours by unit id, so the block model and map views keep each unit's colour.

Behaviour changes (recorded in COMPAT.md): evaluate_model values are unit ids (evaluate_model is public API, stable tier). The default Basement range is now (-inf, 0). A hand-written column dict whose units have gaps, or do not start at 0, is rebuilt from the thicknesses rather than taking its literal min and max values.

Overlap: #297 adds a test in the same file (a textual conflict). #375, #376 and #380 edit from_dict, COMPAT.md and geological_model.py, so a rebase may need small merges.

Tests: 202 passed and 7 skipped in tests/unit/input, test_exporters, test_fault_topology, test_geological_model, test_stratigraphic_column, test_world_location_consumers and the public API tests. The whole tests/unit/modelling folder and the visualisation package tests were not run, because they took too long locally. Reviewed by a second agent; the review's findings are fixed in 5485ee6, 64d3ba8 and 2de0f07.

🤖 Generated with Claude Code

lachlangrose and others added 5 commits November 25, 2026 17:55
… column dict

set_stratigraphic_column made the unit ranges again from the thicknesses,
starting at 0. The basal unit from ProcessInputData has min=-inf and max=0,
so its thickness was inf and all units above it got (inf, inf). Now the
units keep the min and max values from the dict, and get_isovalues uses
these values.

The group names used the dict order (oldest group first), but get_groups
counts the groups from the top of the column. With two or more groups,
each unit got the name, and so the scalar field, of a different group.
Now the names follow the position of each group in the column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evaluate_model gave a running counter (bottom group first, top unit first)
in place of unit.id. Thus the values did not agree with stratigraphic_ids().
Now each point gets the id of its unit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first fix set the unit ranges once, but update_unit_values made them
again on each add_unit or thickness change. The basal unit with an
infinite thickness then gave (inf, inf) to all units above it again.

Now update_unit_values gives an infinite basal unit of a group the range
(-inf, 0), and the units above it start at 0. set_stratigraphic_column
does not set the ranges itself any more. get_isovalues makes the values
again and reads the unit ranges, so a column from from_dict also gives
correct values. The Basement range changes from (0, inf) to (-inf, 0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cmap() gave the colours with the top unit first. evaluate_model now gives
unit.id, which increases from the bottom, and the viewers map each value
to a colour in order. Thus the block model and map colours were in the
reverse order. Now cmap() gives the colours in the order of the unit ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evaluate_model is a stable method. Its values are now unit ids, and the
cmap colours and the basal unit range also changed. Add a COMPAT.md row
for these changes and say in the docstring that the values are unit ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lachlangrose
lachlangrose merged commit c9cb718 into master Nov 25, 2026
37 checks passed
@lachlangrose
lachlangrose deleted the fix/strat-column-ids branch November 25, 2026 21:31
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