Hi there. I am processing data from a global model. I need to change the value of just the first forecast lead time value in a NetCDF file from its current value of 0.04166667 (hours) to 0 (hours), in order for a downstream application to properly identify and read in my first record as the hour0 record. For this particular application, the difference between the first timestep (0.04166667h) and what would truly be the initial field (0h) does not matter scientifically, but from a data processing standpoint for the downstream application, it kills my workflow. So I just need to adjust that one time value from 0.04166667 to 0.
Here is my "time:units" line from an ncdump:
time:units = "hours since 2023-09-04 18:00:00"
And here is the first line from my list of forecast time values from the ncdump:
Use parentheses not brackets for array subscripting. Documentation is here http://nco.sf.net/nco.html#ncap2. Try this: ncap2 -O -s 'time(0)=0.0' ~/nco/data/in.nc ~/foo.nc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay, I figured it out. In case anyone has a similar issue, I'll explain what I did. I abandoned trying to use ncap2 and looked into using cdo instead. Here is the command that worked using cdo:
Hi there. I am processing data from a global model. I need to change the value of just the first forecast lead time value in a NetCDF file from its current value of 0.04166667 (hours) to 0 (hours), in order for a downstream application to properly identify and read in my first record as the hour0 record. For this particular application, the difference between the first timestep (0.04166667h) and what would truly be the initial field (0h) does not matter scientifically, but from a data processing standpoint for the downstream application, it kills my workflow. So I just need to adjust that one time value from 0.04166667 to 0.
Here is my "time:units" line from an ncdump:
time:units = "hours since 2023-09-04 18:00:00"
And here is the first line from my list of forecast time values from the ncdump:
time = 0.04166667, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
All other forecast lead times after the first one should remain the same.
When I try to use ncap2, I get the following error:
$ ncap2 -s 'time[1]=0' nggps2d_ord1.nc testfix.nc
Command-line script:1:6: unexpected token: 1
Obviously I'm doing something wrong with this command. Can someone provide assistance on this?
Thanks!
Use parentheses not brackets for array subscripting. Documentation is here http://nco.sf.net/nco.html#ncap2. Try this:
ncap2 -O -s 'time(0)=0.0' ~/nco/data/in.nc ~/foo.ncOkay, I figured it out. In case anyone has a similar issue, I'll explain what I did. I abandoned trying to use ncap2 and looked into using cdo instead. Here is the command that worked using cdo:
cdo settaxis,2023-09-04,18:00:00,1hour nggps2d_ord1.nc testfix.nc
And after doing this, the first line from my list of forecast values from an ncdump of testfix.nc yields this:
time = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
And synoptic plots of the data all check out okay.