Project

General

Profile

How to sum precipitation for events of a given duration only

Added by Michelle Irizarry 6 months ago

Hi!

I have a netcdf file with hourly precipitation data. This is what I want to do:

1) First, I want to identify the hours where precipitation is above a threshold (let's say 1 mm):
cdo gtc,1 tempor.nc temp1.nc

2) Then, I want to identify events (defined as consecutive hours above the threshold) that last exactly two hours, and I want to sum the precipitation values for those two hours. This would give me the precipitation totals for 2-hour events. Note that I am not looking for 2 consecutive hours within longer events, but events that last exactly 2 hours above the threshold.
This is where I am stuck.
cdo consects temp1.nc temp2.nc gives me the number of consecutive hours above the 1 mm threshold, but only writes out the number of consecutive hours on the last hour of the period.
cdo consecsum temp1.nc temp2.nc gives me the count of consecutive hours so far that are above the 1 mm threshold. So, this might be useful, if I can somehow only keep values for the first two timesteps when the output from consecsum is a sequence like this: 1, 2, 0. I do not want to identify the first two timesteps when I have 1, 2, 3, etc. because those events are longer than 2 hours. I only want to identify the first two timesteps in sequences like this: 1, 2, 0.
 
3) Finally, for each year, I want to average the precipitation totals for events that last exactly 2 hours.
I know I can use cdo yearmean for this last step.

Any way of doing this all (steps 1-3) generically?
I want to do this process several times, first identify all events exactly 2 hours long, sum the precipitation over the 2 hours, then average over a year.
I then want to identify all events exactly 3 hours long, sum the precipitation over the 3 hours, then average over a year...
I then want to identify all events exactly 6 hours long, sum the precipitation over the 6 hours, then average over a year...
etc.

Any help would be greatly appreciated.

I am attaching tempor.nc which consists of just one grid location, but I want to do the above for a gridded dataset of hourly precipitation.

Thanks, Michelle

tempor.nc (23.9 MB) tempor.nc

Replies (2)

RE: How to sum precipitation for events of a given duration only - Added by Estanislao Gavilan 6 months ago

Hi Michelle,

you have tricky question here. I am no sure how to do it with cdo, but I can help you a little bit. You can easily keep the sequence 1,2 doing this.

cdo ltc,3 consecsum gtc,1 tempor.nc temp1.nc

that will give you a mask such as

0,1,0,0,1,1,0,0

The problem is how to remove the 1 for the sequence 0,1,0 or for other numbers such as as 3 or 6. You could try to find the last hour and then get the backward sum. For example for 2 you do

cdo eqc,2 consecsum gtc,1 tempor.nc temp1.nc

0,0,0,0,0,1,0,0

Subsequently, you can find the time where the mask is equal to 1 and sum the previous time step using timsum and -seldate. You will probably have to use a bit of bash or python to make it work. For other numbers such as 3 or 6 you will have to sum the last 3 or 6 time steps. Again, as long as you know the time you can do it with seldate and timsum.

Best regards,

Estanislao

RE: How to sum precipitation for events of a given duration only - Added by Michelle Irizarry 6 months ago

Thank you Estanislao. I have been wracking my brain trying to figure this one out.
I will play a bit with those commands you recommend to see if I can make it work. I want to try to do the processing with CDO as much as possible since the grid is huge and it would be too slow in R or Python to do the analysis unless I do the work on a computer cluster.

Thanks so much for your time and help,
Michelle

    (1-2/2)