Fix NaN region when -Ra determines a degenerate (zero-range) region from data - #9164
Merged
Conversation
…ounding
The dataset branch of gmtinit_get_region_from_data() already guarded
against a degenerate region (west==east and/or south==north, e.g. a
single input point, or points that only vary in one dimension) by
padding it to +/-1 (or +/-10%) — but that safety valve ran *after*
gmt_round_wesn(), which is what -Ra (approximate/rounded region) uses
to pick a "nice" region from the data.
gmt_round_wesn() takes log10() of the (zero) range while choosing a
rounding increment, which turns wesn into NaNs. By the time the
safety valve runs, wesn[XLO] and wesn[XHI] are both NaN, and
"NaN == NaN" is false, so the valve never fires and the NaN region is
used as-is, e.g.:
echo "0 0" | gmt plot -Sc0.1c -Gred -JX3c -Ba -Ra -Vd
...
plot [ERROR]: Could not parse -nan into ... coordinates!
plot [ERROR]: Offending option -R-nan/-nan/-nan/-nan
Meanwhile -Re (exact region) was unaffected, since it skips
gmt_round_wesn() entirely and lets the safety valve run on the
original (non-NaN) degenerate range, giving -R-1/1/-1/1.
Move the safety valve above the gmt_round_wesn() call so -Ra now sees
the same already-padded, non-degenerate range that -Re does, and
rounds *that* instead of the original zero-width box. Verified with
the above command (now succeeds), a single point away from the origin
(gives a region centered on the point), and that regular multi-point
inputs are unaffected (still -0.2/5.2/-0.2/5.2 for two points 5 units
apart).
This affects every module that can determine -R from input data
("d"/"g" in THIS_MODULE_NEEDS), not just one module.
Assisted-by: Claude Sonnet 5 (Medium effort)
joa-quim
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Move the existing
w==e/s==n safety valvefixing aNaNregion when-Radetermines the region from a single data point (or points that only vary in one dimension).Tested with:
echo "0 0" | gmt plot -Gred -Sc0.1c -JX3c -Ba -Ra -png lixoAssisted-by: Claude Sonnet 5 (Medium effort)