def test_sip_hst(): """Test SIP against astropy.wcs""" test_file = get_pkg_data_filename(os.path.join('data', 'hst_sip.hdr')) hdr = fits.Header.fromtextfile(test_file) crpix1 = hdr['CRPIX1'] crpix2 = hdr['CRPIX2'] wobj = wcs.WCS(hdr) a_pars = dict(**hdr['A_*']) b_pars = dict(**hdr['B_*']) a_order = a_pars.pop('A_ORDER') b_order = b_pars.pop('B_ORDER') sip = SIP([crpix1, crpix2], a_order, b_order, a_pars, b_pars) coords = [1, 1] rel_coords = [1 - crpix1, 1 - crpix2] astwcs_result = wobj.sip_pix2foc([coords], 1)[0] - rel_coords assert_allclose(sip(1, 1), astwcs_result) # Test changing of inputs and calling it with keyword argumenrts. sip.inputs = ("r", "t") assert_allclose(sip(r=1, t=1), astwcs_result) assert_allclose(sip(1, t=1), astwcs_result)
def test_sip_hst(): """Test SIP against astropy.wcs""" test_file = get_pkg_data_filename(os.path.join('data', 'hst_sip.hdr')) hdr = fits.Header.fromtextfile(test_file) crpix1 = hdr['CRPIX1'] crpix2 = hdr['CRPIX2'] wobj = wcs.WCS(hdr) a_pars = dict(**hdr['A_*']) b_pars = dict(**hdr['B_*']) a_order = a_pars.pop('A_ORDER') b_order = b_pars.pop('B_ORDER') sip = SIP([crpix1, crpix2], a_order, b_order, a_pars, b_pars) coords = [1, 1] rel_coords = [1 - crpix1, 1 - crpix2] astwcs_result = wobj.sip_pix2foc([coords], 1)[0] - rel_coords assert_allclose(sip(1, 1), astwcs_result) # Test changing of inputs and calling it with keyword argumenrts. sip.inputs = ("r", "t") assert_allclose(sip(r=1, t=1), astwcs_result) assert_allclose(sip(1, t=1), astwcs_result) # Test representations assert repr(sip) == ( "<SIP([<Shift(offset=-2048.)>, <Shift(offset=-1024.)>, " "<_SIP1D(4, 'A', A_2_0=0.00000855, A_3_0=-0., A_4_0=0., A_0_2=0.00000217, " "A_0_3=0., A_0_4=0., A_1_1=-0.0000052, A_1_2=-0., A_1_3=-0., " "A_2_1=-0., A_2_2=0., A_3_1=0.)>, " "<_SIP1D(4, 'B', B_2_0=-0.00000175, B_3_0=0., B_4_0=-0., B_0_2=-0.00000722, " "B_0_3=-0., B_0_4=-0., B_1_1=0.00000618, B_1_2=-0., B_1_3=0., " "B_2_1=-0., B_2_2=-0., B_3_1=-0.)>])>") with conf.set_temp('max_width', 80): assert str(sip) == ( "Model: SIP\n" " Model: Shift\n" " Inputs: ('x',)\n" " Outputs: ('y',)\n" " Model set size: 1\n" " Parameters:\n" " offset\n" " -------\n" " -2048.0\n" "\n" " Model: Shift\n" " Inputs: ('x',)\n" " Outputs: ('y',)\n" " Model set size: 1\n" " Parameters:\n" " offset\n" " -------\n" " -1024.0\n" "\n" " Model: _SIP1D\n" " Inputs: ('x', 'y')\n" " Outputs: ('z',)\n" " Model set size: 1\n" " Order: 4\n" " Coeff. Prefix: A\n" " Parameters:\n" " A_2_0 A_3_0 ... A_3_1 \n" " --------------------- ---------------------- ... ---------------------\n" " 8.551277582556502e-06 -4.730444829222791e-10 ... 1.971022971660309e-15\n" "\n" " Model: _SIP1D\n" " Inputs: ('x', 'y')\n" " Outputs: ('z',)\n" " Model set size: 1\n" " Order: 4\n" " Coeff. Prefix: B\n" " Parameters:\n" " B_2_0 B_3_0 ... B_3_1 \n" " ---------------------- --------------------- ... ----------------------\n" " -1.746491877058669e-06 8.567635427816317e-11 ... -3.779506805487476e-15\n" ) # Test get num of coeffs assert sip.sip1d_a.get_num_coeff(1) == 6 # Test error message = "Degree of polynomial must be 2< deg < 9" sip.sip1d_a.order = 1 with pytest.raises(ValueError) as err: sip.sip1d_a.get_num_coeff(1) assert str(err.value) == message sip.sip1d_a.order = 10 with pytest.raises(ValueError) as err: sip.sip1d_a.get_num_coeff(1) assert str(err.value) == message