euratom-software / calcam

Python package of spatial calibration tools for science & engineering camera systems.
Other
32 stars 15 forks source link

CI/CD warning messages from SciPy/Matplotlib deprecation #132

Open pfbuxton opened 1 week ago

pfbuxton commented 1 week ago

While running CI/CD testing (for my own packages) I see these warnings. Normally best to fix these things before they break when SciPy/Matplotlib are updated.

calcam/gui/core.py:29: DeprecationWarning: Please import center_of_mass from the scipy.ndimage namespace; the scipy.ndimage.measurements namespace is deprecated and will be removed in SciPy 2.0.0.

I have tested and can confirm that on SciPy 1.14.1, this replacement works:

from scipy.ndimage.measurements import center_of_mass as CoM  # original
from scipy.ndimage import center_of_mass as CoM  # new

calcam/raycast.py:32: DeprecationWarning: Please import netcdf_file from the scipy.io namespace; the scipy.io.netcdf namespace is deprecated and will be removed in SciPy 2.0.0.

I have tested and can confirm that on SciPy 1.14.1, this replacement works:

from scipy.io.netcdf import netcdf_file  # original
from scipy.io import netcdf_file  # new

calcam/gui/image_analysis.py:46: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed in 3.11. Use matplotlib.colormaps[name] or matplotlib.colormaps.get_cmap() or pyplot.get_cmap() instead.

The warning message originates from here, calcam/gui/image_analysis.py#L26. Where there is a try/except for importing:

try:
    from matplotlib.cm import get_cmap
except ImportError:
    from matplotlib import colormaps as mpl_cmaps
    get_cmap = mpl_cmaps.get_cmap

what is happening is you are trying to do the import using the old API and then falling back to the new API if there is a failure. But we are in the transition period where the first try succeeds with a warning message. If you reverse the try/except you will test the new API first.

Hope this is of help.

ssilburn commented 1 week ago

Hi Peter,

Thanks very much for flagging these, the first two weren't on my radar and I agree swapping the try/except order for get_cmap seems sensible. Since these are currently only depracation warnings I don't think it's urgent enough to do a special release, but will include them in the next release (or do another release when Scipy 2.0.0 appears, whichever happens first!)