Project

General

Profile

Calculate yearly cumulative sum

Added by Pauline Millet over 3 years ago

Hello all,

I'd like to get the day of the year when a cumulative target temperature is reached, i.e. "get the day of the year when 200°C is accumulated since the beginning of the year".

`timcumsum` is interesting to compute the cumulative sum but I didn't find its equivalent to compute it yearly. I then have to loop over the years to compute my yearly indicator, here is the code I run for the calculation:

for year in years_list:
    year_val = cdo.yearmin(
        input = f"-setctomiss,0 -muldoy -gec,200 -timcumsum -select,year={year} {ifile}", 
        returnArray = 'tas'
    )

I finally concate results for each year to get a single output.

Is there a way to do something similar with CDO, avoiding looping over years?

Thanks,
Pauline


Replies (3)

RE: Calculate yearly cumulative sum - Added by Pauline Millet over 3 years ago

Hello,
I'm just popping up this post in case anyone has an answer...
Thanks,
Pauline

RE: Calculate yearly cumulative sum - Added by Ralf Mueller over 3 years ago

sorry for my ignorance Pauline, but I don't think there is an better solution here. Since every timestep within a year has to be taken into account (because it could be matching one) a yearly statistics won't help you.

But you only read from your input, so you could easily parallelize the loop over the years. Just compute the years of the input with cdo.showyear(....) and loop over them in a multiprocessing.Pool

best wishes
ralf

RE: Calculate yearly cumulative sum - Added by Pauline Millet over 3 years ago

Thanks for the suggestion Ralf!

    (1-3/3)