Project

General

Profile

Extract conditional variables

Added by Ulf Graewe almost 3 years ago

Dear wizards,
I am faced with the challenge to extract dependent variables.
I have hourly maps of water level and wave height. Since I will do a bit of extreme value analysis, I need (for the sake of simplicity on monthly basis) the water level at maximum wave height. How to do that?

To find the maximum values for each month is easy. However, since both variables are not independent, there might be a time shift between both and I can not simply do cdo timmax on both variables.
Currently I do:
#extract variables
ncks -O -v z data.19840301.nc4 ssh.nc
ncks -O -v waveH data.19840301.nc4 wav.nc

cdo -s timmax wav.nc wav.max.nc
#get the index of the max wave heigth
cdo -s ge wav.nc wav.max.nc wav.mask.nc
  1. mask ssh to zero, except at max wave heigth
    cdo -s mul ssh.nc wav.mask.nc ssh.masked.nc
  2. blank out zeros, to account for ssh below mean sea level
    cdo -s setctomiss,0 ssh.masked.nc ssh.masked.miss.nc
  3. find the max value in the masked field
    cdo -s timmax ssh.masked.miss.nc ssh.max.nc

Is there any smarter way to do that?
How to do that if I like to have the daily max values? Do I have to wrap a cdo daysplit around it and loop over the individual days?

Cheers,
ulf


Replies (1)

RE: Extract conditional variables - Added by Karin Meier-Fleischer almost 3 years ago

Hi Ulf,

I would say a little bit. The computations 1.-3. from above can be shortened to

cdo -s -timmax -setctomiss,0 -mul ssh.nc wav.mask.nc ssh.max.nc

If you want the daily maximum values use daymax instead of timmax.

    (1-1/1)