Ouranosinc / xclim

Library of derived climate variables, ie climate indicators, based on xarray.
https://xclim.readthedocs.io/en/stable/
Apache License 2.0
322 stars 56 forks source link

Please add option for 'weekly' frequency in the SPI family of models #1892

Open C15H24 opened 2 weeks ago

C15H24 commented 2 weeks ago

Addressing a Problem?

No response

Potential Solution

the function standardized_precipitation_index accepts freq = 'W' as signifying the nature of the groupings is weekly - and any downstream adjustments that would need to be made to validate the output

Additional context

Many projects in government are beginning to operate and produce products on a weekly basis

Contribution

Code of Conduct

coxipi commented 2 weeks ago

Hi! We can add this indeed. Just a couple caveats:

  1. It will only work with standard calendars, as .resample(time="W") and .groupby("time.week") is not yet compatible with cf-time (https://github.com/pydata/xarray/discussions/6375)
  2. Since there is not an integer number of weeks in a year, using .resample(time="W").mean() the days included in week1 can vary from year to year, e.g.
    
    # days included in week 1 between 2000 and 2002
    2000: [Jan 3, Jan 9]
    2001: [Jan 1, Jan 7]
    2002: [Dec31 2001, Jan 6]
    ...

sometimes Jan 1rst is not included, sometimes Week1 includes days from december, etc. I'm curious to know if this is what you envision when you consider weekly groupings.
C15H24 commented 4 days ago

Yes, I envision strict adherence to ISO-8601 weeks :) So, looks like it would need to be implemented upstream (cftime.datetime) first?

Thank you for your response