desihub / specsim

Quick simulations of spectrograph response
2 stars 9 forks source link

New test_downsampling failure #137

Closed weaverba137 closed 6 months ago

weaverba137 commented 6 months ago

While working on #136, most tests succeeded, but specsim.tests.test_camera.test_downsampling was one unexpected failure.

=================================== FAILURES ===================================
______________________________ test_downsampling _______________________________

    def test_downsampling():
        c = specsim.config.load_config('test')
        i = specsim.instrument.initialize(c)
        camera = i.cameras[0]

        # Use an intermediate dense matrix for downsampling.
        # This is the old implementation of get_output_resolution_matrix()
        # which uses too much memory.
        n = len(camera._output_wavelength)
        m = camera._downsampling
        i0 = camera.ccd_slice.start - camera.response_slice.start
        R1 = (camera._resolution_matrix[: n * m, i0 : i0 + n * m].toarray()
             .reshape(n, m, n, m).sum(axis=3).sum(axis=1) / float(m))

        # Use the new sparse implementation of get_output_resolution_matrix().
        R2 = camera.get_output_resolution_matrix()

>       assert np.allclose(R1, R2.toarray())
E       AssertionError: assert False
E        +  where False = <function allclose at 0x7f5074f20ee0>(array([[0.6386939 , 0.17828141, 0.00237037, ..., 0.        , 0.        ,\n        0.        ],\n       [0.17828141, 0.63...9 ,\n        0.17828141],\n       [0.        , 0.        , 0.        , ..., 0.0023727 , 0.17828141,\n        0.6386939 ]]), array([[7.21582136e-01, 1.38638623e-01, 5.69036350e-04, ...,\n        0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n...\n       [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n        5.71582129e-04, 1.38638623e-01, 7.21582136e-01]]))
E        +    where <function allclose at 0x7f5074f20ee0> = np.allclose
E        +    and   array([[7.21582136e-01, 1.38638623e-01, 5.69036350e-04, ...,\n        0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n...\n       [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n        5.71582129e-04, 1.38638623e-01, 7.21582136e-01]]) = <bound method spmatrix.toarray of <1500x1500 sparse matrix of type '<class 'numpy.float64'>'\n   with 7494 stored elements (5 diagonals) in DIAgonal format>>()
E        +      where <bound method spmatrix.toarray of <1500x1500 sparse matrix of type '<class 'numpy.float64'>'\n    with 7494 stored elements (5 diagonals) in DIAgonal format>> = <1500x1500 sparse matrix of type '<class 'numpy.float64'>'\n with 7494 stored elements (5 diagonals) in DIAgonal format>.toarray

I have temporarily marked this test with pytest.mark.xfail so that other tests are not impeded.

weaverba137 commented 6 months ago

Fixed in #132.