Example #1
0
    def test_lenstronomy_vs_numpy_electron(self):
        """Compare the lenstronomy and numpy noise variance for electron units

        """
        lens_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                   data_count_unit='e-',
                                                   **self.noise_kwargs)
        noise_model_numpy = NoiseModelNumpy(data_count_unit='e-',
                                            **self.noise_kwargs)
        numpy_sigma2 = {}
        numpy_sigma2['sky'] = noise_model_numpy.get_sky_noise_sigma2()
        numpy_sigma2['readout'] = noise_model_numpy.get_readout_noise_sigma2()
        numpy_sigma2['poisson'] = noise_model_numpy.get_poisson_noise_sigma2(
            self.img)
        np.testing.assert_almost_equal(lens_sigma2['sky'],
                                       numpy_sigma2['sky'],
                                       decimal=7,
                                       err_msg="sky")
        np.testing.assert_almost_equal(lens_sigma2['readout'],
                                       numpy_sigma2['readout'],
                                       decimal=7,
                                       err_msg="readout")
        np.testing.assert_array_almost_equal(lens_sigma2['poisson'],
                                             numpy_sigma2['poisson'],
                                             decimal=7,
                                             err_msg="poisson")
Example #2
0
    def test_lenstronomy_vs_torch_electron(self):
        """Compare the lenstronomy and torch noise variance for electron units

        """
        lens_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                   data_count_unit='e-',
                                                   **self.noise_kwargs)
        img_torch_tensor = torch.DoubleTensor(self.img)
        noise_model_torch = NoiseModelTorch(data_count_unit='e-',
                                            **self.noise_kwargs)
        torch_sigma2 = {}
        torch_sigma2['sky'] = noise_model_torch.get_sky_noise_sigma2()
        torch_sigma2['readout'] = noise_model_torch.get_readout_noise_sigma2()
        torch_sigma2['poisson'] = noise_model_torch.get_poisson_noise_sigma2(
            img_torch_tensor)
        np.testing.assert_almost_equal(lens_sigma2['sky'],
                                       torch_sigma2['sky'],
                                       decimal=7,
                                       err_msg="sky")
        np.testing.assert_almost_equal(lens_sigma2['readout'],
                                       torch_sigma2['readout'],
                                       decimal=7,
                                       err_msg="readout")
        np.testing.assert_array_almost_equal(lens_sigma2['poisson'],
                                             torch_sigma2['poisson'],
                                             decimal=7,
                                             err_msg="poisson")
Example #3
0
 def test_lenstronomy_background(self):
     """Without involving the numpy noise module, simply check that the background noise variance (readout plus sky) when background noise is specified as None equals the computed readout plus sky variance"""
     lens_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                data_count_unit='ADU',
                                                **self.noise_kwargs)
     if self.noise_kwargs['background_noise'] is None:
         lens_sigma2['sky_plus_readout'] = lens_sigma2['sky'] + lens_sigma2[
             'readout']
Example #4
0
    def test_get_noise_sigma2_lenstronomy_composite_background(self):
        """Validate the output of the lenstronomy noise module with background noise defined by sky and readout noise properties rather than an estimate of the combined background noise level

        """
        noise_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                    data_count_unit='ADU',
                                                    **self.noise_kwargs)
        self.assertEqual(noise_sigma2['poisson'].shape, self.img.shape)
        self.assertTrue(isinstance(noise_sigma2['sky'], float))
        self.assertTrue(isinstance(noise_sigma2['readout'], float))
        return noise_sigma2
Example #5
0
    def test_lenstronomy_vs_tf_electron(self):
        """Compare the lenstronomy and tf noise variance for electron units

        """
        lens_sigma2 = get_noise_sigma2_lenstronomy(self.img, data_count_unit='e-', **self.noise_kwargs)
        img_tf_tensor = tf.cast(self.img, tf.float32)
        noise_model_tf = NoiseModelTF(data_count_unit='e-', **self.noise_kwargs)
        tf_sigma2 = {}
        tf_sigma2['sky'] = noise_model_tf.get_sky_noise_sigma2()
        tf_sigma2['readout'] = noise_model_tf.get_readout_noise_sigma2()
        tf_sigma2['poisson'] = noise_model_tf.get_poisson_noise_sigma2(img_tf_tensor)
        np.testing.assert_array_almost_equal(self.img, img_tf_tensor.numpy(), decimal=5, err_msg="image array")
        np.testing.assert_almost_equal(lens_sigma2['sky'], tf_sigma2['sky'], decimal=7, err_msg="sky")
        np.testing.assert_almost_equal(lens_sigma2['readout'], tf_sigma2['readout'], decimal=7, err_msg="readout")
        np.testing.assert_array_almost_equal(lens_sigma2['poisson'], tf_sigma2['poisson'].numpy(), decimal=7, err_msg="poisson")
Example #6
0
    def test_lenstronomy_vs_torch_ADU(self):
        """Compare the lenstronomy and torch noise variance for ADU units

        """
        numpy_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                    data_count_unit='ADU',
                                                    **self.noise_kwargs)
        img_torch_tensor = torch.DoubleTensor(self.img)
        noise_model_torch = NoiseModelTorch(**self.noise_kwargs)
        torch_sigma2 = {}
        torch_sigma2['sky'] = noise_model_torch.get_sky_noise_sigma2()
        torch_sigma2['readout'] = noise_model_torch.get_readout_noise_sigma2()
        torch_sigma2['poisson'] = noise_model_torch.get_poisson_noise_sigma2(
            img_torch_tensor)
        self.assertEqual(numpy_sigma2['sky'], torch_sigma2['sky'])
        self.assertEqual(numpy_sigma2['readout'], torch_sigma2['readout'])
        np.testing.assert_array_almost_equal(numpy_sigma2['poisson'],
                                             torch_sigma2['poisson'].numpy(),
                                             decimal=7)
Example #7
0
    def test_lenstronomy_vs_tf_ADU(self):
        """Compare the lenstronomy and tf noise variance for ADU units

        """
        numpy_sigma2 = get_noise_sigma2_lenstronomy(self.img,
                                                    data_count_unit='ADU',
                                                    **self.noise_kwargs)
        img_tf_tensor = tf.cast(self.img, tf.float32)
        noise_model_tf = NoiseModelTF(**self.noise_kwargs)
        tf_sigma2 = {}
        tf_sigma2['sky'] = noise_model_tf.get_sky_noise_sigma2()
        tf_sigma2['readout'] = noise_model_tf.get_readout_noise_sigma2()
        tf_sigma2['poisson'] = noise_model_tf.get_poisson_noise_sigma2(
            img_tf_tensor)
        np.testing.assert_array_almost_equal(self.img,
                                             img_tf_tensor.numpy(),
                                             decimal=5)
        np.testing.assert_equal(numpy_sigma2['sky'], tf_sigma2['sky'])
        np.testing.assert_equal(numpy_sigma2['readout'], tf_sigma2['readout'])
        np.testing.assert_array_almost_equal(numpy_sigma2['poisson'],
                                             tf_sigma2['poisson'].numpy(),
                                             decimal=7)