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

SPI index error: FitError: Optimization converged to parameters that are outside the range allowed by the distribution. #1567

Closed
1 task done
PraewKPT opened this issue Dec 21, 2023 · 6 comments
Assignees
Labels
support Questions and help for users/developers

Comments

@PraewKPT
Copy link

Setup Information

INSTALLED VERSIONS

python: 3.11.7
boltons: installed
bottleneck: 1.3.7
cf_xarray: 0.8.7
cftime: 1.6.2
click: 8.1.6
clisops: None
dask: 2022.02.0
flox: None
jsonpickle: 3.0.2
lmoments3: 1.0.6
numba: 0.58.1
pandas: 2.1.4
pint: 0.23
scipy: 1.9.3
sklearn: 1.3.2
statsmodels: 0.14.0
xarray: 2023.11.0
xclim: 0.47.0
Anaconda-based environment: no

Context

How can I fix this problem?
"FitError: Optimization converged to parameters that are outside the range allowed by the distribution."
I don't know where is the problem from?

Code of Conduct

  • I agree to follow this project's Code of Conduct
@PraewKPT PraewKPT added the support Questions and help for users/developers label Dec 21, 2023
@PraewKPT PraewKPT reopened this Dec 21, 2023
@aulemahal
Copy link
Collaborator

Hi @PraewKPT,

This error does not ring a bell to me, but may be my colleague who coded SPI knows about it. In any case, would you be able to provide a minimal example that raises the error ? What data are you using, is it shareable ? Could you show us what code you have and which parameters you use ?

Thanks.

@coxipi
Copy link
Contributor

coxipi commented Dec 21, 2023

Hi! It seems like a scipy error. I'll wait for details. It could be a bug on our side, but I suspect it could also be the data that is hard to fit? We'll see.

@PraewKPT
Copy link
Author

Thank you for your help. I am new to SPI.

@coxipi
Copy link
Contributor

coxipi commented Dec 22, 2023

Hi @PraewKPT, thanks for sharing more info.

  • Could you also show the python code you used to produce this? A bigger error message for context would be good too.
  • I'm assuming you won't get the error if you set method="APP", in SPI, e.g. xclim.atmos.standardized_precipitation_index(pr,...,method="APP",...) can you confirm this?
  • Can you isolate a small spatial region / a single pixel where the problem occurs? e.g. try your computation with:
pr = pr.isel(lat=slice(100,120), lon=slice(100,120)) # or something else that makes sense in your context

and see if you still have the error. Maybe your problem only happens on a few pixels and it would be hard to find it, so if you're not successful after trying a couple small regions, don't lose too much time on this. But if it works, it would be nice if you can simply share a small .nc file here.

Cheers!

@PraewKPT
Copy link
Author

Hi @coxipi , thank you for your advice.
I haven't found an error when I set method = "APP".

@coxipi
Copy link
Contributor

coxipi commented Dec 23, 2023

The method "APP" is an approximation. In the case of the gamma distribution, it's based on an approximation of the maximum likelihood formulation of the gamma parameters, see eq.22 here

@PraewKPT PraewKPT closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions and help for users/developers
Projects
None yet
Development

No branches or pull requests

3 participants