-
Notifications
You must be signed in to change notification settings - Fork 59
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
fitkwargs are not propagated to lmoments3 lmom_fit function #2043
Comments
Hi Sascha, I didn't check specifically with Lmoments3 because of the licensing issues. I think that specifically for
I guess that for other distributions, a
In this sense, the previous argument |
Did you try with a string |
Ah, sorry, I read too fast. I do think we will hit a problem specifically with lmom-gamma, but currently, But I guess the way that lmoments works, you don't take starting values for an optimization process, you just compute moments of you data and use them in some formulas that give you the parameters? So |
So, right now, we accept
elif method == "PWM":
# ...
if "floc" in fitkwargs and type(dist) == "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 = list(dist.lmom_fit(x - fitkwargs["floc"]).values())
params["loc"] = fitkwargs["floc"]
else:
params = list(dist.lmom_fit(x).values()) I don't think we plan on having a full-fledged support for |
I agree with this solution! I support a warning if Don't you need to edit |
I have to see how That is,
I have updated my previous comment to reflect this |
see #2045 |
Wow that was fast. I actually agree and the easiest solution would probably be to even just raise an error. When the floc parameter is provided for PWM. I currently just apply the offset before calling But I see you already put in a solution 👍 |
Addressing a Problem?
I am using
xclim.indices.stats.standardized_index_fit_params
to compute SPI and SPEI. I am calling it withmethod='PWM', dist=lmoments3.distr['gam']
and sometimes get errors where the L-moments are invalid (lmoments3/distr.py:1207). This is due to potentially negative values.I have seen two situations for negative values:
water_budget = pr - pet <0
rolling.mean
gives negative values on non-negative array. pydata/xarray#3855A common solution seems to be adding an offset (e.g. I can add a large value for
water_budget+=1000
or a very small numberpr+=0.0001
for the second case). Previously xclim supported anoffset
parameter that is soon to be deprecated.I couldn't really figure out a good way to provide a scalar with units but using a one-dimensional DataArray with units attributes worked.
The suggest alternative for the deprecated offset is using
fitkwargs=dict(floc= -offset)
but this parameter doesn't seem to be propagated to the lmom_fit function when providingmethod='PWM'
to _fitfunc_1d.Potential Solution
I am a little confused to how the lmoments3 part works but the
GammaGen
inherits fromscipy.stats._continuous_distns.gamma_gen
so we might be able to propagate it the argument to the internal fit. Another solution that could also solve the lmoments3 license issue, is using scipy.stats.lmoment introduced in SciPy 1.15 and deprecating lmoments3.Additional context
No response
Contribution
Code of Conduct
The text was updated successfully, but these errors were encountered: