Skip to content

When to keep or remove a grids default CPT argument #6909

Closed

Description

@PaulWessel

As I was testing a grdmath macro to obtain Parsons and Sclater [1977] depths from an age grid, I noticed something odd. If I run

gmt grdmath -R200/240/40/60 @earth_age_01m_g PS77 = depth_ps77.grd

then the grid is correct with a range in depths from 2535 to 5356 meters. However, grdinfo says a bit more:

...
depth_ps77.grd: v_min: 2535.00390625 v_max: 5356.30371094 name: z
depth_ps77.grd: scale_factor: 1 add_offset: 0
depth_ps77.grd: Default CPT: @earth_age.cpt

Because the default CPT inherited from the age grid is passed along, and that CPT is set to go from 0 to 340 Myr, trying to make a simple map fails:

bad

I have to specify a master CPT for this to work:

good

It is not immediately obvious to me when we should wipe the incoming CPT. Well, it is in the sense that we are concerting unit from Myr to m and thus the old CPT should be irrelevant, but grdmath does not know that. Even a simple operation that does not change the units will fail due to the new range:

gmt grdmath -R160W/120W/40/60 @earth_age_01m_g/ 500 SUB = t.grd

would not plot a black ocean map. So there seems to be two possibilities here:

  1. grdmath should always wipe the default CPT setting in the output grid
  2. grdmath should leave it along and we write a Note in the documentation to explain the problem.

I think we have to go with (1) here. It is a relatively obscure problem and people will not read that section and just be frustrated why their basic plot is blank. I think this is the only module where this sort of thing can happen (unit change or wild range change). Any opposing voices, @GenericMappingTools/core ?

Activity

  1. added
    bug
    on Jul 23, 2022
  2. added this to the 6.5.0 milestone on Jul 23, 2022
  3. self-assigned this
    on Jul 23, 2022
  4. joa-quim commented on Jul 23, 2022

    @joa-quim
    Member

    This is a hint on a more general problem of metadata propagation which a not easy problem at all.
    Solution 1. is the only one to go here.

  5. PaulWessel commented on Jul 24, 2022

    @PaulWessel
    ContributorAuthor

    There was another thing I ran into last week but now I cannot find where/how it happened, but it had to do with incoming grid x and y units not being passed to the outgoing grid. So a one-liner plot of the input grid worked well (x and y were both km so we properly do the same scale for both axes) but the one-liner for hte output grid came out ugly and square because that axis info was lost. So in that case we should propagate the meta data through. I will see if I can rediscover this.

  6. Esteban82 commented on Jul 24, 2022

    @Esteban82
    Member

    I agree with Joaquim. We should follow solution 1.

  7. WalterHFSmith commented on Jul 25, 2022

    @WalterHFSmith
    Contributor
  8. PaulWessel commented on Jul 25, 2022

    @PaulWessel
    ContributorAuthor

    The only other thing to consider is what operations are being done. If Z values are altered then CPT for them should be dropped. If X or Y values are altered then maybe metadata for them should be dropped?

    Yes, that makes sense. However, I think x and y only changes in a grid when grdedit -R or -I are used, and also grdproject (but I think we are smart enough to change x,y from degrees to whatever the units are there). So maybe this is grdedit only?

    For z I think grdmath must drop always since it is too much (if even doable) to keep track of what is a minor correction to a data set (say, removing 3.4 mGal from a FAA grid based on some model) and one that clearly changes the units (multiplication, for example). It is too hard to be that judge so we have to let the user decide.

  9. WalterHFSmith commented on Jul 25, 2022

    @WalterHFSmith
    Contributor
  10. PaulWessel commented on Jul 25, 2022

    @PaulWessel
    ContributorAuthor

    Yes, I thought about that too. It is a bit annoying if you actually want to carry forward the grid's CPT given what you know and now you have to add it back in. Perhaps the better implementation of what we just merged is to add a new option:

    -C[cpt] Retain the grid's default cpt, or alternatively replace it with a new default CPT [Default removes any default CPT from the output grid].

    I could then do

    gmt grdmath -R200/240/40/60 -Cturbo @earth_age_01m_g PS77 = depth_ps77.grd

    and be done with it. I think I like this more. What does that grumpy Portuguese guy think?

  11. joa-quim commented on Jul 25, 2022

    @joa-quim
    Member

    Fine for me. And to not disappoint you. I barely use grdmath anymore.

  12. PaulWessel commented on Jul 25, 2022

    @PaulWessel
    ContributorAuthor

    I am crushed.

  13. PaulWessel commented on Jul 25, 2022

    @PaulWessel
    ContributorAuthor

    I still do thinkgs like evaluating cooling plate model isotherm depth etc in matlab and you would do that in Julia. But how do you do great circles distances from nodes to a point, spherical azimuths from grid nodes to a point, weighted statistics on geo grids (e.g., MEDIANW and others) without grdmath in the mix?

  14. joa-quim commented on Jul 25, 2022

    @joa-quim
    Member

    I can call grdmath from Julia if I need to.

    And, if it's for my own use only I often still prefer Matlab to Julia. The difference is on incomparable superior Matlab IDE+debug experience.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions