Exemplo n.º 1
0
def test_sip_irac():
    """Test forward and inverse SIP againts astropy.wcs"""

    test_file = get_pkg_data_filename(os.path.join('data', 'irac_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_*'])
    ap_pars = dict(**hdr['AP_*'])
    bp_pars = dict(**hdr['BP_*'])
    a_order = a_pars.pop('A_ORDER')
    b_order = b_pars.pop('B_ORDER')
    ap_order = ap_pars.pop('AP_ORDER')
    bp_order = bp_pars.pop('BP_ORDER')
    del a_pars['A_DMAX']
    del b_pars['B_DMAX']
    pix = [200, 200]
    rel_pix = [200 - crpix1, 200 - crpix2]
    sip = SIP([crpix1, crpix2],
              a_order,
              b_order,
              a_pars,
              b_pars,
              ap_order=ap_order,
              ap_coeff=ap_pars,
              bp_order=bp_order,
              bp_coeff=bp_pars)

    foc = wobj.sip_pix2foc([pix], 1)
    newpix = wobj.sip_foc2pix(foc, 1)[0]
    assert_allclose(sip(*pix), foc[0] - rel_pix)
    assert_allclose(sip.inverse(*foc[0]) + foc[0] - rel_pix, newpix - pix)
Exemplo n.º 2
0
def test_sip_irac():
    """Test forward and inverse SIP against astropy.wcs"""

    test_file = get_pkg_data_filename(os.path.join('data', 'irac_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_*'])
    ap_pars = dict(**hdr['AP_*'])
    bp_pars = dict(**hdr['BP_*'])
    a_order = a_pars.pop('A_ORDER')
    b_order = b_pars.pop('B_ORDER')
    ap_order = ap_pars.pop('AP_ORDER')
    bp_order = bp_pars.pop('BP_ORDER')
    del a_pars['A_DMAX']
    del b_pars['B_DMAX']
    pix = [200, 200]
    rel_pix = [200 - crpix1, 200 - crpix2]
    sip = SIP([crpix1, crpix2], a_order, b_order, a_pars, b_pars,
              ap_order=ap_order, ap_coeff=ap_pars, bp_order=bp_order,
              bp_coeff=bp_pars)

    foc = wobj.sip_pix2foc([pix], 1)
    newpix = wobj.sip_foc2pix(foc, 1)[0]
    assert_allclose(sip(*pix), foc[0] - rel_pix)
    assert_allclose(sip.inverse(*foc[0]) +
                    foc[0] - rel_pix, newpix - pix)

    # Test inverse representations
    assert repr(sip.inverse) ==\
        "<InverseSIP([<Polynomial2D(2, c0_0=0., c1_0=0.0000114, c2_0=0.00002353, " +\
        "c0_1=-0.00000546, c0_2=-0.00000667, c1_1=-0.00001801)>, " +\
        "<Polynomial2D(2, c0_0=0., c1_0=-0.00001495, c2_0=0.00000122, c0_1=0.00001975, " +\
        "c0_2=-0.00002601, c1_1=0.00002944)>])>"
    assert str(sip.inverse) ==\
        "Model: InverseSIP\n" +\
        "    Model: Polynomial2D\n" +\
        "    Inputs: ('x', 'y')\n" +\
        "    Outputs: ('z',)\n" +\
        "    Model set size: 1\n" +\
        "    Degree: 2\n" +\
        "    Parameters:\n" +\
        "        c0_0   c1_0      c2_0      c0_1       c0_2       c1_1   \n" +\
        "        ---- -------- --------- ---------- ---------- ----------\n" +\
        "         0.0 1.14e-05 2.353e-05 -5.463e-06 -6.666e-06 -1.801e-05\n" +\
        "\n" +\
        "    Model: Polynomial2D\n" +\
        "    Inputs: ('x', 'y')\n" +\
        "    Outputs: ('z',)\n" +\
        "    Model set size: 1\n" +\
        "    Degree: 2\n" +\
        "    Parameters:\n" +\
        "        c0_0    c1_0       c2_0      c0_1      c0_2       c1_1  \n" +\
        "        ---- ---------- --------- --------- ---------- ---------\n" +\
        "         0.0 -1.495e-05 1.225e-06 1.975e-05 -2.601e-05 2.944e-05\n"
Exemplo n.º 3
0
def test_sip_no_coeff():
    sip = SIP([10, 12], 2, 2)
    assert_allclose(sip.sip1d_a.parameters, [0., 0., 0])
    assert_allclose(sip.sip1d_b.parameters, [0., 0., 0])
    with pytest.raises(NotImplementedError):
        sip.inverse

    # Test model set
    sip = SIP([10, 12], 2, 2, n_models=2)
    assert sip.sip1d_a.model_set_axis == 0
    assert sip.sip1d_b.model_set_axis == 0
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def test_sip_no_coeff():
    sip = SIP([10, 12], 2, 2)
    assert_allclose(sip.sip1d_a.parameters, [0., 0., 0])
    assert_allclose(sip.sip1d_b.parameters, [0., 0., 0])
    with pytest.raises(NotImplementedError):
        sip.inverse
Exemplo n.º 6
0
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