Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monthly sum of wet days from daily data using Climate Data Operators (CDO)

I have climate data with a daily temporal resolution and would like a count of days that have precipitation (e.g., greater than 1mm/day) by month and by year.

I've tried eca_pd,1 and eca_rr1, but these commands return wet-day totals for all years.

For example, cdo eca_pd,1 infile outfile

Is there a command to return wet-days for each month and/or year?

like image 403
derelict Avatar asked Dec 07 '22 10:12

derelict


2 Answers

You can accomplish this task with CDO's masking function, for more details beyond the answer below, you can also refer to my video guide on masking using cdo.

The first step is to make an equivalent file with 1 if P>threshold (1mm/day in your case) and 0 otherwise. For this we use the "greater than or equal to a constant" gec function (or ge="greater than" if you prefer):

cdo gec,1 input.nc mask.nc 

(assuming units are mm/day in your input file).

Then you can simply sum this mask over the period (months, years etc) that you want your statistic

cdo monsum mask.nc nwetdays_mon.nc 
cdo yearsum mask.nc nwetdays_year.nc

Of course you can pipe this if you like to do this on one line: e.g.

cdo monsum -gec,1 input.nc nwetdays_mon.nc 

We can take this even further if you want to work out the climatology for a particular month. If you have a multiyear dataset then you can use the wonderful "ymonstat" commands. So for example, once you have calculated your monthly series of wet days above, you can calculate the average for each month with

cdo ymonmean nwetdays_mon.nc nwetdays_mon_clim.nc

You can then difference the series from this monthly climatology to give you the anomaly of wet days in each month over the series

cdo ymonsub nwetdays_mon.nc nwetdays_mon_clim.nc nwetdays_mon_anom.nc

I hope that helps!

(ps: I usually always find it is easier to calculate these kinds of statistics directly with CDO in this way, I rarely find that the built in climate functions calculate exactly the statistic as/how I want).

like image 163
Adrian Tompkins Avatar answered Dec 28 '22 07:12

Adrian Tompkins


With NCO's ncap2, create a binary flag then total it in the desired dimension(s):

ncap2 -s 'rainy=(precip > 1);rainy_days=rainy.total($time)' in.nc out.nc
like image 32
Charlie Zender Avatar answered Dec 28 '22 08:12

Charlie Zender