I'm learning how to use the NCO tools, and I was wondering how I could add the time dimension ("time" and "nbnds") to a netcdf file. Below is an example using a simple netcdf file I created. I'm sure NCO can do this, but I'm not sure how... Any help would be super useful. Thanks!
ncap2 works great for adding a single time data entry (e.g.: time = 74875). However, in the dimensions, it shows "time = 1 ;". I was wondering... how can I change this entry in order to show the following? time = UNLIMITED ; // (1 currently)
Lastly, related to this... is it possible to add the "time_bnds" information? I tried:
As far as I know, there is no way to specify creation from scratch of a record dimension in ncap2 (Henry will correct me if otherwise). This is an oversight that we will try to address soon. For now, follow Patrick's suggestion.
cz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HI Charlie,
For now I have added the definition of unlimited dim(s) to defdim()
as a hidden feature
When the size is negative this indicated an unlimited dim
e.g defdim("time", -10)
My view is that it opens up a few problems that need to be ironed out.
1) when unlimited dim isn't the first dim (netcdf4) then ncap2 bombs out
2) Cant redefine in Output an unlimited dim that is in Input
Once we have ironed out the problems then I guess we can define the
parser tokens LIMITED/UNLIMITED
and make the defdim call like:
defdim("time",10,UNLIMITED)
Any way give it a go ?
....Henry
On 29/10/14 15:45, Charlie Zender wrote:
Thank you, Patrick.
As far as I know, there is no way to specify creation from scratch of
a record dimension in ncap2 (Henry will correct me if otherwise). This
is an oversight that we will try to address soon. For now, follow
Patrick's suggestion.
cz
This is a fine stopgap solution.
netCDF4 raises lots of issues for ncap2, and
one more such issue is negligible :)
I'm not sure exactly what you mean by point 2).
What does it mean to "redefine in Output" a dimension?
As long as what this user wants to do will work with
your new patch, then the documentation in your brief
note will suffice so interested users
can test this hidden feature (knowing the syntax may
later change).
Thanks!
c
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Guys... your suggestions are amazing! Thank you so much... it works like a charm! :)
One last question: is it possible to add the "time" dimension to the "z" variable in my netcdf file? For instance, using the example below:
how can I change "float z(lat, lon) ;" into "float z(time, lat, lon) ;"?
Just a side note... I just wanted to say how incredibly great it is to work with NCO! This tool is so powerful...
Just fyi, I wanted to share with others a link that I found that has some valuable "primers" for those like me that are starting to learn this nifty toolbox:
Hi everyone,
I'm learning how to use the NCO tools, and I was wondering how I could add the time dimension ("time" and "nbnds") to a netcdf file. Below is an example using a simple netcdf file I created. I'm sure NCO can do this, but I'm not sure how... Any help would be super useful. Thanks!
My original netCDF file consists of:
netcdf test1 {
dimensions:
lon = 3 ;
lat = 2 ;
variables:
double lon(lon) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:actual_range = 0., 359.9 ;
double lat(lat) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:actual_range = -90., 89.9 ;
float z(lat, lon) ;
z:long_name = "z" ;
z:_FillValue = NaNf ;
// global attributes:
:title = "Test 1" ;
data:
lat = -90, -89.9;
lon = 0, 0.1, 0.2;
z = 0.3161385, 0.290362, 0.340162, 0.3, 0.2, 0.23;
}
And I would like to add the "time" component into it so that it looks like this:
netcdf test1 {
dimensions:
time = UNLIMITED ; // (1 currently)
lon = 3 ;
lat = 2 ;
nbnds = 2 ;
variables:
double time(time) ;
time:units = "days since 1800-1-1 00:00:00" ;
time:long_name = "Time" ;
time:actual_range = 74875., 74905. ;
time:axis = "T" ;
time:bounds = "time_bnds" ;
double lat(lat) ;
lat:long_name = "Latitude" ;
lat:units = "degrees_north" ;
lat:actual_range = -90.f, 89.9f ;
double lon(lon) ;
lon:long_name = "Longitude" ;
lon:units = "degrees_east" ;
lon:actual_range = 0.f, 359.9f ;
float z(lat, lon) ;
z:long_name = "z" ;
z:_FillValue = NaNf ;
double time_bnds(time, nbnds) ;
time_bnds:long_name = "Time Boundaries" ;
// global attributes:
:title = "Test 1" ;
data:
time = 74875 ;
lat = -90, -89.9;
lon = 0, 0.1, 0.2;
z = 0.3161385, 0.290362, 0.340162, 0.3, 0.2, 0.23;
time_bnds = 74875, 74905;
}
use ncap2
http://nco.sf.net/nco.html#ncap2
e.g.,
ncap2 -s 'defdim("time",1);time[time]=74875.0;time@long_name="Time"; etc.etc.etc.' -O ~/nco/data/in.nc ~/foo.nc
cz
Thank you so much CZ for the prompt response. This is incredibly helpful! :)
ncap2 works great for adding a single time data entry (e.g.: time = 74875). However, in the dimensions, it shows "time = 1 ;". I was wondering... how can I change this entry in order to show the following? time = UNLIMITED ; // (1 currently)
Lastly, related to this... is it possible to add the "time_bnds" information? I tried:
but I keep getting the error: Command-line script:1:39: expecting ;, found ','
Am I missing something on the syntax?
Hi,
Here is an example I have used recently.
ncap2 -Oh -s 'defdim("tbnds",2) ; time[time]={15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5,319, 349.5} ; time_bnds[time,tbnds]={0, 31, 31, 59, 59, 90, 90, 120, 120, 151, 151, 181, 181, 212, 212, 243, 243, 273, 273, 304, 304, 334, 334, 365.} ; time@units="days since 1900-01-01 00:00:00" ; time@calendar="NOLEAP" ; time@bounds="time_bnds"; time=time+(1980-1900)365 ; time_bnds[time,tbnds]=time_bnds[time,tbnds]+(1980-1900)365' infile.nc outfile.nc
In your example, I think you have missed the use of brackets {} when you specify nbnds[nbnds]
So should be: nbnds[nbnds]={74875.0,7490.0};
ncap2 -Oh -s 'defdim("time",1); time[time]=74875.0; time@long_name="Time"; defdim("nbnds",2); nbnds[nbnds]={74875.0,7490.0}; nbnds@long_name="Time Boundaries";' file1.nc file2.nc
To pass from the fixed size time dimension to an UNLIMITED time dimension you will use:
ncks -O --mk_rec time file2.nc file3.nc
I don't know how to perform this directly from ncap2 commands but would be interested in.
Regards
Patrick
Thank you, Patrick.
As far as I know, there is no way to specify creation from scratch of a record dimension in ncap2 (Henry will correct me if otherwise). This is an oversight that we will try to address soon. For now, follow Patrick's suggestion.
cz
HI Charlie,
For now I have added the definition of unlimited dim(s) to defdim()
as a hidden feature
When the size is negative this indicated an unlimited dim
e.g defdim("time", -10)
My view is that it opens up a few problems that need to be ironed out.
1) when unlimited dim isn't the first dim (netcdf4) then ncap2 bombs out
2) Cant redefine in Output an unlimited dim that is in Input
Once we have ironed out the problems then I guess we can define the
parser tokens LIMITED/UNLIMITED
and make the defdim call like:
defdim("time",10,UNLIMITED)
Any way give it a go ?
....Henry
On 29/10/14 15:45, Charlie Zender wrote:
Hi Henry,
Hi Henry,
This is a fine stopgap solution.
netCDF4 raises lots of issues for ncap2, and
one more such issue is negligible :)
I'm not sure exactly what you mean by point 2).
What does it mean to "redefine in Output" a dimension?
As long as what this user wants to do will work with
your new patch, then the documentation in your brief
note will suffice so interested users
can test this hidden feature (knowing the syntax may
later change).
Thanks!
c
Guys... your suggestions are amazing! Thank you so much... it works like a charm! :)
One last question: is it possible to add the "time" dimension to the "z" variable in my netcdf file? For instance, using the example below:
how can I change "float z(lat, lon) ;" into "float z(time, lat, lon) ;"?
netcdf test5 {
dimensions:
lat = 2 ;
lon = 3 ;
time = UNLIMITED ; // (1 currently)
nbnds = 2 ;
variables:
double lat(lat) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:actual_range = -90., 89.9 ;
double lon(lon) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:actual_range = 0., 359.9 ;
double nbnds(time, nbnds) ;
nbnds:long_name = "Time Boundaries" ;
double time(time) ;
time:long_name = "Time" ;
float z(lat, lon) ;
z:long_name = "z" ;
z:_FillValue = 9.96921e+36f ;
// global attributes:
:title = "Test 1" ;
:history = "Thu Oct 30 10:10:17 2014: ncks -O --mk_rec time test4.nc test5.nc" ;
:NCO = "4.3.7" ;
data:
lat = -90, -89.9 ;
lon = 0, 0.1, 0.2 ;
nbnds =
74870, 74945 ;
time = 74875 ;
z =
0.3161385, 0.290362, 0.340162,
0.3, 0.2, 0.23 ;
}
Never mind guys... I saw that this was covered in an earlier post: https://sourceforge.net/p/nco/discussion/9830/thread/0851525d/
This worked perfectly for me too
Just a side note... I just wanted to say how incredibly great it is to work with NCO! This tool is so powerful...
Just fyi, I wanted to share with others a link that I found that has some valuable "primers" for those like me that are starting to learn this nifty toolbox:
https://earthsystemcog.org/projects/dcmip-2012/netcdf
Gosh, err, thanks.
I was not aware of the DCMIP page on NCO.
Nice.