Closed nusbaume closed 5 months ago
@nusbaume --- I actually was just doing this for something else the other day. Not sure whether you've implemented or not, but I found using Xarray's "weighted" along with the time accessor days_in_month
worked well:
def time_averaging(fld):
timeweights = fld.time.dt.days_in_month
return fld.weighted(timeweights).mean(dim='time')
This is been implemented in the PR that I submitted (in plot_global_latlon.py). However, I needed to change the time associated with the climo filesm as it had previously only been indexed (1-12) rather than having a true datetime associated.
I believe the functions due the same thing, this is my implementation. I think @brianpm still needs an associated datetime also.
month_length = mdata.time.dt.days_in_month
weights = (month_length.groupby("time.season") / month_length.groupby("time.season").sum())
mseasons[s] =(mdata * weights).groupby("time.season").sum(dim="time").sel(season=s)
I believe this has now been implemented everywhere. There's functionality in plotting_functions
to apply weights, and it is an option in the config file (on by default, I believe).
New feature type
New climatology method or climatology enhancement
What is this new feature?
As requested by @WillyChap, the ADF needs the ability to weight seasonal averages (e.g. DJF) based on the number of days in each month.
Assistance required?
No, I will make a PR when the feature is ready
Extra info
No response