Example #1
0
def test_observation_pixels(image_data):
    obs = Observation(image=image_data['image'],
                      weight=image_data['weight'],
                      jacobian=image_data['jacobian'])
    pixels = obs.pixels

    my_pixels = make_pixels(image_data['image'], image_data['weight'],
                            image_data['jacobian'])

    assert np.all(pixels == my_pixels)
Example #2
0
def test_observation_pixels_update_jacobian(image_data):
    obs = Observation(image=image_data['image'],
                      weight=image_data['weight'],
                      jacobian=image_data['jacobian'])
    new_jac = DiagonalJacobian(x=8, y=13, scale=1.2)

    my_pixels = make_pixels(image_data['image'], image_data['weight'], new_jac)

    assert np.all(obs.pixels != my_pixels)
    obs.jacobian = new_jac
    assert np.all(obs.pixels == my_pixels)
Example #3
0
def test_observation_pixels_update_weight(image_data):
    rng = np.random.RandomState(seed=11)
    obs = Observation(image=image_data['image'],
                      weight=image_data['weight'],
                      jacobian=image_data['jacobian'])

    new_arr = np.exp(rng.normal(size=obs.image.shape))
    my_pixels = make_pixels(image_data['image'], new_arr,
                            image_data['jacobian'])

    assert np.all(obs.pixels != my_pixels)
    obs.weight = new_arr
    assert np.all(obs.pixels == my_pixels)
Example #4
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
Example #5
0
def test_observation_pixels_noignore_zero(image_data):

    weight = image_data['weight'].copy()
    weight[:, 5] = 0.0

    obs = Observation(
        image=image_data['image'],
        weight=weight,
        jacobian=image_data['jacobian'],
        ignore_zero_weight=False,
    )
    pixels = obs.pixels

    my_pixels = make_pixels(
        image_data['image'],
        weight,
        image_data['jacobian'],
        ignore_zero_weight=False,
    )

    assert np.all(pixels == my_pixels)