Extract a year from ncdf and make it constant for the whole time series
Added by Felix Leung over 7 years ago
I have a netcdf monthly data from 1960-2100. I want to extract the 1960 data and make it the same for each year. How do I do it? How to extract the 12 months in a year and replace all years? Thanks. Please let me know if it is not clear.
Replies (6)
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Ralf Mueller over 7 years ago
Hi Felix!
- select the year:
cdo -selyear,1960 ifile 1960_DataFile.nc
- I would then split the large file per year with
cdo splityear
- loop over all years except 1960 with something like this
for year in $(seq -w 1961 1 2100); do cdo setyear,$year 1960_DataFile.nc ${year}_DataFile.nc ; done
- concat all files with
cdo cat '*_DataFile.nc' all.nc
hth
ralf
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Felix Leung over 7 years ago
Thanks for your quick reply! Why do you need to split the large file in step 2?
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Ralf Mueller over 7 years ago
good point - forget about it ;-) I was on the wrong track to the solution ....
sorry for the entropy,
ralf
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Felix Leung over 7 years ago
Thank you very much! It works!
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Felix Leung over 7 years ago
Hi Ralf,
I have tried it with a different .nc file but I got this error when I do the cdo cat
Warning (cdfInqContents) : 5 dimensional variables are not supported, skipped variable resp_s!
Warning (cdfInqContents) : 5 dimensional variables are not supported, skipped variable cs!
How to make it supported?
RE: Extract a year from ncdf and make it constant for the whole time series - Added by Ralf Mueller over 7 years ago
it depends: 5-dims are not supported by underlying IO library CDI. I guess, you will have to use another tool like some NCO programm.
If your time axis is relative, you could simple copy the 1960-file and change the time axis meta date, i.e. the reference date
hth
ralf