def test_slice_with_sip(): mywcs = WCS(naxis=2) mywcs.wcs.crval = [1, 1] mywcs.wcs.cdelt = [0.1, 0.1] mywcs.wcs.crpix = [1, 1] mywcs._naxis = [1000, 500] mywcs.wcs.ctype = ['RA---TAN-SIP', 'DEC--TAN-SIP'] a = np.array([[0, 0, 5.33092692e-08, 3.73753773e-11, -2.02111473e-13], [0, 2.44084308e-05, 2.81394789e-11, 5.17856895e-13, 0.0], [-2.41334657e-07, 1.29289255e-10, 2.35753629e-14, 0.0, 0.0], [-2.37162007e-10, 5.43714947e-13, 0.0, 0.0, 0.0], [-2.81029767e-13, 0.0, 0.0, 0.0, 0.0]]) b = np.array([[0, 0, 2.99270374e-05, -2.38136074e-10, 7.23205168e-13], [0, -1.71073858e-07, 6.31243431e-11, -5.16744347e-14, 0.0], [6.95458963e-06, -3.08278961e-10, -1.75800917e-13, 0.0, 0.0], [3.51974159e-11, 5.60993016e-14, 0.0, 0.0, 0.0], [-5.92438525e-13, 0.0, 0.0, 0.0, 0.0]]) mywcs.sip = Sip(a, b, None, None, mywcs.wcs.crpix) mywcs.wcs.set() pscale = 0.1 # from cdelt slice_wcs = mywcs.slice([slice(1, None), slice(0, None)]) # test that CRPIX maps to CRVAL: assert_allclose(slice_wcs.all_pix2world(*slice_wcs.wcs.crpix, 1), slice_wcs.wcs.crval, rtol=0.0, atol=1e-6 * pscale) slice_wcs = mywcs.slice([slice(1, None, 2), slice(0, None, 4)]) # test that CRPIX maps to CRVAL: assert_allclose(slice_wcs.all_pix2world(*slice_wcs.wcs.crpix, 1), slice_wcs.wcs.crval, rtol=0.0, atol=1e-6 * pscale)
def test_non_convergence_warning(): """Test case for issue #11446 Since we can't define a target accuracy when plotting a WCS `all_world2pix` should not error but only warn when the default accuracy can't be reached. """ # define a minimal WCS where convergence fails for certain image positions wcs = WCS(naxis=2) crpix = [0, 0] a = b = ap = bp = np.zeros((4, 4)) a[3, 0] = -1.20116753e-07 test_pos_x = [1000, 1] test_pos_y = [0, 2] wcs.sip = Sip(a, b, ap, bp, crpix) # first make sure the WCS works when using a low accuracy expected = wcs.all_world2pix(test_pos_x, test_pos_y, 0, tolerance=1e-3) # then check that it fails when using the default accuracy with pytest.raises(NoConvergence): wcs.all_world2pix(test_pos_x, test_pos_y, 0) # at last check that world_to_pixel_values raises a warning but returns # the same 'low accuray' result with pytest.warns(UserWarning): assert_allclose(wcs.world_to_pixel_values(test_pos_x, test_pos_y), expected)