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

Change lmoments3 behaviour with fitkwargs #2045

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ Changelog

v0.55.0 (unreleased)
--------------------
Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`)
Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Éric Dupuis (:user:`coxipi`).

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* New function ``ensemble.partition.general_partition`` (:pull:`2035`)

Internal changes
^^^^^^^^^^^^^^^^
* There is now a warning stating that `fitkwargs` are not employed when using `lmoments3` distribution. One exception is the use of `floc` which is allowed with the gamma distribution. `floc` is used to shift the distribution before computing fitting parameters with the lmoments3 distribution since `loc=0` is always assumed in the library. (:issue:`2043`, :pull:`2045`).

v0.54.0 (2024-12-16)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`), Sascha Hofmann (:user:`saschahofmann`).
Expand Down
15 changes: 15 additions & 0 deletions src/xclim/indices/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ def _fitfunc_1d(arr, *, dist, nparams, method, **fitkwargs):
# lmoments3 will raise an error if only dist.numargs + 2 values are provided
if len(x) <= dist.numargs + 2:
return np.asarray([np.nan] * nparams)
if (type(dist).__name__ != "GammaGen" and len(fitkwargs.keys()) != 0) or (
type(dist).__name__ == "GammaGen"
and set(fitkwargs.keys()) - {"floc"} != set()
):
warnings.warn(
"Lmoments3 does not use `fitkwargs` arguments, except for `floc` with the Gamma distribution."
)
if "floc" in fitkwargs and type(dist).__name__ == "GammaGen":
# lmoments3 assumes `loc` is 0, so `x` may need to be shifted
# note that `floc` must already be in appropriate units for `x`
params = dist.lmom_fit(x - fitkwargs["floc"])
params["loc"] = fitkwargs["floc"]
params = list(params.values())
else:
params = list(dist.lmom_fit(x).values())
params = list(dist.lmom_fit(x).values())
coxipi marked this conversation as resolved.
Show resolved Hide resolved
elif method == "APP":
args, kwargs = _fit_start(x, dist.name, **fitkwargs)
Expand Down
Loading