Skip to content

Commit 1fa71a9

Browse files
committed
Merge branch 'main' into feature/area_fix
2 parents 3fcd83a + 5e9e263 commit 1fa71a9

File tree

8 files changed

+52
-13
lines changed

8 files changed

+52
-13
lines changed

autoarray/config/visualize/include.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include_1d:
77
mask: false # Include a Mask ?
88
origin: false # Include the (x,) origin of the data's coordinate system ?
99
include_2d:
10-
border: true # Include the border of the mask (all pixels on the outside of the mask) ?
10+
border: false # Include the border of the mask (all pixels on the outside of the mask) ?
1111
grid: false # Include the data's 2D grid of (y,x) coordinates ?
1212
mapper_image_plane_mesh_grid: false # For an Inversion, include the pixel centres computed in the image-plane / data frame?
1313
mapper_source_plane_data_grid: false # For an Inversion, include the centres of the image-plane grid mapped to the source-plane / frame in source-plane figures?

autoarray/dataset/imaging/dataset.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def from_fits(
213213
psf_path: Optional[Union[Path, str]] = None,
214214
psf_hdu: int = 0,
215215
noise_covariance_matrix: Optional[np.ndarray] = None,
216+
check_noise_map: bool = True,
216217
over_sampling: Optional[OverSamplingDataset] = OverSamplingDataset(),
217218
) -> "Imaging":
218219
"""
@@ -250,6 +251,8 @@ def from_fits(
250251
The hdu the noise map is contained in the .fits file specified by `noise_map_path`.
251252
noise_covariance_matrix
252253
A noise-map covariance matrix representing the covariance between noise in every `data` value.
254+
check_noise_map
255+
If True, the noise-map is checked to ensure all values are above zero.
253256
over_sampling
254257
The over sampling schemes which divide the grids into sub grids of smaller pixels within their host image
255258
pixels when using the grid to evaluate a function (e.g. images) to better approximate the 2D line integral
@@ -280,6 +283,7 @@ def from_fits(
280283
noise_map=noise_map,
281284
psf=psf,
282285
noise_covariance_matrix=noise_covariance_matrix,
286+
check_noise_map=check_noise_map,
283287
over_sampling=over_sampling,
284288
)
285289

@@ -377,6 +381,7 @@ def apply_noise_scaling(self, mask: Mask2D, noise_value: float = 1e8) -> "Imagin
377381
noise_covariance_matrix=self.noise_covariance_matrix,
378382
over_sampling=self.over_sampling,
379383
pad_for_convolver=False,
384+
check_noise_map=False
380385
)
381386

382387
logger.info(
@@ -429,6 +434,7 @@ def apply_over_sampling(
429434
psf=self.psf,
430435
over_sampling=over_sampling,
431436
pad_for_convolver=False,
437+
check_noise_map=False
432438
)
433439

434440
def output_to_fits(

autoarray/inversion/plot/inversion_plotters.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def figures_2d_of_pixelization(
122122
reconstructed_image: bool = False,
123123
reconstruction: bool = False,
124124
errors: bool = False,
125+
signal_to_noise_map: bool = False,
125126
regularization_weights: bool = False,
126127
sub_pixels_per_image_pixels: bool = False,
127128
mesh_pixels_per_image_pixels: bool = False,
@@ -146,6 +147,8 @@ def figures_2d_of_pixelization(
146147
Whether to make a 2D plot (via `imshow` or `fill`) of the mapper's source-plane reconstruction.
147148
errors
148149
Whether to make a 2D plot (via `imshow` or `fill`) of the mapper's source-plane errors.
150+
signal_to_noise_map
151+
Whether to make a 2D plot (via `imshow` or `fill`) of the mapper's source-plane signal-to-noise-map.
149152
sub_pixels_per_image_pixels
150153
Whether to make a 2D plot (via `imshow`) of the number of sub pixels per image pixels in the 2D
151154
data's mask.
@@ -243,6 +246,23 @@ def figures_2d_of_pixelization(
243246
except TypeError:
244247
pass
245248

249+
if signal_to_noise_map:
250+
try:
251+
signal_to_noise_values = (
252+
self.inversion.reconstruction_dict[mapper_plotter.mapper]
253+
/ self.inversion.errors_dict[mapper_plotter.mapper]
254+
)
255+
256+
mapper_plotter.plot_source_from(
257+
pixel_values=signal_to_noise_values,
258+
auto_labels=AutoLabels(
259+
title="Signal To Noise Map", filename="signal_to_noise_map"
260+
),
261+
)
262+
263+
except TypeError:
264+
pass
265+
246266
# TODO : NEed to understand why this raises an error in voronoi_drawer.
247267

248268
if regularization_weights:

autoarray/mask/abstract_mask.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ def pixel_scale(self) -> float:
7575
"""
7676
for pixel_scale in self.pixel_scales:
7777
if abs(pixel_scale - self.pixel_scales[0]) > 1.0e-8:
78-
raise exc.MaskException(
79-
"Cannot return a pixel_scale for a grid where each dimension has a "
80-
"different pixel scale (e.g. pixel_scales[0] != pixel_scales[1])"
78+
logger.warning(
79+
f"""
80+
The Mask has different pixel scales in each dimensions, which are {self.pixel_scales}.
81+
82+
This is not expected, and will lead to unexpected behaviour in the grid and mask classes.
83+
The code will continue to run, but you should check that the pixel scales are as you expect and
84+
that associated data structures (e.g. grids) are behaving as you expect.
85+
"""
8186
)
8287

8388
return self.pixel_scales[0]

autoarray/structures/decorators/to_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def via_grid_2d_irr(self, result) -> Union[Grid2DIrregular, List[Grid2DIrregular
4747
----------
4848
result
4949
The input result (e.g. of a decorated function) that is converted to an Grid2DIrregular or list of
50-
Grid2DIrregular objects.
50+
`Grid2DIrregular` objects.
5151
"""
5252
if not isinstance(result, list):
5353
return Grid2DIrregular(values=result)

autoarray/structures/grids/irregular_2d.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from autoarray.numpy_wrapper import np
1+
import logging
22
from typing import List, Optional, Tuple, Union
33

4+
from autoarray.numpy_wrapper import np
45
from autoarray.abstract_ndarray import AbstractNDArray
56
from autoarray.geometry.geometry_2d_irregular import Geometry2DIrregular
67
from autoarray.mask.mask_2d import Mask2D
@@ -10,6 +11,8 @@
1011
from autoarray.structures.grids import grid_2d_util
1112
from autoarray.geometry import geometry_util
1213

14+
logger = logging.getLogger(__name__)
15+
1316

1417
class Grid2DIrregular(AbstractNDArray):
1518
def __init__(self, values: Union[np.ndarray, List]):
@@ -351,9 +354,12 @@ def pixel_scale(self) -> float:
351354
if self.pixel_scales[0] == self.pixel_scales[1]:
352355
return self.pixel_scales[0]
353356
else:
354-
raise exc.GridException(
355-
"Cannot return a pixel_scale for a grid where each dimension has a "
356-
"different pixel scale (e.g. pixel_scales[0] != pixel_scales[1])"
357+
logger.warning(
358+
f"""
359+
The `Grid2DIrregular` has pixel scales of {self.pixel_scales}, which are not the same in both
360+
dimensions. This means that the pixel scale of the grid is not a single value and may cause
361+
issues with calculations that assume a uniform pixel scale.
362+
"""
357363
)
358364

359365
@classmethod

test_autoarray/inversion/inversion/test_mapper_valued.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ def test__magnification_via_interpolation_from():
196196
)
197197

198198
mapper = aa.m.MockMapper(
199-
parameters=3,
199+
parameters=4,
200200
mask=mask,
201201
interpolated_array=magnification,
202-
mapping_matrix=np.ones((4, 3)),
202+
mapping_matrix=np.ones((4, 4)),
203203
)
204204

205205
mapper_valued = aa.MapperValued(values=np.array(magnification), mapper=mapper)
206206

207207
magnification = mapper_valued.magnification_via_interpolation_from()
208208

209-
assert magnification == pytest.approx(3.6666666666666665, 1.0e-4)
209+
assert magnification == pytest.approx(4.0, 1.0e-4)
210210

211211
magnification = mapper_valued.magnification_via_interpolation_from(
212212
shape_native=(3, 3), extent=(-1.0, 1.0, -1.0, 1.0)
213213
)
214214

215-
assert magnification == pytest.approx(3.6666666666666665, 1.0e-4)
215+
assert magnification == pytest.approx(4.0, 1.0e-4)

test_autoarray/inversion/plot/test_inversion_plotters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test__individual_attributes_are_output_for_all_mappers(
6767
mesh_pixels_per_image_pixels=True,
6868
image_pixels_per_mesh_pixel=True,
6969
errors=True,
70+
signal_to_noise_map=True,
7071
regularization_weights=True,
7172
)
7273

@@ -76,6 +77,7 @@ def test__individual_attributes_are_output_for_all_mappers(
7677
assert path.join(plot_path, "mesh_pixels_per_image_pixels.png") in plot_patch.paths
7778
assert path.join(plot_path, "image_pixels_per_mesh_pixel.png") in plot_patch.paths
7879
assert path.join(plot_path, "errors.png") in plot_patch.paths
80+
assert path.join(plot_path, "signal_to_noise_map.png") in plot_patch.paths
7981
assert path.join(plot_path, "regularization_weights.png") in plot_patch.paths
8082

8183
plot_patch.paths = []

0 commit comments

Comments
 (0)