How to get values of a categorical grid?


I am working with the GEBCO Type Identifier (TID). The grid is categorical and the nodes only have the following values:

  • 0: land
  • 11 to 17: Direct measurements.
  • 40 to 46; Indirect measurements
  • 70 to 72: Unknown

Reference: Contributing Data


So, I created a categorical CPT and made the following map. But, as you can there are 10 categories that are not used. So, I want to filter these 10 categories from the CPT. How can I do it?

What I try

I use these commands to extract the values present in my region:

gmt grd2xyz $TID -R$R -ZTLu | gmt histogram -T1 -Io -bi1u

I got this:

0 5492280
10 139246
11 2916246
14 9283
17 1134184
40 4160258
41 7241290
43 4662
44 73215

It works but I am not interest in the total of nodes. Is there any way to avoid doing that (so it would be faster)?

I could use add -o0 in the previous commnad and them use grep within a loop (I think) to filter the cpt. Is there any easy way to do this? Should I make a feature request?

Remember that anything but plain Cartesian projection will resample your grid using whatever splines method is in effect. You should either plot using -JQ or explore grdimage -nn to avoid the resampling (which makes no sense with caregories).

Thanks Paul. I use grdimage -nn+a.

Determining unique values in the grid is no faster if we count them or not. You could just create a categorical CPT like

0 white ; land
11 blue; single-beam
etc since you would have to add those names manually anyway.

For the record, I managed to it with;

for nombre in $(gmt grd2xyz $TID -R$R | sort | uniq)
  grep "^$nombre" TID.cpt >> my_TID.cpt

Yes, I made my general TID cpt for the above map.

But, if I made a local map, then only a few categories are needed.