Repository navigation
grdcontour: Stop duplicating contours at phase singularities with -Z+p - #9302
Conversation
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>
|
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. |
|
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. |
|
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. |
|
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
left a comment
There was a problem hiding this comment.
OK, maybe it's not necessary. Let it apply to master and I'll later do a merge and see if there are conflicts.
With
-Z+p, a contour that ends at a phase singularity (e.g. the source point of aSBAZgrid) 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 intest/grdcontour/periodic.sh) and the extra copies were drawn through the labels. The fix insrc/gmt_support.c(gmt_contours) traces the other half and splices it, and the baseline forperiodic.shis updated so itsGMT_KNOWN_FAILUREflag can be dropped.Tested with:
With this fix:
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