Project

General

Profile

CDO : selection of time steps based on a condition

Added by Derrick Danso about 5 years ago

Hi,

I have a netcdf file with 2 variables; "var1" and "var2". What I would like to do is to select only time steps (for both var1 and var2) when "var1" meets a certain condition (e.g. var1 > 0).
Could this be done with cdo? If yes, how?

Thank you.


Replies (1)

RE: CDO : selection of time steps based on a condition - Added by Ralf Mueller about 5 years ago

hi Derrick!

The short answer is: No. BUT you can come close to this in other ways:

  • create a multidimensional mask file based on your criteria (like 'cdo -gtc,0') and mask all other files (locations in all timesteps) and do your processing on the remaining locations, only
  • create a list of timesteps (integers), oder dates/times for which the criteria is fulfilled. Use the above gtc or any other useful operators, that creates a 0-1-mask and take the fldmax of it. This way you will get a timeseries of 1 and 0 along the original time axis. Now use the operators call
     cdo outputkey,timestep,value <infle>
    and pipe it through grep for like
    cdo outputkey,timestep,value <infile> | grep '1'
    with a little bit more text-porcesing you can get a list of corresponding timesteps as integers. With that list you can preppend all your call with
     -seltimestep,<comma-separated-list-of-integers>
    et voila, you have your timestep selection based on a criteria

hth
ralf

you might also check the expr operator, it has some conditional options via the ternary operator.

hth
ralf

    (1-1/1)