Non-Finite Error even with all Finite Data
Description
Hi - I am developing a code for fitting emission lines using astropy.modeling. I am using Gaussian1D models for individual emission-lines fitting and testing for extra components. When I use numpy version: 1.22.4 and astropy version: 5.2.1, I am getting the following error:
NonFiniteValueError: Objective function has encountered a non-finite value, this will cause the fit to fail!
Please remove non-finite values from your input data before fitting to avoid this error.
I checked all the data I have and there are no NonFinite values in my data. The same code is working fine, if I am using numpy version: 1.21.5 and astropy version: 5.0. I am not sure what changed with the updated versions?
Please tell me how I can use the updated versions of numpy/astropy without breaking my code.
Expected behavior
Specifically, I am fitting two-component model for each of the [SII]6716,6731 doublet. The error is produced when the data is very noisy.
How to Reproduce
No response
Versions
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import astropy; print("astropy", astropy.__version__)
import numpy; print("Numpy", numpy.__version__)
import erfa; print("pyerfa", erfa.__version__)
try:
import scipy
print("Scipy", scipy.__version__)
except ImportError:
print("Scipy not installed")
try:
import matplotlib
print("Matplotlib", matplotlib.__version__)
except ImportError:
print("Matplotlib not installed")
The code produces the error with the following versions:
Linux-5.14.21-150400.24.81_12.0.87-cray_shasta_c-x86_64-with-glibc2.31
Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0]
astropy 5.2.1
Numpy 1.22.4
pyerfa 2.0.0.1
Scipy 1.8.1
Matplotlib 3.6.2
The code works fine with the following versions:
Linux-5.14.21-150400.24.81_12.0.87-cray_shasta_c-x86_64-with-glibc2.31
Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46)
[GCC 9.4.0]
astropy 5.0
Numpy 1.21.5
pyerfa 2.0.0.1
Scipy 1.7.3
Matplotlib 3.5.1
The code is here - https://github.com/Ragadeepika-Pucha/DESI_linefitting/blob/main/py/fit_lines.py
Your fitting problem is encountering an non-finite output value during the fit iteration process.
Is there a way to get around that?
Not easily. I suggest that you try one of the other non linear fitters, the TRFLSQFitter is a bit more well behaved and uses the default scipy now suggests.
@WilliamJamieson , wasn't there an option to disable this feature for backward compatibility?