What's wrong with this netCDF file?

Added by Juan Jose 9 months ago

This is a question related to the one I have just posed here.

I have to plot a netCDF file. But for some reason, GMT does not know how to read the file. I get something like:

> gmt grdinfo cor-PRE-SON.nc
grdinfo (api_import_grid): No 2-D variable in file [cor-PRE-SON.nc]
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)
[Session gmt (0)]: Error returned from GMT API: GMT_GRID_READ_ERROR (18)

I have to make a nasty workaround: I use external tools to produce a file with three columns (lon lat value) and then I use xyz2grd to produce a suitable netCDF file. This is time consuming (I have to plot many figures), prone to mistakes and generally a lame workaround.

Could you give me a hint on what's wrong with this file? I attach it to this message.

Thanks.

cor-T2M-DJF.nc - Example netcdf file on a latlon projection (10.5 KB)


Replies (3)

RE: What's wrong with this netCDF file? - Added by Paul 9 months ago

GMT expects netCDF grids to follow the COARDS convention [http://ferret.pmel.noaa.gov/Ferret/documentation/coards-netcdf-conventions]. By default, we look for the first 2-D variable in the file and expect that to be the grid. Your file has no 2-D grid but a 4-dimensional data cube, which is fine, and it is named var1. As is, GMT would need to be told that, e.g.

gmt grdinfo "cor-T2M-DJF.nc?var1"

that would get the first possible 2-D slice I believe. If you want a particular 2-D slice from this 4-D cube you will need to supply more information, e.g.

gmt grdinfo "cor-T2M-DJF.nc?var1[5,2]"

See section 7.26 in the CookBook. However, we can probably do a bit better than that. We should be able to allow

gmt grdinfo cor-T2M-DJF.nc

to work with a warning (stating what slice we are selecting) by finding the first named variable (if there is no z) that has >= 2 dimensions.

RE: What's wrong with this netCDF file? - Added by Paul 9 months ago

I have implemented the above in r19893. E.g.

gmt grdinfo cor-T2M-DJF.nc -V
grdinfo [WARNING]: No 2-D array in file cor-T2M-DJF.nc.  Selecting first 2-D slice in the 4-D array var1
grdinfo [WARNING]: No 2-D array in file cor-T2M-DJF.nc.  Selecting first 2-D slice in the 4-D array var1
cor-T2M-DJF.nc: Title: 
cor-T2M-DJF.nc: Command: Wed Mar 07 12:21:35 2018: cdo -f nc -g ../DATA/T2M-MM5-WINDOW-daily.nc copy ../CORRELATION/cor-T2M-DJF.ext ../CORRELATION/cor-T2M-DJF.nc
cor-T2M-DJF.nc: Remark: 
cor-T2M-DJF.nc: Gridline node registration used [Geographic grid]
cor-T2M-DJF.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
cor-T2M-DJF.nc: x_min: -18.75 x_max: 45 x_inc: 3.75 name: longitude n_columns: 18
cor-T2M-DJF.nc: y_min: 27.8334445 y_max: 72.361581 y_inc: 3.71067804167 name: latitude n_rows: 13
cor-T2M-DJF.nc: z_min: NaN z_max: NaN name: var1
cor-T2M-DJF.nc: scale_factor: 1 add_offset: 0
cor-T2M-DJF.nc: format: classic

RE: What's wrong with this netCDF file? - Added by Juan Jose 9 months ago

Thanks Paul. Specifying the var name and time steps works nicely.

(1-3/3)