Reputation: 21
How can one give this peculiar netCDF file a proper time axis?
"time" exists as both a dimension and a variable, but the time variable uses "serial\ date\ number" as its dimension.
There are two challenges: 1. the variables vs. dimensions issue; and 2. "serial\ date\ number" appears to indicate spaces (with backslash delimiters) on some systems, but has underscores ("serial_date_number") on other systems.
netcdf
dimensions:
lon = 80 ;
lat = 41 ;
pres = 27 ;
time = 12053 ;
serial\ date\ number = 12053 ;
variables:
double u_mjo(time, pres, lat, lon) ;
double lon(lon) ;
lon:units = "degrees_east" ;
double lat(lat) ;
lat:units = "degrees_north" ;
double p_level(pres) ;
p_level:units = "hPa" ;
double time(serial\ date\ number) ;
time:units = "days since 0000-01-01 00:00 UTC" ;
...
Upvotes: 1
Views: 2040
Reputation: 31
On Ubuntu 14.04 I was able to do:
ncrename -v variable\ with\ whitespace,variable_with_whitespace filein.nc fileout.nc
Upvotes: 0
Reputation: 16365
Here's the procedure that worked for me using only NCO commands (no ncdump/manual edit/ncgen step):
Extract 4 time steps from OPeNDAP dataset to local netCDF file allfields.nc
:
ncks -d time,0,3 -d serial_date_number,0,3
http://weather.rsmas.miami.edu/repository/opendap/synth:100ae90b-71ac-4d38-add9-f8982a976322:L2FsbGZpZWxkcy5uYw==/entry
-O allfields.nc
Extract the time
variable into a separate file time.nc
:
ncks -v time allfields.nc time.nc
Extract everything except the time
variable to a separate file fixed.nc
(which also removes the problematic serial_date_number
dimension`):
ncks -C -x -v time allfields.nc fixed.nc
Rename the dimension serial_data_number
to time
:
ncrename -O -d serial_date_number,time time.nc
Append the file with fixed time to the file without time:
ncks -A time.nc fixed.nc
The files I used and created in this workflow may be seen here: http://geoport.whoi.edu/thredds/catalog/usgs/data2/rsignell/models/mapes/catalog.html
Upvotes: 2
Reputation: 21
The solution to convert original.nc to fixed.nc, addressing the 2 challenges, was (after much wrangling) this:
# 1. extract time from the original.nc file to create a new file with only time:
ncks -v time original.nc time.nc
# 2. remove the time variable from original.nc (which removes the problematic `serial_date_number dimension`)
ncks -C -x -v time original.nc fixed.nc
#3. Fix the time.nc file manually, with a text editor:
ncdump time.nc > time.txt # dump netCDF to text
## text-edit time.txt to fix up header,
## creating time = UNLIMITED ; // (12053 currently)
ncgen -o newtime.nc < time.txt # remake netCDF from text
# 4. Finally, concatenate the new time variable file into fixed.nc
ncks -A newtime.nc fixed.nc
Upvotes: 0