def test_gradient_map(): image = np.zeros((6, 8)) grad = image_util.gradient_map(image) npt.assert_almost_equal(grad, image, decimal=6) image_ones = np.ones((6, 8)) grad = image_util.gradient_map(image_ones) npt.assert_almost_equal(grad, image, decimal=6) assert np.shape(grad) == np.shape(image)
def covariance_matrix(data, background_rms, exposure_map, gradient_boost_factor=None): """ returns a diagonal matrix for the covariance estimation which describes the error Notes: - the exposure map must be positive definite. Values that deviate too much from the mean exposure time will be given a lower limit to not under-predict the Poisson component of the noise. - the data must be positive semi-definite for the Poisson noise estimate. Values < 0 (Possible after mean subtraction) will not have a Poisson component in their noise estimate. :param data: data array, eg in units of photons/second :param background_rms: background noise rms, eg. in units (photons/second)^2 :param exposure_map: exposure time per pixel, e.g. in units of seconds :param gradient_boost_factor: None or float, variance terms added in quadrature scaling with gradient^2 * gradient_boost_factor :return: len(d) x len(d) matrix that give the error of background and Poisson components; (photons/second)^2 """ if gradient_boost_factor is not None: gradient_map = image_util.gradient_map(data) * gradient_boost_factor else: gradient_map = 0 d_pos = np.zeros_like(data) d_pos[data >= 0] = data[data >= 0] sigma = d_pos / exposure_map + background_rms**2 + gradient_map**2 return sigma