Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Exposure times = 1.0 s
# Imaging (counts) = 4.0
# Background (counts) = 0.0
# Noise (counts) = sqrt(4.0 + 0.0**2) = 2.0
# Noise (eps) = 2.0 / 1.0
image = aa.array.full(fill_value=4.0, shape_2d=(4, 2))
exposure_time = aa.array.ones(shape_2d=(4,2))
background_noise = aa.array.zeros(shape_2d=(4,2))
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert (
imaging_data.estimated_noise_map.in_2d == 2.0 * np.ones((4, 2))
).all()
def test__same_as_above_but_different_image_values_in_each_pixel_and_new_background_values(
self
):
# Can use pattern from previous test_autoarray for values
image = aa.array.manual_2d(
array=[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
)
exposure_time = aa.array.ones(shape_2d=(3,2))
background_noise = aa.array.full(fill_value=12.0, shape_2d=(3,2))
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert imaging_data.estimated_noise_map.in_2d == pytest.approx(
np.array(
[
[np.sqrt(1.0 + 144.0), np.sqrt(2.0 + 144.0)],
[np.sqrt(3.0 + 144.0), np.sqrt(4.0 + 144.0)],
[np.sqrt(5.0 + 144.0), np.sqrt(6.0 + 144.0)],
]
),
1e-2,
)
# Imaging (counts) = 1.0
# Background (counts) = 5.0
# Noise (counts) = sqrt(1.0 + 5**2)
# Noise (eps) = sqrt(1.0 + 5**2) / 1.0
image = aa.array.ones(shape_2d=(2,3))
exposure_time = aa.array.ones(shape_2d=(2,3))
background_noise = aa.array.full(fill_value=5.0, shape_2d=(2,3))
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert imaging_data.estimated_noise_map.in_2d == pytest.approx(
np.array(
[
[np.sqrt(1.0 + 25.0), np.sqrt(1.0 + 25.0), np.sqrt(1.0 + 25.0)],
[np.sqrt(1.0 + 25.0), np.sqrt(1.0 + 25.0), np.sqrt(1.0 + 25.0)],
]
),
1e-2,
)
# Imaging (counts) = 1.0
# Background (counts) = sqrt(3.0)
# Noise (counts) = sqrt(1.0 + sqrt(3.0)**2) = sqrt(1.0 + 3.0) = 2.0
# Noise (eps) = 2.0 / 1.0 = 2.0
image = aa.array.ones(shape_2d=(3,3))
exposure_time = aa.array.ones(shape_2d=(3,3))
background_noise = aa.array.full(fill_value=3.0 ** 0.5, shape_2d=(3,3))
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert imaging_data.estimated_noise_map.in_2d == pytest.approx(
2.0 * np.ones((3, 3)), 1e-2
)
def test__via_edges__input_all_ones__sky_bg_level_1(self):
imaging_data = al.ImagingData(
image=aa.array.manual_2d(np.ones((3, 3))),
noise_map=np.ones((3, 3)),
psf=aa.kernel.ones(shape_2d=(3,3)),
pixel_scales=0.1,
)
sky_noise = imaging_data.background_noise_from_edges(no_edges=1)
assert sky_noise == 0.0
def test__via_edges__6x5_image_two_edges__values(self):
image = aa.array.manual_2d(
[
[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 100, 12, 13],
[14, 15, 100, 16, 17],
[18, 19, 20, 21, 22],
[23, 24, 25, 26, 27],
]
)
imaging_data = al.ImagingData(
image=image,
noise_map=np.ones((3, 3)),
psf=aa.kernel.ones(shape_2d=(3,3)),
pixel_scales=0.1,
)
sky_noise = imaging_data.background_noise_from_edges(no_edges=2)
assert sky_noise == np.std(np.arange(28))
def test__via_edges__4x3_image_simple_gaussian__ignores_central_pixels(self):
image = aa.array.manual_2d([[1, 1, 1], [1, 100, 1], [1, 100, 1], [1, 1, 1]])
imaging_data = al.ImagingData(
image=image,
noise_map=np.ones((3, 3)),
psf=aa.kernel.ones(shape_2d=(3,3)),
pixel_scales=0.1,
)
sky_noise = imaging_data.background_noise_from_edges(no_edges=1)
assert sky_noise == 0.0
# Imaging (counts) = 4.0
# Background (counts) = 0.0
# Noise (counts) = sqrt(4.0 + 0.0**2) = 2.0
# Noise (eps) = 2.0 / 4.0 = 0.5
image = aa.array.ones(shape_2d=(1,5))
exposure_time = aa.array.full(fill_value=4.0, shape_2d=(1,5))
background_noise = aa.array.zeros(shape_2d=(1,5))
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert (
imaging_data.estimated_noise_map.in_2d == 0.5 * np.ones((1, 5))
).all()
image = aa.array.manual_2d(
array=[[5.0, 3.0], [10.0, 20.0]]
)
exposure_time = aa.array.manual_2d(
array=[[1.0, 2.0], [3.0, 4.0]]
)
background_noise = aa.array.full(fill_value=9.0,
shape_2d=((2, 2))
)
imaging_data = al.ImagingData(
image=image,
pixel_scales=1.0,
psf=aa.kernel.ones(shape_2d=(3,3)),
exposure_time_map=exposure_time,
background_noise_map=background_noise,
)
assert imaging_data.estimated_noise_map.in_2d == pytest.approx(
np.array(
[
[np.sqrt(5.0 + 81.0), np.sqrt(6.0 + 18.0 ** 2.0) / 2.0],
[
np.sqrt(30.0 + 27.0 ** 2.0) / 3.0,
np.sqrt(80.0 + 36.0 ** 2.0) / 4.0,
],
]
),
1e-2,
)