imexam icon indicating copy to clipboard operation
imexam copied to clipboard

imexam fails with astropy 5.2

Open olebole opened this issue 3 years ago • 2 comments

After uploading astropy 5.2, I found that the CI tests of imexam no longer pass. Specifically, the following test fails:

______________________________ test_gauss_center _______________________________

    def test_gauss_center():
        """Check the gaussian center fitting."""
    
        from astropy.convolution import Gaussian2DKernel
    
        # This creates a 2D normalized gaussian kernal with
        # a set amplitude. Guess off-center
        amp = 0.0015915494309189533
        size = 81.0
        sigma = 10.0
    
        gaussian_2D_kernel = Gaussian2DKernel(sigma, x_size=size, y_size=size)
        plots = Imexamine()
        plots.set_data(gaussian_2D_kernel.array)
        a, xx, yy, xs, ys = plots.gauss_center(37, 37)
    
>       assert_allclose(amp, a, 1e-6)
E       AssertionError: 
E       Not equal to tolerance rtol=1e-06, atol=0
E       
E       Mismatched elements: 1 / 1 (100%)
E       Max absolute difference: 1.61872075e-07
E       Max relative difference: 0.0001017
E        x: array(0.001592)
E        y: array(0.001592)

/usr/lib/python3/dist-packages/imexam/tests/test_imexamine.py:128: AssertionError
----------------------------- Captured stdout call -----------------------------
xc=40.0000	yc=40.0000
------------------------------ Captured log call -------------------------------
INFO     imexam.util:imexamine.py:1015 xc=40.0000	yc=40.0000

Shall one just increase the rtol or is this a real problem?

olebole avatar Dec 17 '22 11:12 olebole

See https://github.com/astropy/astropy/issues/14226#issuecomment-2631375146 – the definition of amplitude/normalisation has changed with astropy 5.2, so the target value amp would have slightly increased. You could update the value for amp (which would break astropy < 5.2 though), increase rtol or increase size to 101 – that would keep the truncated parts small enough to hold the deviation below 1e-06 as well.

dhomeier avatar Feb 03 '25 20:02 dhomeier

That should work up to astropy 6.1.x; with 7.0.0 however all the fitter tests are failing with

FAILED imexam/tests/test_imexamine.py::test_line_fit - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inho...
FAILED imexam/tests/test_imexamine.py::test_column_fit - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inho...
FAILED imexam/tests/test_imexamine.py::test_gauss_center - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inho...
FAILED imexam/tests/test_imexamine.py::test_radial_profile - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inho...
FAILED imexam/tests/test_imexamine.py::test_radial_profile_cumulative - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inho...

which is due to a bug in the Jacobian fit_deriv for CompondModel and fixed in astropy/astropy#17618 (7.0.1).

dhomeier avatar Feb 03 '25 20:02 dhomeier