Skip to content

makecpt in externals produce wrong CPTs when master has hinge #2327

Closed

Description

@joa-quim
julia> cpt = makecpt(" -T-10000/2000/100 -Cgeo");
julia> psscale(cpt, B=:af, show=1, D="x8c/1c+w12c/0.5c+jTC+h", fmt=:png)

GMTjl_tmp

Checked and Matlab displays the same behavior, which doesn't rule out the possibility that error in gmtmex and the Julia wrapper mimicked it.

Activity

  1. PaulWessel commented on Dec 22, 2019

    @PaulWessel
    Contributor

    This section in gmtmex_parser.c looks suspicious:

    		if (mxIsNaN (hinge[0])) {
    			P->has_hinge = 1;
    			P->mode &= GMT_CPT_HINGED;
    		}
    

    Should be !mxIsNaN (hinge[0]), no? If NaN then no hinge, else there is a hinge at that value.
    And should not P->hinge be set to hinge[0] if true? (default to zero so probably not the issue in this example, but the if-test is.

  2. seisman commented on Dec 22, 2019

    @seisman
    Member

    GMT command line gives the same result.

    gmt begin map png
    gmt makecpt -T-10000/2000/100 -Cgeo
    gmt colorbar -Baf -Dx1c/1c+w10c+h
    gmt end show
    

    image

  3. PaulWessel commented on Dec 22, 2019

    @PaulWessel
    Contributor

    Problem is makecpt which is not doing the same thing as the auto-stretching (which does honor the hinge). Still think the mex code is wrong but that is not the problem here though. Will have to see where to fix it.

  4. PaulWessel commented on Dec 23, 2019

    @PaulWessel
    Contributor

    Fixing the lack of hinge-implementation in sample_cpt. Getting a few failures:
    125 - GMT_tut_17.sh (Failed)
    407 - grdmath/ops.sh (Failed)
    458 - makecpt/logcpt.sh (Failed)

    Looking at tut 17 we have the case that we now actually are honoring the hinge. Top is the new plot, bottom is the old:

    GMT_tut_17-new

    GMT_tut_17

    You can see that since we run gmt makecpt -Cno_green -T-2/30/2 with a hinge at 0, then all the blue colors get squashed into the -2/0 range. Below is the original CPT from -1 to +1 with hinge at 0:

    t

    Only T = -2 and T = 0 (the hinge) samples the left half of the color scale. The resampled CPT is

    -2	42/255/255	0	42/255/255
    0	255/255/84	2	255/255/84
    2	255/255/84	4	255/255/84
    4	255/240/0	6	255/240/0
    6	255/240/0	8	255/240/0
    8	255/191/0	10	255/191/0
    10	255/191/0	12	255/191/0
    12	255/168/0	14	255/168/0
    14	255/138/0	16	255/138/0
    16	255/138/0	18	255/138/0
    18	255/112/0	20	255/112/0
    20	255/112/0	22	255/112/0
    22	255/77/0	24	255/77/0
    24	255/77/0	26	255/77/0
    26	red	28	red
    28	red	30	red
    

    while before the bug fix we get

    -2	32/96/255	0	32/96/255
    0	32/159/255	2	32/159/255
    2	32/191/255	4	32/191/255
    4	0/207/255	6	0/207/255
    6	42/255/255	8	42/255/255
    8	85/255/255	10	85/255/255
    10	127/255/255	12	127/255/255
    12	170/255/255	14	170/255/255
    14	255/255/84	16	255/255/84
    16	255/240/0	18	255/240/0
    18	255/191/0	20	255/191/0
    20	255/168/0	22	255/168/0
    22	255/138/0	24	255/138/0
    24	255/112/0	26	255/112/0
    26	255/77/0	28	255/77/0
    28	red	30	red
    

    with the original no_green (from -1 to +1 with hinge at 0):

    -1	32/96/255	-0.875	32/96/255
    -0.875	32/159/255	-0.75	32/159/255
    -0.75	32/191/255	-0.625	32/191/255
    -0.625	0/207/255	-0.5	0/207/255
    -0.5	42/255/255	-0.375	42/255/255
    -0.375	85/255/255	-0.25	85/255/255
    -0.25	127/255/255	-0.125	127/255/255
    -0.125	170/255/255	0	170/255/255
    0	255/255/84	0.125	255/255/84
    0.125	255/240/0	0.25	255/240/0
    0.25	255/191/0	0.375	255/191/0
    0.375	255/168/0	0.5	255/168/0
    0.5	255/138/0	0.625	255/138/0
    0.625	255/112/0	0.75	255/112/0
    0.75	255/77/0	0.875	255/77/0
    0.875	red		1	red
    
    

    You can clearly see that the colors right after the hinge (0) has red = 255, which is what the new resample does while the old makecpt with the bug does not convert to red until z = 14, way past the hinge. Thus I am pretty sure my revised sample_cpt fixes the bug. Agree @joa-quim and @seisman ?

  5. PaulWessel commented on Dec 23, 2019

    @PaulWessel
    Contributor

    BTW, the bug fix corrects @seisman's bug plot above as well.

  6. seisman commented on Dec 23, 2019

    @seisman
    Member

    Looks good to me. BTW, is there an option to ignore hinge in the master CPT?

  7. PaulWessel commented on Dec 23, 2019

    @PaulWessel
    Contributor

    No. One one hand the designer of the CPT deliberately designed it this way to use that hinge, so to override it could give usages that may look bad. On the other hand we want GMT to do anything, so perhaps makecpt and grd2cpt should have the ability to turn off the hinge. Running out of letters, so while makecpt -L is not used, there are no upper-case letters left for grd2cpt, meaning perhaps we use --ignore-hinge?

  8. PaulWessel commented on Dec 23, 2019

    @PaulWessel
    Contributor

    Another point to make is the pointlessness of people using things like -T-10000/2000/100. This is asking for degraded plots. Here is what @seisman example looks like after my fix:

    old

    You can see the 100 m discrete sampling in the CPT. Perhaps @joa-quim wanted that, perhaps not. By running the same example with just -T-10000/2000 we get this:

    new

    with a continuous change in color. This is preferred for images etc but perhaps the former is OK if you want to point constant color between contours in a colormap. As that interval gets larger, the aliasing gets worse.

  9. PaulWessel commented on Dec 24, 2019

    @PaulWessel
    Contributor

    Please open a feature request if you feel ignoring the hinge is a needed option, @seisman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions