Description
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:
I have to specify a master CPT for this to work:
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:
- grdmath should always wipe the default CPT setting in the output grid
- 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
joa-quim commentedon Jul 23, 2022
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.
PaulWessel commentedon Jul 24, 2022
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.
Must erase any input grid CPT in grdmath
Esteban82 commentedon Jul 24, 2022
I agree with Joaquim. We should follow solution 1.
Must erase any input grid CPT in grdmath (#6914)
WalterHFSmith commentedon Jul 25, 2022
PaulWessel commentedon Jul 25, 2022
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.
WalterHFSmith commentedon Jul 25, 2022
PaulWessel commentedon Jul 25, 2022
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.grdand be done with it. I think I like this more. What does that grumpy Portuguese guy think?
joa-quim commentedon Jul 25, 2022
Fine for me. And to not disappoint you. I barely use
grdmathanymore.PaulWessel commentedon Jul 25, 2022
I am crushed.
PaulWessel commentedon Jul 25, 2022
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?
joa-quim commentedon Jul 25, 2022
I can call
grdmathfrom 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.
Let grdmath control what happens to grid CPT settings
Let grdmath control what happens to grid CPT settings (#6916)