Skip to content

2D plots: draw lithology, fault domains and age masks without smoothing - #32

Open
javoha wants to merge 1 commit into
mainfrom
jvh/plot-2d-nearest
Open

javoha wants to merge 1 commit into
mainfrom
jvh/plot-2d-nearest

Conversation

@javoha

@javoha javoha commented Dec 4, 2026

Copy link
Copy Markdown
Member

What

The categorical images of the 2D plots are drawn with interpolation="nearest":

  • plot_structural_model_2D: lithology
  • plot_fault_model_2D: fault domain map
  • StructuralFrame.plot_age_mask_section: age mask (True/False)

Why

matplotlib smooths images by default (antialiased) when they are shown at less than about 3 pixels per cell, and it averages the data values before colouring them. For lithology ids this draws formations that aren't there: between the basement (id 0) and a young formation (id 5), the averages 1–4 appear as thin lines or dots of the formations in between.

It shows up in flat models drawn to scale. In the Weisweiler case study (110 × 95 cells in the section, 28 km wide and 3.8 km deep, so about one pixel per cell in z), the 2D section showed red dots of one formation inside another and thin lines of other formations along the boundaries. A pixel comparison of that section: 815 pixels showed the wrong formation and about 1,400 a blended colour that belongs to no formation; with nearest both disappear. The fault domain map has the same problem with domain ids, and the age mask got grey edges.

Not changed: the scalar field section (continuous values) and the simulation contour plots (contourf), where smoothing doesn't invent categories.

Until this is merged, the same effect can be had in a script with plt.rcParams["image.interpolation"] = "nearest".

Tests

  • A section where the basement borders the youngest formation directly, drawn at under 3 pixels per cell, may only contain those two colours. Without the fix the test fails (three extra formation colours are drawn).
  • The three images use nearest.
  • Locally: 2D plot, structural visualization and structural object tests, 84 passed. CI runs the full suite.

matplotlib smooths images by default ("antialiased") when they are shown
at less than about 3 pixels per cell, and it averages the data values
before colouring them. For lithology ids that creates formations that
are not there: between the basement (0) and a young formation (5), the
averages 1-4 are drawn as thin lines or dots of the formations in
between. It shows up in flat models drawn to scale, e.g. the Weisweiler
case study (110 x 95 cells, 28 km wide, 3.8 km deep: one pixel per cell
in z), where the 2D section had red WalhornFM dots inside WilhelmineFM
and thin lines of other formations along the boundaries.

interpolation="nearest" for the categorical images:
- plot_structural_model_2D: lithology
- plot_fault_model_2D: fault domain map
- StructuralFrame.plot_age_mask_section: age mask (True/False)

Not changed: the scalar field section (continuous values) and the
simulation contour plots.

Tests: a section where the basement borders the youngest formation,
drawn at under 3 pixels per cell, may only contain those two colours
(fails without the fix); the three images use nearest.

Co-Authored-By: Claude Opus 5.5
@javoha
javoha requested review from a team as code owners December 4, 2026 14:31
@javoha

javoha commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Before/after on a synthetic flat model (28 km × 3.8 km, 110 × 95 cells, ~1 px per cell in z, a young formation eroding into four older layers): with matplotlib's default smoothing, other formations appear as dots inside the young formation and as thin lines along the boundaries; with interpolation="nearest" only the real formations are drawn.
pr32_before_after

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