Project

General

Profile

How to extract every nth time steps

Added by ep gupal almost 2 years ago

I can not find a way to use seltimestep in order to extract every nth timestep of a netcdf file. For example, if I have the following time steps

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, ...

I would like to extract every 2 timesteps starting from 1st timestep

0,2,4,6,8,10,12,14,16, ...

The command that I was playing around with is

cdo seltimestep,1/2/1000 (assuming I have total 1000 timesteps)

and it does not work as I intended. How do I do this?


Replies (2)

RE: How to extract every nth time steps - Added by ep gupal almost 2 years ago

Nevermind, I found out how to do it. Look at this post (https://code.mpimet.mpg.de/boards/1/topics/4586) as a reference, I found out the solution for my question.

cdo seltimestep,1/1000/2 infile.nc outfile.nc

So, in general case

cdo seltimestep,first_timestep/end_timestep/nth_time_step infile.nc outfile.nc

RE: How to extract every nth time steps - Added by Karin Meier-Fleischer almost 2 years ago

Good that you already found the solution! :)

You can also use the select operator with timestep:

cdo -select,timestep=1/1000/2 infile.nc outfile.nc
    (1-2/2)