selecting multiple timesteps of the same date/timestep
Added by Andy Richling over 2 years ago
Hello,
I want to select multiple timesteps (in my case days) from a netCDF File, which will also select duplicate entries if given.
Generally I use
cdo seltimestep,1,2,3,4 IN.NC OUT.NC
or cdo select,date=YYYY-MM-DD,YYYY-MM-DD IN.NC OUT.NC
to select timesteps. This works great to select multiple timesteps. But if I enter the same date/timestep twice or more often, then in the OUT.NC the timestep/date exists only once.
Is there an elegant way to also get the exact timesteps I have selected. Or does this only work via iterating the cdo command over each timestep individually I want to select and then make use of cat command?
Thanks,
Andy
Replies (4)
RE: selecting multiple timesteps of the same date/timestep - Added by Karin Meier-Fleischer over 2 years ago
Hi Andy,
CDO works with streams that means that you have to 'read and think' from the right to the left.
Short example, assume your infile.nc contains 10 time steps
cdo seltimestep,1,2,3,4 infile.nc outfile.nc
returns a netCDF file with 4 time steps and the 'rest' gets lost.
If you to do something like
cdo -seltimestep,1,2 -mulc,10 -seltimestep,1,2,3,4 infile.nc outfile.nc
that means (from right to left)
1. select time step 1,2,3, and 4 from infile.nc
2. pipe the result to the mulc operator (= multiply fields by 10)
3. pipe the result to the seltimestep operator to select the first two time steps
4. write the result to outfile.nc
I would not recommend to do such operations at once!
RE: selecting multiple timesteps of the same date/timestep - Added by Andy Richling over 2 years ago
Hi Karin,
thanks for the quick response and the explanation.
But I think that's not the issue I wanted to address, or I did not got it. I guess my question was a bit misleading, so I will try it again
As you said, I select time steps "1,2,3,4" from an infile with
cdo seltimestep,1,2,3,4 infile.nc outfile.nc
and get the outfile with the selected timesteps "1,2,3,4".
Now I do the same thing, but I want select certain timesteps more than once. Eg. timestep "3" should be selected 2 times:
cdo seltimestep,1,2,3,3,4 infile.nc outfile.nc
In that case, the outfile also contains timestep "1,2,3,4" once. I was expecting the outfile will contain timestep "1,2,3,3,4". That means timestep "3" will occur 2 times in the outfile. But that's not the case.
At the the moment I process the cdo command for each timestep individually to get the outfile I want.
Something like that:
for i in 1 2 3 3 4 cdo cat -seltimestep,i infile.nc outfile.nc
But I was hoping to avoid iterating the select-command over each timestep by using the comma-separated timesteps ("1,2,3,3,4") in the seltimestep command.
I hope that's now a bit better understandable.
Regards,
Andy
RE: selecting multiple timesteps of the same date/timestep - Added by Karin Meier-Fleischer over 2 years ago
One question: why do you want to select one timestep multiple times?
Usually, you want to avoid duplicate time steps, and IMO CDO do that when selecting the time steps.
RE: selecting multiple timesteps of the same date/timestep - Added by Andy Richling over 2 years ago
I agree with you, generally it makes sense to remove duplicate entries, but I thought there is maybe an option to enable/disable it as it is done in the mergetime command using the environment variable SKIP_SAME_TIME.
In my special case I select certain time steps to make composites. I also use the workaround for randomly generated bootstrap samples (with replacement). Due to the replacement of time steps I need also the duplicated entries.
But it seems the command was not made for such a purpose.