grizli icon indicating copy to clipboard operation
grizli copied to clipboard

Updating to Polynomial

Open TheSkyentist opened this issue 1 year ago • 2 comments

As of SciPy 1.12.0 polyfit and polyval can no longer be directly imported from SciPy. This caused import errors when running grizli. I suspect this is due to the fact that polyfit and polyval are part of the old polynomial API, which has been upgraded with NumPy Polynomial package, primarily resulting in greater numerical stability. While I could have just fixed the imports, I went through and updated the code to use the new Polynomial API. If preferred, I can simply replace the scipy imports with the correct/not broken numpy imports.

TheSkyentist avatar Feb 06 '24 15:02 TheSkyentist

I like the modernization idea, but the wholesale changes to the new Polynomial behavior are a bit risky, particularly in the way the order of the polynomial coefficients are interpreted is exactly reversed! Those coeffs[::-1] throughout aren't pretty, but at least everything (sort of) works!

Could we just switch to from numpy.polynomial.polynomial import polyfit, polyval for now and file switching to the Polynomial objects as a WIP Issue?

gbrammer avatar Feb 10 '24 11:02 gbrammer

Sounds good, I've submitted PR #207 to address the short-term issues, but will continue testing against this PR and keep this updated.

TheSkyentist avatar Feb 11 '24 13:02 TheSkyentist

This PR now passes all CI checks and has been tested on real data to ensure it gives the same results.

TheSkyentist avatar May 31 '24 15:05 TheSkyentist

Thanks for keeping an eye on this. Can you update minimum versions on the numpy and scipy dependencies in setup.cfg to ensure compatibility with these changes (e.g., cumtrapz > cumulative_trapezoid)? I added scipy<1.14 the other day to fix a bug in the external (and apparently stale) peakutils module, which uses scipy.integrate.simps that has been renamed to simpson.

gbrammer avatar Jun 27 '24 09:06 gbrammer

This is a good point, we actually maintain greater compatibility with this change. The "new" Polynomial syntax has been around in NumPy since 1.4, which is over 10 years old at this point. It's true that scipy has finally removed the deprecated "simps/cumtrapz" syntax, I've forked peakutils and made the necessary updates, I wonder if we can pull from there for now. I wonder if there is a more modern package with the same functionality.

TheSkyentist avatar Jun 27 '24 13:06 TheSkyentist

I've just pushed the change requiring NumPy >=1.4. There are likely other parts of grizli that would require newer NumPy versions, but this is a start.

TheSkyentist avatar Jun 27 '24 13:06 TheSkyentist

Thanks. Can you find the minimum scipy needed for cumulative_trapezoid?

gbrammer avatar Jun 27 '24 17:06 gbrammer

Scipy 1.6 introduced the new scipy.integrate.

TheSkyentist avatar Jun 28 '24 09:06 TheSkyentist

Merged! Thanks again, @TheSkyentist.

gbrammer avatar Jun 28 '24 14:06 gbrammer