find the frequency of dry days based on spi index
Added by Nurul Ain over 3 years ago
Hi, how can I find the number of value of -1 untill -4 from my data?
Replies (5)
RE: find the frequency of dry days based on spi index - Added by Karin Meier-Fleischer over 3 years ago
Hi Nurul,
I would guess that you can create a kind of a mask for each timestep where values in your given range will be 1 and all others 0, and pipe the result to timsum.
For values between -4 and -1:
cdo -timsum -setrtoc2,-4,-1,1,0 infile outfile
-Karin
RE: find the frequency of dry days based on spi index - Added by Karin Meier-Fleischer over 3 years ago
Another way, e.g for variable pr:
cdo -timsum -expr,'pr=((pr>=-4.0) && (pr<=-1.0)) ? 1.0 : 0.0' infile outfile
RE: find the frequency of dry days based on spi index - Added by Nurul Ain over 3 years ago
ya, and then after i change all value in range needed as 1, can i calculate how many 1 were there? and divide by 420
RE: find the frequency of dry days based on spi index - Added by Karin Meier-Fleischer over 3 years ago
Have you tried the examples above with your data? Did you have a look at the result with ' cdo info outfile '?
Ok, let's start with the explanation. First, you have to know that you need to read the operator list from right to left! The output of each operator is internally piped to the next operator.
1. Set all values between -4 and -1 to value 1 and all other values outside the range to 0
-expr,'pr=((pr>=-4.0) && (pr<=-1.0)) ? 1.0 : 0.0'
2. ' Add of the 1s ' - means to compute the sum of the values for each grid cell for all time steps
-timsum
3. To divide the values by a constant 420
-divc,420
CDO command line at the end:
cdo -divc,420 -timsum -expr,'pr=((pr>=-4.0) && (pr<=-1.0)) ? 1.0 : 0.0' infile outfile
It is always a good starting point to read the FAQ and the User guide.
RE: find the frequency of dry days based on spi index - Added by Nurul Ain over 3 years ago
thank you! Ive tried but I also currently trying to prevent from NaN is changing to 0 too.