[THREDDS #AWG-971354]: TDS Netcdf time dimension name changes
- Subject: [THREDDS #AWG-971354]: TDS Netcdf time dimension name changes
- Date: Fri, 11 Oct 2019 06:35:30 -0600
Trying to make a collection of GRIB messages look like a netCDF Dataset is a
pretty interesting process. Because each GRIB message is essentially one
at one level (or layer) at one time means we have to aggregate similar grids
together into multidimensional variables. Part of that process involves creating
the dimensions, such as time. Unfortunately, we do not control the order in
we receive the messages (nor if we receive all messages), so we have to take a
rather simplistic approach in how we create and name things. For something like
time, whatever variable is stored in the first message we read in a given GRIB
file (just a bunch of GRIB messages concatenated together), we will give that a
time dimension called "time". The next message we encounter with a different
of time (say, precip accumulation over a time period), we'll call that dimension
time2. As you've seen, with GRIB, there can be many different distinct time
dimensions, and the naming isn't predictable in the sense that you can hard code
"time" in as the dimension and variable ahead of a priori. However, you can
programmaticly look at the dimensions on a variable to figure out dimension
and access their values through their associated coordinate variables, all
ever using a hardcoded string variable.
For any given dataset, the name of the time dimension might change, but its
position in the listing of dimensions will remain the same. You can use this to
get the times, lats, and lons. For example, let's say we have a Dataset with the
# what are the dimension names of the variable "Geopotential_height_isobaric"
('time1', 'isobaric4', 'lat', 'lon')
# get the name of the time dimension associated with the
dtime = dataset.variables['Geopotential_height_isobaric'].dimensions
# the vaule of dtime is 'time1'
# get the array of time values (values are seconds since some start time, or
# something like that)
times = dataset.variables[dtime]
# Convert times using the num2date function available through netCDF4
# (gives you python datetime objects)
vtimes = num2date(times[:], times.units)
# get the names of the lat and lon dimensions
dlat = dataset.variables['Geopotential_height_isobaric'].dimensions
dlon = dataset.variables['Geopotential_height_isobaric'].dimensions
# get the lat and lon arrays associated with "Geopotential_height_isobaric"
lat = dataset.variables[dlat][:]
lon = dataset.variables[dlon][:]
Let me know if that help!
> I have been using python to create weather products based on the data found
> on thredds.ucar.edu
> I have noticed in some on the model data that the time dimension varies
> between time, time1, time2, an time3
> Is there any way to predict this? Or programmatically a way to dynamically
> set this so I can handle the variability gracefully.
> Please help me understands this variability.
Ticket ID: AWG-971354
Department: Support THREDDS
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata
inquiry tracking system and then made publicly available through the web. If
you do not want to have your interactions made available in this way, you must
let us know in each email you send to us.
NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web. If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.