Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle automatic CPT for constant grids #6931

Merged
merged 1 commit into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/gmt_support.c
Expand Up @@ -8610,9 +8610,15 @@ struct GMT_PALETTE *gmt_get_palette (struct GMT_CTRL *GMT, char *file, enum GMT_
GMT_Report (GMT->parent, GMT_MSG_WARNING, "All data points are NaNs so cannot do meaningful automatic CPT generation\n");
zmin = 0.0; zmax = 1.0; /* Does not matter since only NaN color will be used */
}
if (zmax <= zmin) { /* Safety valve 2 */
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Passing zmax <= zmin prevents automatic CPT generation!\n");
return (NULL);
if (zmax <= zmin) { /* Safety valve 2 [min == max] */
/* Have a constant grid or a mask grid with NaNs and a constant [1] - adjust min or max so that we can do an automatic CPT */
if (zmin > 0.0) /* Both are positive so just increase max */
zmax = 2.0 * zmin;
else if (zmin < 0.0) /* Both are negative so just decrease min */
zmin = 2.0 * zmax;
else /* All zeros, must set max to 1 */
zmax = 1.0;
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Found zmax == zmin, replaced with %lg and %lg to allow automatic CPT generation!\n", zmin, zmax);
}

if (file == NULL && (current_cpt = gmt_get_current_item (GMT, "cpt", false))) { /* There is a current CPT in modern mode */
Expand Down
4 changes: 0 additions & 4 deletions src/grdimage.c
Expand Up @@ -1631,10 +1631,6 @@ EXTERN_MSC int GMT_grdimage (void *V_API, int mode, void *args) {
double zmin = Grid_orig->header->z_min, zmax = Grid_orig->header->z_max;
char *cpt = gmt_cpt_default (API, Ctrl->C.file, Ctrl->In.file, Grid_orig->header);
grdimage_reset_grd_minmax (GMT, Grid_orig, &zmin, &zmax);
HH = gmt_get_H_hidden (Grid_orig->header);
if (HH->has_NaNs == GMT_GRID_HAS_NANS && doubleAlmostEqual (zmin, 1.0) && doubleAlmostEqual (zmax, 1.0)) { /* Mask grid, just nudge max to 2 */
zmax = 2.0; /* Otherwise we get annoying warning */
}
if ((P = gmt_get_palette (GMT, cpt, GMT_CPT_OPTIONAL, zmin, zmax, Ctrl->C.dz)) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "Failed to read CPT %s.\n", Ctrl->C.file);
gmt_free_header (API->GMT, &header_G);
Expand Down