Repository navigation
Closed
Labels
bugSomething isn't working
Description
It was brought to my attention today by Christian Ferreira from MB that grdinfo fails to report the z min/max values. It turns out that that the grids in question have no actual_range but oddly the report is that v_min and v_max are zero. Not z_min, z_max.
Example grid can be downloaded from here
So shamelessly GEBCO is not setting the actual_range attribute and calls elevation to the z array. But this is a grdinfo regression, I think.
grdinfo gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Title: The GEBCO_2021 Grid - a continuous terrain model for oceans and land at 15 arc-second intervals
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Command: Information on the development of the data set and the source data sets included in the grid can be found in the data set documentation available from https://www.gebco.net
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Remark:
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Pixel node registration used [Geographic grid]
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Grid file format: ns = GMT netCDF format (16-bit integer), CF-1.7
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: x_min: 22.9458333333 x_max: 27.2041666667 x_inc: 0.00416666666667 (15 sec) name: longitude n_columns: 1022
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: y_min: 31.9625 y_max: 35.5041666667 y_inc: 0.00416666666667 (15 sec) name: latitude n_rows: 850
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: v_min: 0 v_max: 0 name: Elevation relative to sea level [m]
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: scale_factor: 1 add_offset: 0
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: format: classic
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: Default CPT:
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
PaulWessel commentedon Jun 1, 2022
No regression, I think. We have had -M for ages to find data min/max in grdinfo. We do not loop over the data unless -M is given.
PaulWessel commentedon Jun 1, 2022
and old 6.2.rc0 gives the same.
joa-quim commentedon Jun 1, 2022
And we never crossed with this before? So GEBCO and EMODNET are fscrewing their grids. Because grdinfo may be called in scripts (it is in MB), we should automatically trigger -M when no actual_range, no?
PaulWessel commentedon Jun 1, 2022
But there are tons of reasons why someone might call grdinfo and often knowing the range of z is not one of them. So we do not want to add that burden unless requested. Any scripts calling this need to be aware that grids not written by GMT can be fucked. But GMT grids always writes min/max.
cdsferreira commentedon Jun 2, 2022
I'm not sure if GEBCO or EMODNET are doing something wrong here. I had a look at the CF Convention (link bellow), and the as I understand in section 4.3 (Vertical (Height or Depth) Coordinate) the default is use V and not Z for the vertical axis. The standard even says: "Optionally, the vertical type may be indicated additionally by providing the standard_name attribute with an appropriate value, and/or the axis attribute with the value Z."
http://cfconventions.org/Data/cf-conventions/cf-conventions-1.9/cf-conventions.html#vertical-coordinate
To me sounds that a grid to be fully compliant with the CF Convention should use V over Z.
Also, if GMT is able to recognise these grids as COARDS, CF-1.5 (under the IDs nb, ns, ni, nf and nd), the same standard was already there in 2010 (link bellow).
http://cfconventions.org/Data/cf-conventions/cf-conventions-1.5/build/cf-conventions.html#vertical-coordinate
Therefore I presume that the use of -M inside grdinfo could perhaps be standard when files are recognised by GMT as COARDS, CF-1.5 (or later), isn't? What are the drawbacks of enabling -M as default for the IDs nb, ns, ni, nf and nd inside GMT?
PaulWessel commentedon Jun 2, 2022
I dont think GMT is or will be parsing all possible attributes in a CF file. However ncdump -h shows this
as the only range given for depth. But this is the global depths for the whole grid. This particular subset is just
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: v_min: -4439 at x = 26.1270833333 y = 34.4354166667 v_max: 2372 at x = 24.03125 y = 35.29375which we get via -M by reading the whole grid. Looks to me whatever tool wrote this subset did not save the range of this subset's values. I am not sure we want to force GMT to always read the entire grid file if there is no info on the range since many uses of grdinfo has nothing to do with the range of the data. But we can have a discussion on this of course. For instance, if there is no info on the range, perhaps we should turn on -M unless some other option has been selected that implies we do not need the z-range. And if we had parsed the geospatial_vertical attributes we would have returned the wrong range.
PaulWessel commentedon Jun 2, 2022
Sorry forgot: The only drawback is that we are forced to read all the values of the grid rather than just the header. This can take time for very large grids. It is not really noticeable for small files of course, but that is why we have a -M option.
cdsferreira commentedon Jun 2, 2022
I agree, if the grid "complaint" with the CF convention doesn't follow it and just copy/paste the header of the main GEBCO grid then things get tricky. But I must note that when running grdinfo in the full GEBCO grid I get:
And if I run ncdump on that file the header shows me:
Is it right that grdinfo didn't get that from the netCDF header when not using -M? The file in question is available here:
https://www.gebco.net/data_and_products/gridded_bathymetry_data/
PS: I only work with grids up to 4-8GB, and therefore it doesn't bother me much force -M. But I know people working with 3D visualisation using netCDF layers of hundreds of Terabytes. That must be hard if the header is wrong and you're forced to read again the whole file to get the min/max values. That's something I should personally look into since I'm going to work with them this year.
joa-quim commentedon Jun 2, 2022
The
geospatial_vertical_min|maxare a different story because they are global attributes and ofc we are not going to parse all the global attributes. The problem is that GEBCO and apparently EMODNET are screwing by not inserting the z (or whatever name the 2D variable has) actual_range attribute. I must confess that I have not GEBCO in high consideration (why the hell do they distribute others grids using their own name?) and if it was only for GEBCO I would say ... But if EMODNET is doing the same shit we may have to do something.An alternative to Paul's idea, which I don't fully grasp how it would work, is to expand the -M option to -M[f|l], where -Mforce (the default for -M) means what it does now and -Mlilght means that if z_range is not given in file then GMT will get it.
BTW, this fails miserably
PaulWessel commentedon Jun 2, 2022
Seems to me the solution is to tell those who write these grids to fix their mistakes and not impose extra solutions for us. I dont see why it is on us to fix others mistakes. In the meantime, -M is there to help deal with such grids. It cannot become a default just because some grids lack proper metadata.
joa-quim commentedon Jun 2, 2022
I was not proposing to make it the default. Just to have a light weight -Ml that could be thrown into scripts that absolutely need to have z range but at same time not spending resources and users time when grids are well behaved.
PaulWessel commentedon Jun 2, 2022
OK, I can see that as a possibility.
PaulWessel commentedon Jun 2, 2022
If you have time to do this @joa-quim then go ahead. I would prefer
-M[c|f] for conditional (only if no z-range) or forced [Default]
PaulWessel commentedon Jun 2, 2022
Note that normal -M affects the output format. I would think -Mc would only get the min/max (and report them) but not do the rest that -M does (find the location of those min, max).
joa-quim commentedon Jun 3, 2022
I'll try but won't have time to look at it before Sunday night.
dwcaress commentedon Jun 4, 2022
I'm late to the party but agree that implementing -M[c|f] as described by Paul should let us solve the MB-System problem identified by Christian. Thanks!
PaulWessel commentedon Jun 5, 2022
@joa-quim I am working on this at the airport.
Introduce directives -Mc and -Mf in grdinfo
PaulWessel commentedon Jun 5, 2022
All tests pass, and that funny grid with -Mc now reports
gebco_2021_n35.50506591796875_s31.96197509765625_w22.9449462890625_e27.2021484375.nc: v_min: -4439 v_max: 2372 name: Elevation relative to sea level [m]Of course, -Mf does the same regardless of what the header says, and plain -M still means we report the location of the extrema as well. When the header has a valid range and you use -Mc then (with -Vd) you can see it skips the read:
grdinfo [DEBUG]: Found valid actual data range in header - no need to read matrixjoa-quim commentedon Jun 5, 2022
Still at airports? Well, the good side is that it's good for GMT.
PaulWessel commentedon Jun 5, 2022
Introduce directives -Mc and -Mf in grdinfo (#6767)
cdsferreira commentedon Jun 7, 2022
Thanks a lot Paul and Joaquim. Dave and I will start testing it and work to adapt the MB-System scripts to the new grdinfo.
PS: I have a few people I know at GEBCO and EMODNET (that seam to care a lot about data quality and compliance to standards) I know and I can report that their grids are written wrong. I don't know if that will produce improvements but I was puzzled that the netCDF grids from these two large entities that was supposed to target GMT users were not GMT/netCDF compatible. But I experienced already that with some crazy netCDF files from Ifremer where everything was scrabbled in GMT, so I used the ESRI ASCII grids that were written properly. I will also contact the CF Convention committee and suggest build a quick test suite to check netCDF grid compliance to CF Conventions, and help spot these mishandling of the standard. Maybe with that would not be always on us to adapt our software to read broken grids.
joa-quim commentedon Jun 7, 2022
Thanks Christian. Having them fixing their grids would be the best thing.