spacetelescope / webbpsf

James Webb Space Telescope PSF simulation tool
https://webbpsf.readthedocs.io
BSD 3-Clause "New" or "Revised" License
119 stars 63 forks source link

photutils 2.x.x incompatability #933

Closed BradleySappington closed 6 days ago

BradleySappington commented 6 days ago

Tests are failing with the new releases of photutils. I have put an upper limit in Pyproject.toml and requirements.txt When the issue is fixed those upper limits can be amended.

Here are the test outputs that are failing:

=================================== FAILURES ===================================
______________________________ test_all_detectors ______________________________

    def test_all_detectors():
        """
        Check that running all the detectors works (ie setting all_detectors=True). In
        particular for NIRCam, test that the detectors pulled are correct
        (shortwave vs longwave) with respect to the filter
        """
        nir = webbpsf_core.NIRCam()
        longfilt = 'F250M'
        shortfilt = 'F140M'

        # Case 1: Shortwave -> check that only the SW detectors are applied for the SW filter
        nir.filter = shortfilt
>       grid1 = nir.psf_grid(all_detectors=True, num_psfs=1, add_distortion=False, fov_pixels=1, oversample=2, verbose=False)

webbpsf/tests/test_psfgrid.py:110: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
webbpsf/webbpsf_core.py:768: in psf_grid
    gridmodel = inst.create_grid()
webbpsf/gridded_library.py:440: in create_grid
    model = self.to_model(psf_arr, meta)
webbpsf/gridded_library.py:4[93](https://github.com/spacetelescope/webbpsf/actions/runs/11978420511/job/33398398876?pr=926#step:9:94): in to_model
    model = GriddedPSFModel(ndd)
.tox/py310-astropydev-test/lib/python3.10/site-packages/photutils/psf/gridded_models.py:119: in __init__
    self.data, self.grid_xypos = self._define_grid(nddata)
.tox/py310-astropydev-test/lib/python3.10/site-packages/photutils/psf/gridded_models.py:238: in _define_grid
    self._validate_data(nddata)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

data = NDData([[[0.13415117, 0.13498[95](https://github.com/spacetelescope/webbpsf/actions/runs/11978420511/job/33398398876?pr=926#step:9:96)1],
         [0.13418078, 0.13511403]]])

    @staticmethod
    def _validate_data(data):
        """
        Validate the input ePSF data.

        Parameters
        ----------
        data : `~astropy.nddata.NDData`
            The input NDData object containing the ePSF data.

        Raises
        ------
        TypeError
            If the input data is not an NDData instance.
        ValueError
            If the input data is not a 3D numpy ndarray or if the input
            data contains NaNs or infs.
        """
        if not isinstance(data, NDData):
            raise TypeError('data must be an NDData instance.')

        if data.data.ndim != 3:
            raise ValueError('The NDData data attribute must be a 3D numpy '
                             'ndarray')
        ----------
        data : `~astropy.nddata.NDData`
            The input NDData object containing the ePSF data.

        Raises
        ------
        TypeError
            If the input data is not an NDData instance.
        ValueError
            If the input data is not a 3D numpy ndarray or if the input
            data contains NaNs or infs.
        """
        if not isinstance(data, NDData):
            raise TypeError('data must be an NDData instance.')

        if data.data.ndim != 3:
            raise ValueError('The NDData data attribute must be a 3D numpy '
                             'ndarray')

        if not np.all(np.isfinite(data.data)):
            raise ValueError('All elements of input data must be finite.')

        # this is required by RectBivariateSpline for kx=3, ky=3
        if np.any(np.array(data.data.shape[1:]) < 4):
>           raise ValueError('The length of the PSF x and y axes must both '
                             'be at least 4.')
E           ValueError: The length of the PSF x and y axes must both be at least 4.

.tox/py310-astropydev-test/lib/python3.10/site-packages/photutils/psf/gridded_models.py:164: ValueError
=========================== short test summary info ============================
FAILED webbpsf/tests/test_psfgrid.py::test_all_detectors - ValueError: The length of the PSF x and y axes must both be at least 4.
FAILED webbpsf/tests/test_psfgrid.py::test_nircam_errors - ValueError: The length of the PSF x and y axes must both be at least 4.
======= 2 failed, [124](https://github.com/spacetelescope/webbpsf/actions/runs/11978420511/job/33398398876?pr=926#step:9:125) passed, 3 skipped, 1 xfailed in 354.61s (0:05:54) ========
ERROR: InvocationError for command /home/runner/work/webbpsf/webbpsf/.tox/py310-astropydev-test/bin/pytest (exited with code 1)
mperrin commented 6 days ago

This should be a duplicate of #924 which should have been fixed with my PR #925 that Marcio merged earlier today

mperrin commented 6 days ago

I can confirm that all the tests in test_psfgrid.py pass on develop for me with photutils=2.0.2. In other words the fixes in PR #925 that I wrote three weeks ago and finally got merged today do seem to have fixed the above. At least, so it seems for me...

BradleySappington commented 6 days ago

interesting, in that case, I will remove my upper limits in requirements project.toml in a new branch and see if everything passes.

BradleySappington commented 6 days ago

I created https://github.com/spacetelescope/webbpsf/pull/935 that will undo the restrictions put on photutils. This issue is good to close. Thanks!