Skip to content

Commit 8e3fa55

Browse files
Jammy2211Jammy2211
authored andcommitted
simplify image mesh tests to not use SettingsInversion
1 parent ee5637d commit 8e3fa55

10 files changed

Lines changed: 38 additions & 43 deletions

File tree

autoarray/inversion/mock/mock_image_mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, image_plane_mesh_grid=None):
1414
self.image_plane_mesh_grid = image_plane_mesh_grid
1515

1616
def image_plane_mesh_grid_from(
17-
self, mask: Mask2D, adapt_data: Optional[np.ndarray], settings=None
17+
self, mask: Mask2D, adapt_data: Optional[np.ndarray],
1818
) -> Grid2DIrregular:
1919
if adapt_data is not None and self.image_plane_mesh_grid is not None:
2020
return adapt_data * self.image_plane_mesh_grid

autoarray/inversion/mock/mock_mesh.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def image_plane_mesh_grid_from(
3737
self,
3838
mask: Mask2D,
3939
adapt_data,
40-
settings=None,
4140
):
4241
if adapt_data is not None and self.image_plane_mesh_grid is not None:
4342
return adapt_data * self.image_plane_mesh_grid

autoarray/inversion/mock/mock_pixelization.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ def __init__(
1010
mapper=None,
1111
image_plane_mesh_grid=None,
1212
):
13-
super().__init__(
14-
mesh=mesh, regularization=regularization
15-
)
13+
super().__init__(mesh=mesh, regularization=regularization)
1614

1715
self.mapper = mapper
1816
self.image_plane_mesh_grid = image_plane_mesh_grid

autoarray/inversion/pixelization/image_mesh/abstract.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def image_plane_mesh_grid_from(
3030
self,
3131
mask: Mask2D,
3232
adapt_data: Optional[np.ndarray] = None,
33-
settings: SettingsInversion = None,
3433
) -> Grid2DIrregular:
3534
raise NotImplementedError
3635

autoarray/inversion/pixelization/image_mesh/hilbert.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,14 @@ def image_plane_mesh_grid_from(
300300

301301
return mesh_grid
302302

303-
304303
def check_mesh_pixels_per_image_pixels(
305-
self, mask: Mask2D, mesh_grid: Grid2DIrregular, settings: SettingsInversion
304+
self,
305+
mask: Mask2D,
306+
mesh_grid: Grid2DIrregular,
307+
image_mesh_min_mesh_pixels_per_pixel=None,
308+
image_mesh_min_mesh_number: int = 5,
309+
image_mesh_adapt_background_percent_threshold: float = None,
310+
image_mesh_adapt_background_percent_check: float = 0.8,
306311
):
307312
"""
308313
Checks the number of mesh pixels in every image pixel and raises an `InversionException` if there are fewer
@@ -315,12 +320,12 @@ def check_mesh_pixels_per_image_pixels(
315320
316321
1) Compute the 2D array of the number of mesh pixels in every masked data image pixel.
317322
2) Find the number of mesh pixels in the N data pixels with the larger number of mesh pixels, where N is
318-
given by `settings.image_mesh_min_mesh_number`. For example, if `settings.image_mesh_min_mesh_number=5` then
323+
given by `image_mesh_min_mesh_number`. For example, if `image_mesh_min_mesh_number=5` then
319324
the number of mesh pixels in the 5 data pixels with the most data pixels is computed.
320-
3) Compare the lowest value above to the value `settings.image_mesh_min_mesh_pixels_per_pixel`. If the value is
325+
3) Compare the lowest value above to the value `image_mesh_min_mesh_pixels_per_pixel`. If the value is
321326
below this value, raise an `InversionException`.
322327
323-
Therefore, by settings `settings.image_mesh_min_mesh_pixels_per_pixel` to a value above 1 the code is forced
328+
Therefore, by settings `image_mesh_min_mesh_pixels_per_pixel` to a value above 1 the code is forced
324329
to adapt the image mesh enough to put many mesh pixels in the brightest image pixels.
325330
326331
Parameters
@@ -340,19 +345,19 @@ def check_mesh_pixels_per_image_pixels(
340345
return
341346

342347
if settings is not None:
343-
if settings.image_mesh_min_mesh_pixels_per_pixel is not None:
348+
if image_mesh_min_mesh_pixels_per_pixel is not None:
344349
mesh_pixels_per_image_pixels = self.mesh_pixels_per_image_pixels_from(
345350
mask=mask, mesh_grid=mesh_grid
346351
)
347352

348353
indices_of_highest_values = np.argsort(mesh_pixels_per_image_pixels)[
349-
-settings.image_mesh_min_mesh_number :
354+
-image_mesh_min_mesh_number:
350355
]
351356
lowest_mesh_pixels = np.min(
352357
mesh_pixels_per_image_pixels[indices_of_highest_values]
353358
)
354359

355-
if lowest_mesh_pixels < settings.image_mesh_min_mesh_pixels_per_pixel:
360+
if lowest_mesh_pixels < image_mesh_min_mesh_pixels_per_pixel:
356361
raise exc.InversionException()
357362

358363
return mesh_grid
@@ -362,7 +367,10 @@ def check_adapt_background_pixels(
362367
mask: Mask2D,
363368
mesh_grid: Grid2DIrregular,
364369
adapt_data: Optional[np.ndarray],
365-
settings: SettingsInversion,
370+
image_mesh_min_mesh_pixels_per_pixel=None,
371+
image_mesh_min_mesh_number: int = 5,
372+
image_mesh_adapt_background_percent_threshold: float = None,
373+
image_mesh_adapt_background_percent_check: float = 0.8,
366374
):
367375
"""
368376
Checks the number of mesh pixels in the background of the image-mesh and raises an `InversionException` if
@@ -375,15 +383,15 @@ def check_adapt_background_pixels(
375383
The check works as follows:
376384
377385
1) Find all pixels in the background of the `adapt_data`, which are N pixels with the lowest values, where N is
378-
a percentage given by `settings.image_mesh_adapt_background_percent_check`. If N is 50%, then the half of
386+
a percentage given by `image_mesh_adapt_background_percent_check`. If N is 50%, then the half of
379387
pixels in `adapt_data` with the lowest values will be checked.
380388
2) Sum the total number of mesh pixels in these background pixels, thereby estimating the number of mesh pixels
381389
assigned to background pixels.
382390
3) Compare this value to the total number of mesh pixels multiplied
383-
by `settings.image_mesh_adapt_background_percent_threshold` and raise an `InversionException` if the number
391+
by `image_mesh_adapt_background_percent_threshold` and raise an `InversionException` if the number
384392
of mesh pixels is below this value, meaning the background did not have sufficient mesh pixels in it.
385393
386-
Therefore, by setting `settings.image_mesh_adapt_background_percent_threshold` the code is forced
394+
Therefore, by setting `image_mesh_adapt_background_percent_threshold` the code is forced
387395
to adapt the image mesh in a way that places many mesh pixels in the background regions.
388396
389397
Parameters
@@ -405,11 +413,11 @@ def check_adapt_background_pixels(
405413
return
406414

407415
if settings is not None:
408-
if settings.image_mesh_adapt_background_percent_threshold is not None:
416+
if image_mesh_adapt_background_percent_threshold is not None:
409417
pixels = mesh_grid.shape[0]
410418

411419
pixels_in_background = int(
412-
mask.shape_slim * settings.image_mesh_adapt_background_percent_check
420+
mask.shape_slim * image_mesh_adapt_background_percent_check
413421
)
414422

415423
indices_of_lowest_values = np.argsort(adapt_data)[:pixels_in_background]
@@ -425,6 +433,6 @@ def check_adapt_background_pixels(
425433
)
426434

427435
if mesh_pixels_in_background < (
428-
pixels * settings.image_mesh_adapt_background_percent_threshold
436+
pixels * image_mesh_adapt_background_percent_threshold
429437
):
430438
raise exc.InversionException()

autoarray/inversion/pixelization/image_mesh/kmeans.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def image_plane_mesh_grid_from(
5252
self,
5353
mask: Mask2D,
5454
adapt_data: Optional[np.ndarray],
55-
settings: SettingsInversion = None,
5655
) -> Grid2DIrregular:
5756
"""
5857
Returns an image mesh by running a KMeans clustering algorithm on the weight map.

autoarray/inversion/pixelization/image_mesh/overlay.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ def image_plane_mesh_grid_from(
186186
self,
187187
mask: Mask2D,
188188
adapt_data: Optional[np.ndarray] = None,
189-
settings: SettingsInversion = None,
190189
) -> Grid2DIrregular:
191190
"""
192191
Returns an image-mesh by overlaying a uniform grid of (y,x) coordinates over the masked image that the

autoarray/preloads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
self,
2323
mapper_indices: np.ndarray = None,
2424
source_pixel_zeroed_indices: np.ndarray = None,
25-
image_plane_mesh_grid : np.ndarray = None,
25+
image_plane_mesh_grid: np.ndarray = None,
2626
linear_light_profile_blurred_mapping_matrix=None,
2727
):
2828
"""

autoarray/structures/grids/uniform_2d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ def over_sampler(self):
197197

198198
from autoarray.operators.over_sampling.over_sampler import OverSampler
199199

200-
self._over_sampler = OverSampler(sub_size=self.over_sample_size.array.astype("int"), mask=self.mask)
200+
self._over_sampler = OverSampler(
201+
sub_size=self.over_sample_size.array.astype("int"), mask=self.mask
202+
)
201203

202204
return self._over_sampler
203205

test_autoarray/inversion/pixelization/image_mesh/test_abstract.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,28 @@ def test__mesh_pixels_per_image_pixels_from(mask, mesh_grid, image_mesh):
4444

4545
def test__check_mesh_pixels_per_image_pixels(mask, mesh_grid, image_mesh):
4646
image_mesh.check_mesh_pixels_per_image_pixels(
47-
mask=mask, mesh_grid=mesh_grid, settings=None
47+
mask=mask, mesh_grid=mesh_grid,
4848
)
4949

5050
image_mesh.check_mesh_pixels_per_image_pixels(
5151
mask=mask,
5252
mesh_grid=mesh_grid,
53-
settings=aa.SettingsInversion(
54-
image_mesh_min_mesh_pixels_per_pixel=3, image_mesh_min_mesh_number=1
55-
),
53+
image_mesh_min_mesh_pixels_per_pixel=3,
54+
image_mesh_min_mesh_number=1
5655
)
5756

5857
with pytest.raises(aa.exc.InversionException):
5958
image_mesh.check_mesh_pixels_per_image_pixels(
6059
mask=mask,
6160
mesh_grid=mesh_grid,
62-
settings=aa.SettingsInversion(
63-
image_mesh_min_mesh_pixels_per_pixel=5, image_mesh_min_mesh_number=1
64-
),
61+
image_mesh_min_mesh_pixels_per_pixel=5, image_mesh_min_mesh_number=1
6562
)
6663

6764
with pytest.raises(aa.exc.InversionException):
6865
image_mesh.check_mesh_pixels_per_image_pixels(
6966
mask=mask,
7067
mesh_grid=mesh_grid,
71-
settings=aa.SettingsInversion(
72-
image_mesh_min_mesh_pixels_per_pixel=3, image_mesh_min_mesh_number=2
73-
),
68+
image_mesh_min_mesh_pixels_per_pixel=3, image_mesh_min_mesh_number=2
7469
)
7570

7671

@@ -88,19 +83,15 @@ def test__check_adapt_background_pixels(mask, mesh_grid, image_mesh):
8883
mask=mask,
8984
mesh_grid=mesh_grid,
9085
adapt_data=adapt_data,
91-
settings=aa.SettingsInversion(
92-
image_mesh_adapt_background_percent_threshold=0.05,
93-
image_mesh_adapt_background_percent_check=0.9,
94-
),
86+
image_mesh_adapt_background_percent_threshold=0.05,
87+
image_mesh_adapt_background_percent_check=0.9,
9588
)
9689

9790
with pytest.raises(aa.exc.InversionException):
9891
image_mesh.check_adapt_background_pixels(
9992
mask=mask,
10093
mesh_grid=mesh_grid,
10194
adapt_data=adapt_data,
102-
settings=aa.SettingsInversion(
103-
image_mesh_adapt_background_percent_threshold=0.8,
104-
image_mesh_adapt_background_percent_check=0.5,
105-
),
95+
image_mesh_adapt_background_percent_threshold=0.8,
96+
image_mesh_adapt_background_percent_check=0.5,
10697
)

0 commit comments

Comments
 (0)