Skip to content

grdcontour: Stop duplicating contours at phase singularities with -Z+p - #9302

Merged
Esteban82 merged 2 commits into
masterfrom
fix-grdcontour-periodic-labels
Nov 17, 2026
Merged

Esteban82 merged 2 commits into
masterfrom
fix-grdcontour-periodic-labels

Conversation

@Esteban82

Copy link
Copy Markdown
Member

With -Z+p, a contour that ends at a phase singularity (e.g. the source point of a SBAZ grid) was traced only in one direction and then re-traced from every unused edge, so each contour was drawn several times (114 segments instead of 27 in test/grdcontour/periodic.sh) and the extra copies were drawn through the labels. The fix in src/gmt_support.c (gmt_contours) traces the other half and splices it, and the baseline for periodic.sh is updated so its GMT_KNOWN_FAILURE flag can be dropped.

Tested with:

gmt grdmath -Rg -I1 32 22 SBAZ = t.nc
gmt grdcontour t.nc -JG0/0/12c -A20 -Wa1,blue -Bg -Gl-90/0/0/0,0/0/90/0 -Z+p -png periodic_labels

With this fix:

periodic_labels

Before, some blue contour lines were drawn through their labels (e.g., 140° and 160°).

Assisted-by: Claude Opus 5.5

🤖 Generated with Claude Code

Esteban82 and others added 2 commits November 16, 2026 22:53
With -Z+p, a contour that ends at a phase singularity (e.g. the source and
antipode of an SBAZ grid) dead-ends inside the grid without hitting NaNs, so
the interior scan in gmt_contours only traced it one way. Every later start
edge on the untraced part then retraced the whole line, since the tracer
only checks used edges at the start. In test/grdcontour/periodic.sh the 20
contour was drawn 37 times and 140/160 twice, and the extra copies ran
through the labels of the first one.

Treat such a dead end like a NaN dead end so the other direction is traced
and spliced, and stop that reverse trace when it runs into an edge that is
already used. Output for non-periodic grids, including NaN-holed ones, is
unchanged. Remove the known-failure flag from periodic.sh; its 2016 baseline
must be regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old baseline (GMT 5.3, 2016) still showed the contours through
the 140 and 160 degree labels and lacked the red debug helper line
added to the script in 2020.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Esteban82 Esteban82 added bug Something isn't working maintenance Boring but important stuff for the core devs labels Nov 17, 2026
@Esteban82
Esteban82 requested review from a team, joa-quim and seisman November 17, 2026 02:02
@joa-quim

Copy link
Copy Markdown
Member

Federico, I've been quite busy with classes, iGMT and agriculture but I plane to come back to the entire replacement of the GMT contouring algorithm by the one in GDAL. We have a WIP: PR for that, so this should perhaps see if it affects that PR or not.

@Esteban82

Copy link
Copy Markdown
Member Author

Claude says it doesn’t affect it: GenericMappingTools/gmt#9255 keeps the current tracer for -Z+p, which is the only path this fix touches, so the fix stays useful after GenericMappingTools/gmt#9255 and the two PRs don’t overlap. It would only become obsolete if -Z+p were ever moved to GDAL too, which GenericMappingTools/gmt#9255 says isn’t possible since a GDAL band can’t represent the 360° wrap.

@joa-quim

Copy link
Copy Markdown
Member

The -Z+p option was left unchanged because GDAL is not able to reproduce that behavior. This means the GMT algorithm is still used in that case. But any change in this regard should be applied in that branch.

@Esteban82

Copy link
Copy Markdown
Member Author

OK. Claude checked that the two commits apply cleanly on grdcontour-gdal (no conflicts in either direction). Let me know if you still want me to move them to that branch.

@joa-quim joa-quim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, maybe it's not necessary. Let it apply to master and I'll later do a merge and see if there are conflicts.

@Esteban82
Esteban82 merged commit 71d30cc into master Nov 17, 2026
19 of 21 checks passed
@Esteban82
Esteban82 deleted the fix-grdcontour-periodic-labels branch November 17, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maintenance Boring but important stuff for the core devs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants