Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test__signal_to_noise_limit_above_max_signal_to_noise__signal_to_noise_map_unchanged(
self
):
image = aa.array.full(fill_value=20.0, shape_2d=(2,2))
image[3] = 5.0
noise_map_array = aa.array.full(fill_value=5.0, shape_2d=(2,2))
noise_map_array[3] = 2.0
imaging_data = al.ImagingData(
image=image,
psf=aa.kernel.zeros(shape_2d=(3,3)),
noise_map=noise_map_array,
background_noise_map=aa.array.full(fill_value=1.0, shape_2d=(2,2)),
exposure_time_map=aa.array.full(fill_value=2.0, shape_2d=(2,2)),
background_sky_map=aa.array.full(fill_value=3.0, shape_2d=(2,2)),
)
imaging_data = imaging_data.signal_to_noise_limited_data_from_signal_to_noise_limit(
signal_to_noise_limit=100.0
)
assert (imaging_data.image.in_2d == np.array([[20.0, 20.0], [20.0, 5.0]])).all()
assert (
imaging_data.noise_map.in_2d == np.array([[5.0, 5.0], [5.0, 2.0]])
).all()
assert (
imaging_data.signal_to_noise_map.in_2d
== np.array([[4.0, 4.0], [4.0, 2.5]])
def test__signal_to_noise_limit_below_max_signal_to_noise__signal_to_noise_map_capped_to_limit(
self
):
image = aa.array.full(fill_value=20.0, shape_2d=(2,2))
image[3] = 5.0
noise_map_array = aa.array.full(fill_value=5.0, shape_2d=(2,2))
noise_map_array[3] = 2.0
imaging_data = al.ImagingData(
image=image,
psf=aa.kernel.zeros(shape_2d=(3,3)),
noise_map=noise_map_array,
background_noise_map=aa.array.full(fill_value=1.0, shape_2d=(2,2)),
exposure_time_map=aa.array.full(fill_value=2.0, shape_2d=(2,2)),
background_sky_map=aa.array.full(fill_value=3.0, shape_2d=(2,2)),
)
imaging_data_capped = imaging_data.signal_to_noise_limited_data_from_signal_to_noise_limit(
signal_to_noise_limit=2.0
)
assert (
imaging_data_capped.image.in_2d == np.array([[20.0, 20.0], [20.0, 5.0]])
).all()
assert (
imaging_data_capped.noise_map.in_2d
== np.array([[10.0, 10.0], [10.0, 2.5]])
).all()
def test__signal_to_noise_limit_above_max_signal_to_noise__signal_to_noise_map_unchanged(
self
):
image = aa.array.full(fill_value=20.0, shape_2d=(2,2))
image[3] = 5.0
noise_map_array = aa.array.full(fill_value=5.0, shape_2d=(2,2))
noise_map_array[3] = 2.0
imaging_data = al.ImagingData(
image=image,
psf=aa.kernel.zeros(shape_2d=(3,3)),
noise_map=noise_map_array,
background_noise_map=aa.array.full(fill_value=1.0, shape_2d=(2,2)),
exposure_time_map=aa.array.full(fill_value=2.0, shape_2d=(2,2)),
background_sky_map=aa.array.full(fill_value=3.0, shape_2d=(2,2)),
)
imaging_data = imaging_data.signal_to_noise_limited_data_from_signal_to_noise_limit(
signal_to_noise_limit=100.0
)
assert (imaging_data.image.in_2d == np.array([[20.0, 20.0], [20.0, 5.0]])).all()
def test__signal_to_noise_limit_below_max_signal_to_noise__signal_to_noise_map_capped_to_limit(
self
):
image = aa.array.full(fill_value=20.0, shape_2d=(2,2))
image[3] = 5.0
noise_map_array = aa.array.full(fill_value=5.0, shape_2d=(2,2))
noise_map_array[3] = 2.0
imaging_data = al.ImagingData(
image=image,
psf=aa.kernel.zeros(shape_2d=(3,3)),
noise_map=noise_map_array,
background_noise_map=aa.array.full(fill_value=1.0, shape_2d=(2,2)),
exposure_time_map=aa.array.full(fill_value=2.0, shape_2d=(2,2)),
background_sky_map=aa.array.full(fill_value=3.0, shape_2d=(2,2)),
)
imaging_data_capped = imaging_data.signal_to_noise_limited_data_from_signal_to_noise_limit(
signal_to_noise_limit=2.0
def test__image_and_exposure_times_and_background_are_all_ranges_of_values__noise_estimates_correct(
self
):
# Use same pattern as above, noting that we are now also using a variable background signal_to_noise_ratio map.
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.manual_2d(
array=[[5.0, 6.0], [7.0, 8.0]]
)
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(
def test__via_edges__5x5_image_simple_gaussian_two_edges__ignores_central_pixel(
self
):
image = aa.array.manual_2d(
[
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 100, 1, 1],
[1, 1, 1, 1, 1],
[1, 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=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__4x4_image_simple_gaussian__ignores_central_pixels(self):
image = aa.array.manual_2d(
[[1, 1, 1, 1], [1, 100, 100, 1], [1, 100, 100, 1], [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
def test__setup_with_noise(self, transformer_7x7_7):
image = aa.array.manual_2d([[2.0, 0.0, 0.0], [0.0, 1.0, 0.0], [3.0, 0.0, 0.0]])
exposure_time_map = aa.array.full(
fill_value=20.0, pixel_scales=0.1, shape_2d=image.shape_2d
)
uv_plane_data_simulated = al.SimulatedUVPlaneData.from_image_and_exposure_arrays(
image=image,
pixel_scales=0.1,
exposure_time=20.0,
exposure_time_map=exposure_time_map,
transformer=transformer_7x7_7,
noise_sigma=0.1,
noise_seed=1,
)
simulated_visibilities = transformer_7x7_7.visibilities_from_image(
def test__setup_with_psf_blurring_on__blurs_image_and_trims_psf_edge_off(self):
image = aa.array.manual_2d(
array=np.array(
[
[0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0],
]
),
)
psf = aa.kernel.manual_2d(
array=np.array([[0.0, 1.0, 0.0], [1.0, 2.0, 1.0], [0.0, 1.0, 0.0]]),
)
exposure_time_map = aa.array.ones(shape_2d=image.mask.shape