Skip to content

Commit 898703b

Browse files
Jammy2211Jammy2211
authored andcommitted
remove magnification_via methods
1 parent b83197d commit 898703b

6 files changed

Lines changed: 6 additions & 294 deletions

File tree

autoarray/inversion/inversion/mapper_valued.py

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -169,112 +169,4 @@ def mapped_reconstructed_image_from(
169169
xp=self.mapper._xp,
170170
),
171171
mask=self.mapper.mapper_grids.mask,
172-
)
173-
174-
def magnification_via_mesh_from(
175-
self,
176-
) -> float:
177-
"""
178-
Returns the magnification of the reconstruction computed via the mesh, where the magnification is the ratio
179-
of the surface brightness of image in the image-plane over the surface brightness of the source in
180-
the source-plane.
181-
182-
In the image-plane, this is computed by mapping the reconstruction to the image, summing all reconstructed
183-
values and multiplying by the area of each image pixel. This image-plane image is not convolved with the
184-
PSF, as the source plane reconstruction is a non-convolved image.
185-
186-
In the source-plane, this is computed by summing the reconstruction values multiplied by the area of each
187-
mesh pixel, for example if the source-plane is a `Delaunay` mesh this is the area of each corresponding
188-
Delaunay pixel.
189-
190-
This calculatiion is generally more robust that using an interpolated
191-
image (see `magnification_via_interpolation_from`), because it uses the exact the source-plane reconstruction
192-
values. However, certain meshes have irregular pixels, especially at the edge, which can produce large
193-
areas that can artificially decrease the magnification. Including cuts on which source-plane pixels are used,
194-
for example based on brightness, is recommended to ensure the magnification is robust.
195-
196-
Parameters
197-
----------
198-
mesh_pixel_mask
199-
The mask of pixels that are omitted from the reconstruction when computing the image, for example to
200-
remove pixels with low signal-to-noise so they do not impact the magnification calculation.
201-
202-
Returns
203-
-------
204-
The magnification of the reconstruction computed via the mesh.
205-
"""
206-
207-
if isinstance(self.mapper, MapperDelaunay):
208-
raise exc.MeshException(
209-
"""
210-
The method `magnification_via_mesh_from` does not currently support `Delaunay` mesh objects.
211-
212-
To compute the magnification of a `Delaunay` mesh, use the method `magnification_via_interpolation_from`.
213-
214-
This method only supports a `RectangularAdaptDensity`.
215-
"""
216-
)
217-
218-
mapped_reconstructed_image = self.mapped_reconstructed_image_from()
219-
220-
try:
221-
mesh_areas = self.mapper.source_plane_mesh_grid.areas_for_magnification
222-
except AttributeError:
223-
mesh_areas = self.mapper.areas_for_magnification
224-
225-
if np.all(mesh_areas == 0.0):
226-
raise exc.MeshException(
227-
"""
228-
The magnification cannot be computed because the areas of the source-plane mesh pixels are all zero.
229-
230-
This probably means you have specified an invalid source-plane mesh.
231-
"""
232-
)
233-
234-
return np.sum(
235-
mapped_reconstructed_image * mapped_reconstructed_image.pixel_area
236-
) / np.sum(self.values_masked * mesh_areas)
237-
238-
def magnification_via_interpolation_from(
239-
self,
240-
shape_native: Tuple[int, int] = (201, 201),
241-
extent: Optional[Tuple[float, float, float, float]] = None,
242-
) -> float:
243-
"""
244-
Returns the magnification of the reconstruction computed via interpolation, where the magnification is the ratio
245-
of the surface brightness of image in the image-plane over the surface brightness of the source in
246-
the source-plane.
247-
248-
In the image-plane, this is computed by mapping the reconstruction to the image, summing all reconstructed
249-
values and multiplying by the area of each image pixel. This image-plane image is not convolved with the
250-
PSF, as the source plane reconstruction is a non-convolved image. This image therefore does not use
251-
interpolation.
252-
253-
In the source-plane, this is computed by interpolating the reconstruction to a regular grid of pixels, for
254-
example a 2D grid of 401 x 401 pixels, and summing the reconstruction values multiplied by the area of each
255-
pixel. This calculation uses interpolation to compute the source-plane image.
256-
257-
This calculation is generally less robust than using the mesh to compute the magnification,
258-
(see `magnification_via_mesh_from`), as the interpolation may not perfectly represent the source-plane
259-
reconstruction. However, it is computationally faster and can be used when the source-plane mesh has
260-
irregular pixels that are not suitable for computing the magnification.
261-
262-
Parameters
263-
----------
264-
mesh_pixel_mask
265-
The mask of pixels that are omitted from the reconstruction when computing the image, for example to
266-
remove pixels with low signal-to-noise so they do not impact the magnification calculation.
267-
268-
Returns
269-
-------
270-
The magnification of the reconstruction computed via interpolation.
271-
"""
272-
mapped_reconstructed_image = self.mapped_reconstructed_image_from()
273-
274-
interpolated_reconstruction = self.interpolated_array_from(
275-
shape_native=shape_native, extent=extent
276-
)
277-
278-
return np.sum(
279-
mapped_reconstructed_image * mapped_reconstructed_image.pixel_area
280-
) / np.sum(interpolated_reconstruction * interpolated_reconstruction.pixel_area)
172+
)

autoarray/inversion/plot/inversion_plotters.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def figures_2d_of_pixelization(
102102
image_pixels_per_mesh_pixel: bool = False,
103103
magnification_per_mesh_pixel: bool = False,
104104
zoom_to_brightest: bool = True,
105-
interpolate_to_uniform: bool = False,
106105
):
107106
"""
108107
Plots the individual attributes of a specific `Mapper` of the plotter's `Inversion` object in 2D.
@@ -137,9 +136,6 @@ def figures_2d_of_pixelization(
137136
zoom_to_brightest
138137
For images not in the image-plane (e.g. the `plane_image`), whether to automatically zoom the plot to
139138
the brightest regions of the galaxies being plotted as opposed to the full extent of the grid.
140-
interpolate_to_uniform
141-
If `True`, the mapper's reconstruction is interpolated to a uniform grid before plotting, for example
142-
meaning that an irregular Delaunay grid can be plotted as a uniform grid.
143139
"""
144140

145141
if not self.inversion.has(cls=AbstractMapper):
@@ -199,7 +195,6 @@ def figures_2d_of_pixelization(
199195
mapper_plotter.plot_source_from(
200196
pixel_values=pixel_values,
201197
zoom_to_brightest=zoom_to_brightest,
202-
interpolate_to_uniform=interpolate_to_uniform,
203198
auto_labels=AutoLabels(
204199
title="Source Reconstruction", filename="reconstruction"
205200
),

autoarray/inversion/plot/mapper_plotters.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,19 @@ def __init__(
4747
self.mapper = mapper
4848

4949
def figure_2d(
50-
self, interpolate_to_uniform: bool = False, solution_vector: bool = None
50+
self, solution_vector: bool = None
5151
):
5252
"""
5353
Plots the plotter's `Mapper` object in 2D.
5454
5555
Parameters
5656
----------
57-
interpolate_to_uniform
58-
By default, the mesh's reconstruction is interpolated to a uniform 2D array for plotting. If the
59-
reconstruction can be plotted in an alternative format (e.g. using a Delaunay mesh)
60-
settings `interpolate_to_uniform=False` plots the reconstruction using this.
6157
solution_vector
6258
A vector of values which can culor the pixels of the mapper's source pixels.
6359
"""
6460
self.mat_plot_2d.plot_mapper(
6561
mapper=self.mapper,
6662
visuals_2d=self.visuals_2d,
67-
interpolate_to_uniform=interpolate_to_uniform,
6863
pixel_values=solution_vector,
6964
auto_labels=AutoLabels(
7065
title="Pixelization Mesh (Source-Plane)", filename="mapper"
@@ -83,7 +78,7 @@ def figure_2d_image(self, image):
8378
)
8479

8580
def subplot_image_and_mapper(
86-
self, image: Array2D, interpolate_to_uniform: bool = False
81+
self, image: Array2D,
8782
):
8883
"""
8984
Make a subplot of an input image and the `Mapper`'s source-plane reconstruction.
@@ -94,17 +89,13 @@ def subplot_image_and_mapper(
9489
9590
Parameters
9691
----------
97-
interpolate_to_uniform
98-
By default, the mesh's reconstruction is interpolated to a uniform 2D array for plotting. If the
99-
reconstruction can be plotted in an alternative format (e.g. a Delaunay mesh)
100-
settings `interpolate_to_uniform=False` plots the reconstruction using this.
10192
image
10293
The image which is plotted on the subplot.
10394
"""
10495
self.open_subplot_figure(number_subplots=2)
10596

10697
self.figure_2d_image(image=image)
107-
self.figure_2d(interpolate_to_uniform=interpolate_to_uniform)
98+
self.figure_2d()
10899

109100
self.mat_plot_2d.output.subplot_to_figure(
110101
auto_filename="subplot_image_and_mapper"
@@ -115,7 +106,6 @@ def plot_source_from(
115106
self,
116107
pixel_values: np.ndarray,
117108
zoom_to_brightest: bool = True,
118-
interpolate_to_uniform: bool = False,
119109
auto_labels: AutoLabels = AutoLabels(),
120110
):
121111
"""
@@ -128,9 +118,6 @@ def plot_source_from(
128118
zoom_to_brightest
129119
For images not in the image-plane (e.g. the `plane_image`), whether to automatically zoom the plot to
130120
the brightest regions of the galaxies being plotted as opposed to the full extent of the grid.
131-
interpolate_to_uniform
132-
If `True`, the mapper's reconstruction is interpolated to a uniform grid before plotting, for example
133-
meaning that an irregular Delaunay grid can be plotted as a uniform grid.
134121
auto_labels
135122
The labels given to the figure.
136123
"""
@@ -141,7 +128,6 @@ def plot_source_from(
141128
auto_labels=auto_labels,
142129
pixel_values=pixel_values,
143130
zoom_to_brightest=zoom_to_brightest,
144-
interpolate_to_uniform=interpolate_to_uniform,
145131
)
146132
except ValueError:
147133
logger.info(

autoarray/plot/mat_plot/two_d.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ def plot_mapper(
486486
mapper: MapperRectangular,
487487
visuals_2d: Visuals2D,
488488
auto_labels: AutoLabels,
489-
interpolate_to_uniform: bool = False,
490489
pixel_values: np.ndarray = Optional[None],
491490
zoom_to_brightest: bool = True,
492491
):
@@ -504,7 +503,6 @@ def plot_mapper(
504503
mapper=mapper,
505504
visuals_2d=visuals_2d,
506505
auto_labels=auto_labels,
507-
interpolate_to_uniform=interpolate_to_uniform,
508506
pixel_values=pixel_values,
509507
zoom_to_brightest=zoom_to_brightest,
510508
)
@@ -650,7 +648,6 @@ def _plot_delaunay_mapper(
650648
mapper: MapperDelaunay,
651649
visuals_2d: Visuals2D,
652650
auto_labels: AutoLabels,
653-
interpolate_to_uniform: bool = False,
654651
pixel_values: np.ndarray = Optional[None],
655652
zoom_to_brightest: bool = True,
656653
):

test_autoarray/inversion/inversion/test_mapper_valued.py

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -51,137 +51,4 @@ def test__max_pixel_list_from__filter_neighbors():
5151
assert pixel_list[0] == [
5252
0,
5353
8,
54-
]
55-
56-
57-
58-
59-
60-
61-
def test__magnification_via_mesh_from():
62-
mask = aa.Mask2D(
63-
mask=np.array(
64-
[
65-
[False, False, False],
66-
[False, False, False],
67-
[False, False, False],
68-
[False, False, False],
69-
]
70-
),
71-
pixel_scales=(0.5, 0.5),
72-
)
73-
74-
magnification = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
75-
76-
source_plane_mesh_grid = aa.Mesh2DDelaunay(
77-
values=np.array(
78-
[
79-
[0.0, 0.0],
80-
[1.0, 0.5],
81-
[0.0, 1.0],
82-
[1.0, 2.0],
83-
[2.0, 1.0],
84-
[2.0, 2.0],
85-
[2.0, 0.0],
86-
[0.0, 2.0],
87-
[1.0, 1.0],
88-
[1.0, 1.0],
89-
]
90-
),
91-
)
92-
93-
mapper = aa.m.MockMapper(
94-
parameters=3,
95-
source_plane_mesh_grid=source_plane_mesh_grid,
96-
mask=mask,
97-
mapping_matrix=np.ones((12, 10)),
98-
)
99-
100-
mapper_valued = aa.MapperValued(values=magnification, mapper=mapper)
101-
102-
magnification = mapper_valued.magnification_via_mesh_from()
103-
104-
assert magnification == pytest.approx(11.7073170731, 1.0e-4)
105-
106-
107-
def test__magnification_via_mesh_from__with_pixel_mask():
108-
mask = aa.Mask2D(
109-
mask=np.array(
110-
[
111-
[False, False, False],
112-
[False, False, False],
113-
[False, False, False],
114-
[False, False, False],
115-
]
116-
),
117-
pixel_scales=(0.5, 0.5),
118-
)
119-
120-
magnification = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
121-
122-
source_plane_mesh_grid = aa.Mesh2DDelaunay(
123-
values=np.array(
124-
[
125-
[0.0, 0.0],
126-
[1.0, 0.5],
127-
[0.0, 1.0],
128-
[1.0, 2.0],
129-
[2.0, 1.0],
130-
[2.0, 2.0],
131-
[2.0, 0.0],
132-
[0.0, 2.0],
133-
[1.0, 1.0],
134-
[1.0, 1.0],
135-
]
136-
),
137-
)
138-
139-
mapper = aa.m.MockMapper(
140-
parameters=3,
141-
source_plane_mesh_grid=source_plane_mesh_grid,
142-
mask=mask,
143-
mapping_matrix=np.ones((12, 10)),
144-
)
145-
146-
mesh_pixel_mask = np.array(
147-
[True, True, True, True, True, True, True, True, False, False]
148-
)
149-
150-
mapper_valued = aa.MapperValued(
151-
values=magnification, mapper=mapper, mesh_pixel_mask=mesh_pixel_mask
152-
)
153-
154-
magnification = mapper_valued.magnification_via_mesh_from()
155-
156-
assert magnification == pytest.approx(4.0, 1.0e-4)
157-
158-
159-
def test__magnification_via_interpolation_from():
160-
mask = aa.Mask2D(
161-
mask=np.array([[False, False], [False, False]]),
162-
pixel_scales=(0.5, 0.5),
163-
)
164-
165-
magnification = aa.Array2D(
166-
values=[0.0, 1.0, 1.0, 1.0],
167-
mask=mask,
168-
)
169-
170-
mapper = aa.m.MockMapper(
171-
parameters=4,
172-
mask=mask,
173-
interpolated_array=magnification,
174-
mapping_matrix=np.ones((4, 4)),
175-
)
176-
177-
mapper_valued = aa.MapperValued(values=np.array(magnification), mapper=mapper)
178-
179-
magnification = mapper_valued.magnification_via_interpolation_from()
180-
181-
assert magnification == pytest.approx(4.0, 1.0e-4)
182-
183-
magnification = mapper_valued.magnification_via_interpolation_from(
184-
shape_native=(3, 3), extent=(-1.0, 1.0, -1.0, 1.0)
185-
)
186-
187-
assert magnification == pytest.approx(4.0, 1.0e-4)
54+
]

0 commit comments

Comments
 (0)