예제 #1
0
def test_observation_get_has(image_data):
    obs = Observation(image=image_data['image'])
    assert np.all(obs.image == image_data['image'])
    assert not obs.has_bmask()
    assert not obs.has_ormask()
    assert not obs.has_noise()
    assert not obs.has_psf()
    assert not obs.has_psf_gmix()
    assert not obs.has_gmix()

    obs = Observation(image=image_data['image'], weight=image_data['weight'])
    assert np.all(obs.weight == image_data['weight'])

    obs = Observation(image=image_data['image'], bmask=image_data['bmask'])
    assert np.all(obs.bmask == image_data['bmask'])
    assert obs.has_bmask()

    obs = Observation(image=image_data['image'], ormask=image_data['ormask'])
    assert np.all(obs.ormask == image_data['ormask'])
    assert obs.has_ormask()

    obs = Observation(image=image_data['image'], noise=image_data['noise'])
    assert np.all(obs.noise == image_data['noise'])
    assert obs.has_noise()

    obs = Observation(image=image_data['image'], psf=image_data['psf'])
    assert np.all(obs.psf.image == image_data['psf'].image)
    assert obs.has_psf()
    assert not obs.has_psf_gmix()

    obs = Observation(image=image_data['image'], gmix=image_data['gmix'])
    assert np.all(
        obs.gmix.get_full_pars() == image_data['gmix'].get_full_pars())
    assert obs.has_gmix()

    obs = Observation(image=image_data['image'], psf=image_data['psf_gmix'])
    assert np.all(obs.psf.image == image_data['psf_gmix'].image)
    assert obs.has_psf()
    assert obs.has_psf_gmix()
    assert np.all(
        obs.psf.gmix.get_full_pars() == obs.get_psf_gmix().get_full_pars())

    obs = Observation(image=image_data['image'],
                      jacobian=image_data['jacobian'])
    assert (obs.jacobian.get_galsim_wcs() ==
            image_data['jacobian'].get_galsim_wcs())

    obs = Observation(image=image_data['image'], meta=image_data['meta'])
    assert obs.meta == image_data['meta']
예제 #2
0
def test_observation_set(image_data):
    obs = Observation(image=image_data['image'],
                      weight=image_data['weight'],
                      bmask=image_data['bmask'],
                      ormask=image_data['ormask'],
                      noise=image_data['noise'],
                      jacobian=image_data['jacobian'],
                      gmix=image_data['gmix'],
                      psf=image_data['psf'],
                      meta=image_data['meta'])

    rng = np.random.RandomState(seed=11)

    new_arr = rng.normal(size=image_data['image'].shape)
    assert np.all(obs.image != new_arr)
    obs.image = new_arr
    assert np.all(obs.image == new_arr)

    new_arr = np.exp(rng.normal(size=image_data['image'].shape))
    assert np.all(obs.weight != new_arr)
    obs.weight = new_arr
    assert np.all(obs.weight == new_arr)

    new_arr = (np.exp(rng.normal(size=image_data['image'].shape)) *
               100).astype(np.int32)
    assert np.all(obs.bmask != new_arr)
    obs.bmask = new_arr
    assert np.all(obs.bmask == new_arr)
    obs.bmask = None
    assert not obs.has_bmask()

    new_arr = (np.exp(rng.normal(size=image_data['image'].shape)) *
               100).astype(np.int32)
    assert np.all(obs.ormask != new_arr)
    obs.ormask = new_arr
    assert np.all(obs.ormask == new_arr)
    obs.ormask = None
    assert not obs.has_ormask()

    new_arr = rng.normal(size=image_data['image'].shape)
    assert np.all(obs.noise != new_arr)
    obs.noise = new_arr
    assert np.all(obs.noise == new_arr)
    obs.noise = None
    assert not obs.has_noise()

    new_jac = DiagonalJacobian(x=8, y=13, scale=1.2)
    assert new_jac.get_galsim_wcs() != obs.jacobian.get_galsim_wcs()
    obs.jacobian = new_jac
    assert new_jac.get_galsim_wcs() == obs.jacobian.get_galsim_wcs()

    new_meta = {'new': 5}
    assert obs.meta != new_meta
    obs.meta = new_meta
    assert obs.meta == new_meta
    with pytest.raises(TypeError):
        obs.meta = [10]
    obs.meta = None
    assert len(obs.meta) == 0

    new_meta = {'blue': 10}
    new_meta.update(obs.meta)
    assert obs.meta != new_meta
    obs.update_meta_data({'blue': 10})
    assert obs.meta == new_meta
    with pytest.raises(TypeError):
        obs.update_meta_data([10])

    new_gmix = GMix(pars=rng.uniform(size=6))
    assert np.all(obs.gmix.get_full_pars() != new_gmix.get_full_pars())
    obs.gmix = new_gmix
    assert np.all(obs.gmix.get_full_pars() == new_gmix.get_full_pars())
    obs.gmix = None
    assert not obs.has_gmix()
    with pytest.raises(RuntimeError):
        obs.get_gmix()

    new_psf = Observation(image=rng.normal(size=obs.psf.image.shape),
                          meta={'ispsf': True})
    assert np.all(obs.psf.image != new_psf.image)
    obs.psf = new_psf
    assert np.all(obs.psf.image == new_psf.image)
    assert np.all(obs.get_psf().image == new_psf.image)
    obs.psf = None
    assert not obs.has_psf()
    with pytest.raises(RuntimeError):
        obs.get_psf()
    with pytest.raises(RuntimeError):
        obs.get_psf_gmix()