Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support freq="W" in standardized indices #1952

Merged
merged 10 commits into from
Oct 17, 2024
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ New features and enhancements
* ``xclim.indices.run_length.runs_with_holes`` allows to input a condition that must be met for a run to start and a second condition that must be met for the run to stop. (:pull:`1778`).
* New generic compute function ``xclim.indices.generic.thresholded_events`` that finds events based on a threshold condition and returns basic stats for each. See also ``xclim.indices.run_length.find_events``. (:pull:`1778`).
* ``xclim.core.units.rate2amount`` and ``xclim.core.units.amount2rate`` can now also accept quantities (pint objects or strings), in which case the ``dim`` argument must be the ``time`` coordinate through which we can find the sampling rate. (:pull:`1778`).
* `xclim.indices.stats.standardized_index` now supports a weekly resampling frequency. Only standard calendar is supported for this mode. (:issue:`1892`, :pull:`1952`)
coxipi marked this conversation as resolved.
Show resolved Hide resolved

Bug fixes
^^^^^^^^^
Expand Down
5 changes: 5 additions & 0 deletions xclim/indices/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def preprocess_standardized_index(
group = "time.dayofyear"
elif compare_offsets(final_freq, "==", "MS"):
group = "time.month"
elif compare_offsets(final_freq, "==", "W"):
group = "time.week"
else:
raise ValueError(
f"The input (following resampling if applicable) has a frequency `{final_freq}` "
Expand Down Expand Up @@ -910,6 +912,9 @@ def reindex_time(da, da_ref, group):
elif group == "time.month":
da = da.rename(month="time").reindex(time=da_ref.time.dt.month)
da["time"] = da_ref.time
elif group == "time.week":
da = da.rename(week="time").reindex(time=da_ref.time.dt.week)
da["time"] = da_ref.time
# I don't think rechunking is necessary here, need to check
return da if not uses_dask(da) else da.chunk({"time": -1})

Expand Down
Loading