Skip to content

Commit a6c811b

Browse files
Jammy2211Jammy2211
authored andcommitted
move and fix max pixel functions, fully remove mapper valued
1 parent 821fe39 commit a6c811b

File tree

5 files changed

+29
-66
lines changed

5 files changed

+29
-66
lines changed

autoarray/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from .inversion.inversion.abstract import AbstractInversion
3535
from .inversion.regularization.abstract import AbstractRegularization
3636
from .inversion.inversion.factory import inversion_from as Inversion
37-
from .inversion.inversion.mapper_valued import MapperValued
3837
from .inversion.inversion.dataset_interface import DatasetInterface
3938
from .inversion.pixelization.border_relocator import BorderRelocator
4039
from .inversion.pixelization.pixelization import Pixelization

autoarray/inversion/inversion/abstract.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from autoarray.inversion.inversion.settings import SettingsInversion
1515
from autoarray.preloads import Preloads
1616
from autoarray.structures.arrays.uniform_2d import Array2D
17+
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
1718
from autoarray.structures.visibilities import Visibilities
1819

1920
from autoarray.util import misc_util
@@ -756,7 +757,7 @@ def mapper_operated_mapping_matrix_dict(self) -> Dict:
756757
raise NotImplementedError
757758

758759
def max_pixel_list_from(
759-
self, total_pixels: int = 1, filter_neighbors: bool = False
760+
self, total_pixels: int = 1, filter_neighbors: bool = False, mapper_index : int = 0
760761
) -> List[List[int]]:
761762
"""
762763
Returns a list of lists of the maximum cell or pixel values in the mapper.
@@ -782,23 +783,26 @@ def max_pixel_list_from(
782783
-------
783784
784785
"""
786+
mapper = self.cls_list_from(cls=AbstractMapper)[mapper_index]
787+
reconstruction = self.reconstruction_dict[mapper]
788+
785789
max_pixel_list = []
786790

787791
pixel_list = []
788792

789-
pixels_ascending_list = list(reversed(np.argsort(self.values_masked)))
793+
pixels_ascending_list = list(reversed(np.argsort(reconstruction)))
790794

791795
for pixel in range(total_pixels):
792796
pixel_index = pixels_ascending_list[pixel]
793797

794798
add_pixel = True
795799

796800
if filter_neighbors:
797-
pixel_neighbors = self.mapper.neighbors[pixel_index]
801+
pixel_neighbors = mapper.neighbors[pixel_index]
798802
pixel_neighbors = pixel_neighbors[pixel_neighbors >= 0]
799803

800-
max_value = self.values_masked[pixel_index]
801-
max_value_neighbors = self.values_masked[pixel_neighbors]
804+
max_value = reconstruction[pixel_index]
805+
max_value_neighbors = reconstruction[pixel_neighbors]
802806

803807
if max_value < np.max(max_value_neighbors):
804808
add_pixel = False
@@ -810,19 +814,21 @@ def max_pixel_list_from(
810814

811815
return max_pixel_list
812816

813-
@property
814-
def max_pixel_centre(self) -> Grid2DIrregular:
817+
def max_pixel_centre(self, mapper_index : int = 0) -> Grid2DIrregular:
815818
"""
816819
Returns the centre of the brightest pixel in the mapper values.
817820
818821
Returns
819822
-------
820823
The centre of the brightest pixel in the mapper values.
821824
"""
822-
max_pixel = np.argmax(self.values_masked)
825+
mapper = self.cls_list_from(cls=AbstractMapper)[mapper_index]
826+
reconstruction = self.reconstruction_dict[mapper]
827+
828+
max_pixel = np.argmax(reconstruction)
823829

824830
max_pixel_centre = Grid2DIrregular(
825-
values=[self.mapper.source_plane_mesh_grid.array[max_pixel]]
831+
values=[mapper.source_plane_mesh_grid.array[max_pixel]]
826832
)
827833

828834
return max_pixel_centre

autoarray/inversion/inversion/mapper_valued.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

autoarray/inversion/plot/inversion_plotters.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from autoarray.plot.auto_labels import AutoLabels
1010
from autoarray.structures.arrays.uniform_2d import Array2D
1111
from autoarray.inversion.inversion.abstract import AbstractInversion
12-
from autoarray.inversion.inversion.mapper_valued import MapperValued
1312
from autoarray.inversion.plot.mapper_plotters import MapperPlotter
1413

1514

@@ -414,12 +413,10 @@ def subplot_mappings(
414413

415414
mapper = self.inversion.cls_list_from(cls=AbstractMapper)[pixelization_index]
416415

417-
mapper_valued = MapperValued(
418-
values=self.inversion.reconstruction_dict[mapper], mapper=mapper
419-
)
420-
421-
pix_indexes = mapper_valued.max_pixel_list_from(
422-
total_pixels=total_pixels, filter_neighbors=True
416+
pix_indexes = self.inversion.max_pixel_list_from(
417+
total_pixels=total_pixels,
418+
filter_neighbors=True,
419+
mapper_index=pixelization_index
423420
)
424421

425422
indexes = mapper.slim_indexes_for_pix_indexes(pix_indexes=pix_indexes)

test_autoarray/inversion/inversion/test_abstract.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,19 +523,21 @@ def test__max_pixel_list_from_and_centre():
523523
)
524524
)
525525

526-
mapper_valued = aa.MapperValued(
527-
values=np.array([2.0, 3.0, 5.0, 0.0]), mapper=mapper
526+
inversion = aa.m.MockInversion(
527+
reconstruction=np.array([2.0, 3.0, 5.0, 0.0]),
528+
linear_obj_list=[mapper]
528529
)
529530

530-
assert mapper_valued.max_pixel_list_from(total_pixels=2)[0] == [
531+
assert inversion.max_pixel_list_from(total_pixels=2)[0] == [
531532
2,
532533
1,
533534
]
534535

535-
assert mapper_valued.max_pixel_centre.in_list == [(5.0, 6.0)]
536+
assert inversion.max_pixel_centre().in_list == [(5.0, 6.0)]
536537

537538

538539
def test__max_pixel_list_from__filter_neighbors():
540+
539541
mapper = aa.m.MockMapper(
540542
source_plane_mesh_grid=aa.Mesh2DDelaunay(
541543
[
@@ -552,11 +554,12 @@ def test__max_pixel_list_from__filter_neighbors():
552554
)
553555
)
554556

555-
mapper_valued = aa.MapperValued(
556-
values=np.array([5.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]), mapper=mapper
557+
inversion = aa.m.MockInversion(
558+
reconstruction=np.array([5.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]),
559+
linear_obj_list=[mapper]
557560
)
558561

559-
pixel_list = mapper_valued.max_pixel_list_from(
562+
pixel_list = inversion.max_pixel_list_from(
560563
total_pixels=9, filter_neighbors=True
561564
)
562565

0 commit comments

Comments
 (0)