Hi There,
I’m used to work with 2D variables from netCDF files in GMT (through, e;g., xyz2grd or grdimage etc.)
I struggle however to understand how to read variables with more than 2 dimensions.
For instance: I have a spectral variable with dimensions of depth, time and wavelength and I want to display the depth-time transect for one particular wavelength among the 130 available.
Any clue?
Thanks,
David
Maybe the docs can help?
The section, 3.26, is very enlightening to read. But one needs to keep careful track of the layers.
The text says something to the effect that instead of using layer numbers, you can use the layer values if they increase linearly. Does it work for date layers (yyyy-mm-dd) or date & time layers (yyyy-mm-ddThh:mm:ss)?
Say you have a multi-layered 3-D cube file with layers possessing the variable name “ssh” that is given daily, over a whole year. Can one use something like this, to get the grid for Christmas day?
gmt grdconvert "file.nc?ssh[2023-12-25]" -Gdate_20231225.grd
I’m doubtful that the above will work, given this statement in section 4.1, under the heading, Calendar Time Coordinates, if that applies in this situation.
All calendar date-clock strings are internally represented as double precision seconds since proleptic Gregorian date Monday January 1 00:00:00 0001.
Maybe layer names are a different beast?
Alternatively, when it comes to dates and times, one can figure out the layer number to access. Compute the layer number by converting the date to MJD, then subtract the MJD at the start of the year, 2023-01-01.
For example, layer zero has date 2023-01-01; layer 1 has date of 2023-01-02, etc. Hence, the nth layer is: n = mjd(date) - mjd(2023-01-01). Where mjd denotes a function that converts yyyy-mm-dd to Mean Julian Date.
I did it using the latter method and it worked well. For my example of the Christmas grid, you’d have: mjd(20231225) = 60303 and mjd(20230101) = 59945, so the layer is 358, and the command becomes:
gmt grdconvert "file.nc?ssh[358]" -Gdate_20231225.grd
Me too. 2023-12-25
is a string and one cannot index an array with a string.
Generic advice is to also use gdalinfo
. Internal naming can be very complicated and GDAL’s SUBDATASET
mechanism can be the easiest solution (also available in GMT).
If you have a (direct) pointer to one of those files (that ssh
reminds me horrors of trying to find files in pages that linked-to-pages-that-linked-to-pages-that…) I’d be curious to look at it.
Thanks Joaquin for pointing me to the right section of the online GMT docs (admittedly I have a hard time finding my way in these pages; it’s becoming a bit of a jungle!). I think I’ve understood the logic; should be Ok now.