insert missing date
Added by kunal bali over 6 years ago
Dear CDO users,
I have the data of one season from June to September (JJAS) for the period 2000 2017. But in that data, one date is missing i.e. 2004-09-25. So how can I add this missing date with NaN values to the given file?
Replies (5)
RE: insert missing date - Added by Karin Meier-Fleischer over 6 years ago
Hi Kunal,
you can extract the timestep before the missing one and set all values to missing value. Then set the time axis to the missing date and merge it with your data file. Using a value range which doesn't fit your data value range will set all values to missing value.
You have to modify the setvrange values. Here in my test I use data with a value range 240-310 so I set the setvrange outside to -100-0:
cdo -O -settaxis,2004-09-25 -setvrange,-100,0 -selday,24 -selmonth,9 -selyear,2004 infile.nc tmp2.nc cdo mergetime infile.nc tmp2.nc new_infile.nc
Maybe there is another way but it works.
-Karin
RE: insert missing date - Added by kunal bali over 6 years ago
Yeah, that would work. Thanks for this suggestion.
But if we have more than one missing date/timesteps with different time periods (i.e. large datasets with so many missing timesteps)then how can we add those time steps. Suppose file1.nc has 2061 time steps and file2.nc has 2032 time steps then how to make two files with same timesteps. Every time splitting the timesteps would be the time-consuming process.
RE: insert missing date - Added by Karin Meier-Fleischer over 6 years ago
You should write a shell script to retrieve from your two files the timesteps and see which timesteps are missing in file2.nc.
Assume file1.nc has 2061 time steps and file2.nc has 2032 time steps:
...
cdo -s showyear file1.nc | xargs -n1 > times_file1
cdo -s showyear file2.nc | xargs -n1 > times_file2
comm -23 times_file1 times_file2 > missing_times
...
Loop over the missing time steps.
-Karin
RE: insert missing date - Added by jyoti lodha about 5 years ago
Hi
How can I add multiple dates of different year and month using ksh script. Please share one example for it. Wait for a reply. Thanks
RE: insert missing date - Added by Karin Meier-Fleischer about 5 years ago
Hi Jyoti,
you can use a loop in your ksh script to insert the wanted days and months. But you have to do this little work by yourself, we don't have enough time to provide everything. Sorry.
-Karin