Ejemplo n.º 1
0
def test_pixels_smoke(x, y, wcs_g1, wcs_g2, ignore_zero_weight):
    gs_wcs = galsim.ShearWCS(0.25, galsim.Shear(g1=wcs_g1,
                                                g2=wcs_g2)).jacobian()
    jac = Jacobian(y=y,
                   x=x,
                   dudx=gs_wcs.dudx,
                   dudy=gs_wcs.dudy,
                   dvdx=gs_wcs.dvdx,
                   dvdy=gs_wcs.dvdy)
    dims = (13, 15)

    rng = np.random.RandomState(seed=11)
    image = rng.normal(size=dims)
    weight = np.exp(rng.normal(size=dims))

    weight[10, 9] = 0
    weight[8, 7] = 0

    pixels = make_pixels(image,
                         weight,
                         jac,
                         ignore_zero_weight=ignore_zero_weight)

    assert np.allclose(pixels['area'], jac.area)

    found_zero = 0
    for i in range(len(pixels)):
        y, x = jac.get_rowcol(pixels['v'][i], pixels['u'][i])
        assert np.allclose(x, int(x + 0.5))
        assert np.allclose(y, int(y + 0.5))
        x = int(x + 0.5)
        y = int(y + 0.5)

        assert pixels['val'][i] == image[y, x]
        assert np.allclose(pixels['ierr'][i], np.sqrt(weight[y, x]))

        if x == 9 and y == 10:
            found_zero += 1
        if y == 8 and x == 7:
            found_zero += 1

    if ignore_zero_weight:
        assert found_zero == 0
    else:
        assert found_zero == 2
Ejemplo n.º 2
0
def test_jacobian_smoke(kind):
    dudcol = 0.25
    dudrow = 0.1
    dvdcol = -0.4
    dvdrow = 0.34
    col = 5.6
    row = -10.4

    if kind == 'row-col':
        jac = Jacobian(col=col,
                       row=row,
                       dudcol=dudcol,
                       dudrow=dudrow,
                       dvdcol=dvdcol,
                       dvdrow=dvdrow)
    elif kind == 'x-y':
        jac = Jacobian(x=col,
                       y=row,
                       dudx=dudcol,
                       dudy=dudrow,
                       dvdx=dvdcol,
                       dvdy=dvdrow)
    else:
        wcs = galsim.JacobianWCS(dudx=dudcol,
                                 dudy=dudrow,
                                 dvdx=dvdcol,
                                 dvdy=dvdrow)
        jac = Jacobian(x=col, y=row, wcs=wcs)

    assert np.allclose(jac.row0, row)
    assert np.allclose(jac.col0, col)
    assert np.allclose(jac.dudcol, dudcol)
    assert np.allclose(jac.dudrow, dudrow)
    assert np.allclose(jac.dvdcol, dvdcol)
    assert np.allclose(jac.dvdrow, dvdrow)

    assert np.allclose(jac.det, dudcol * dvdrow - dudrow * dvdcol)
    assert np.allclose(jac.sdet,
                       np.sqrt(np.abs(dudcol * dvdrow - dudrow * dvdcol)))
    assert np.allclose(jac.scale,
                       np.sqrt(np.abs(dudcol * dvdrow - dudrow * dvdcol)))

    r, c = 20.0, -44.5
    v, u = jac.get_vu(r, c)
    assert np.allclose(v, dvdrow * (r - row) + dvdcol * (c - col))
    assert np.allclose(u, dudrow * (r - row) + dudcol * (c - col))
    v, u = jac(r, c)
    assert np.allclose(v, dvdrow * (r - row) + dvdcol * (c - col))
    assert np.allclose(u, dudrow * (r - row) + dudcol * (c - col))

    v, u = 20.0, -44.5
    r, c = jac.get_rowcol(v, u)
    assert np.allclose(r, (dudcol * v - dvdcol * u) / jac.det + row)
    assert np.allclose(c, (-dudrow * v + dvdrow * u) / jac.det + col)

    gs_wcs = jac.get_galsim_wcs()
    assert np.allclose(gs_wcs.dudx, jac.dudcol)
    assert np.allclose(gs_wcs.dudy, jac.dudrow)
    assert np.allclose(gs_wcs.dvdx, jac.dvdcol)
    assert np.allclose(gs_wcs.dvdy, jac.dvdrow)

    cpy_jac = jac.copy()
    cpy_jac.set_cen(row=-11, col=-12)
    assert np.allclose(jac.row0, row)
    assert np.allclose(jac.col0, col)
    assert np.allclose(cpy_jac.row0, -11)
    assert np.allclose(cpy_jac.col0, -12)