diff --git a/autoarray/fixtures.py b/autoarray/fixtures.py index 2ae6c3bc..8b5155f6 100644 --- a/autoarray/fixtures.py +++ b/autoarray/fixtures.py @@ -89,6 +89,10 @@ def make_grid_2d_7x7(): return aa.Grid2D.from_mask(mask=make_mask_2d_7x7()) +def make_grid_2d_sub_1_7x7(): + return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sampling_size=1) + + def make_grid_2d_sub_2_7x7(): return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sampling_size=2) @@ -414,7 +418,7 @@ def make_border_relocator_2d_7x7(): def make_rectangular_mapper_7x7_3x3(): mapper_grids = aa.MapperGrids( mask=make_mask_2d_7x7(), - source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled, + source_plane_data_grid=make_grid_2d_sub_2_7x7(), source_plane_mesh_grid=make_rectangular_mesh_grid_3x3(), image_plane_mesh_grid=None, adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1), @@ -422,7 +426,6 @@ def make_rectangular_mapper_7x7_3x3(): return aa.MapperRectangular( mapper_grids=mapper_grids, - over_sampler=make_grid_2d_sub_2_7x7().over_sampler, border_relocator=make_border_relocator_2d_7x7(), regularization=make_regularization_constant(), ) @@ -431,7 +434,7 @@ def make_rectangular_mapper_7x7_3x3(): def make_delaunay_mapper_9_3x3(): mapper_grids = aa.MapperGrids( mask=make_mask_2d_7x7(), - source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled, + source_plane_data_grid=make_grid_2d_sub_2_7x7(), source_plane_mesh_grid=make_delaunay_mesh_grid_9(), image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1), adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1), @@ -439,7 +442,6 @@ def make_delaunay_mapper_9_3x3(): return aa.MapperDelaunay( mapper_grids=mapper_grids, - over_sampler=make_grid_2d_sub_2_7x7().over_sampler, border_relocator=make_border_relocator_2d_7x7(), regularization=make_regularization_constant(), ) @@ -448,7 +450,7 @@ def make_delaunay_mapper_9_3x3(): def make_voronoi_mapper_9_3x3(): mapper_grids = aa.MapperGrids( mask=make_mask_2d_7x7(), - source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled, + source_plane_data_grid=make_grid_2d_sub_2_7x7(), source_plane_mesh_grid=make_voronoi_mesh_grid_9(), image_plane_mesh_grid=aa.Grid2D.uniform(shape_native=(3, 3), pixel_scales=0.1), adapt_data=aa.Array2D.ones(shape_native=(3, 3), pixel_scales=0.1), @@ -456,7 +458,6 @@ def make_voronoi_mapper_9_3x3(): return aa.MapperVoronoi( mapper_grids=mapper_grids, - over_sampler=make_grid_2d_sub_2_7x7().over_sampler, border_relocator=make_border_relocator_2d_7x7(), regularization=make_regularization_constant(), ) diff --git a/autoarray/inversion/mock/mock_mapper.py b/autoarray/inversion/mock/mock_mapper.py index 6d98aa17..84f90425 100644 --- a/autoarray/inversion/mock/mock_mapper.py +++ b/autoarray/inversion/mock/mock_mapper.py @@ -32,11 +32,11 @@ def __init__( super().__init__( mapper_grids=mapper_grids, - over_sampler=over_sampler, border_relocator=border_relocator, regularization=regularization, ) + self._over_sampler = over_sampler self._edge_pixel_list = edge_pixel_list self._pix_sub_weights = pix_sub_weights self._pix_sub_weights_split_cross = pix_sub_weights_split_cross @@ -56,6 +56,12 @@ def params(self): return super().params return self._parameters + @property + def over_sampler(self): + if self._over_sampler is None: + return super().over_sampler + return self._over_sampler + @property def edge_pixel_list(self): return self._edge_pixel_list diff --git a/autoarray/inversion/pixelization/mappers/abstract.py b/autoarray/inversion/pixelization/mappers/abstract.py index b144c4a6..192fa4f5 100644 --- a/autoarray/inversion/pixelization/mappers/abstract.py +++ b/autoarray/inversion/pixelization/mappers/abstract.py @@ -11,7 +11,6 @@ from autoarray.inversion.pixelization.border_relocator import BorderRelocator from autoarray.inversion.pixelization.mappers.mapper_grids import MapperGrids from autoarray.inversion.regularization.abstract import AbstractRegularization -from autoarray.operators.over_sampling.over_sampler import OverSampler from autoarray.structures.arrays.uniform_2d import Array2D from autoarray.structures.grids.uniform_2d import Grid2D from autoarray.structures.mesh.abstract_2d import Abstract2DMesh @@ -26,7 +25,6 @@ def __init__( self, mapper_grids: MapperGrids, regularization: Optional[AbstractRegularization], - over_sampler: OverSampler, border_relocator: BorderRelocator, run_time_dict: Optional[Dict] = None, ): @@ -82,9 +80,6 @@ def __init__( regularization The regularization scheme which may be applied to this linear object in order to smooth its solution, which for a mapper smooths neighboring pixels on the mesh. - over_sampler - Performs over-sampling whereby the masked image pixels are split into sub-pixels, which are all - mapped via the mapper with sub-fractional values of flux. border_relocator The border relocator, which relocates coordinates outside the border of the source-plane data grid to its edge. @@ -94,7 +89,6 @@ def __init__( super().__init__(regularization=regularization, run_time_dict=run_time_dict) - self.over_sampler = over_sampler self.border_relocator = border_relocator self.mapper_grids = mapper_grids @@ -118,6 +112,10 @@ def source_plane_mesh_grid(self) -> Abstract2DMesh: def image_plane_mesh_grid(self) -> Grid2D: return self.mapper_grids.image_plane_mesh_grid + @property + def over_sampler(self): + return self.mapper_grids.source_plane_data_grid.over_sampler + @property def edge_pixel_list(self) -> List[int]: return self.source_plane_mesh_grid.edge_pixel_list diff --git a/autoarray/inversion/pixelization/mappers/delaunay.py b/autoarray/inversion/pixelization/mappers/delaunay.py index c35c4d9b..b579a1eb 100644 --- a/autoarray/inversion/pixelization/mappers/delaunay.py +++ b/autoarray/inversion/pixelization/mappers/delaunay.py @@ -112,12 +112,14 @@ def pix_sub_weights(self) -> PixSubWeights: delaunay = self.delaunay simplex_index_for_sub_slim_index = delaunay.find_simplex( - self.source_plane_data_grid + self.source_plane_data_grid.grid_over_sampled ) pix_indexes_for_simplex_index = delaunay.simplices mappings, sizes = mapper_util.pix_indexes_for_sub_slim_index_delaunay_from( - source_plane_data_grid=np.array(self.source_plane_data_grid), + source_plane_data_grid=np.array( + self.source_plane_data_grid.grid_over_sampled + ), simplex_index_for_sub_slim_index=simplex_index_for_sub_slim_index, pix_indexes_for_simplex_index=pix_indexes_for_simplex_index, delaunay_points=delaunay.points, @@ -127,7 +129,9 @@ def pix_sub_weights(self) -> PixSubWeights: sizes = sizes.astype("int") weights = mapper_util.pixel_weights_delaunay_from( - source_plane_data_grid=np.array(self.source_plane_data_grid), + source_plane_data_grid=np.array( + self.source_plane_data_grid.grid_over_sampled + ), source_plane_mesh_grid=np.array(self.source_plane_mesh_grid), slim_index_for_sub_slim_index=self.slim_index_for_sub_slim_index, pix_indexes_for_sub_slim_index=mappings, diff --git a/autoarray/inversion/pixelization/mappers/factory.py b/autoarray/inversion/pixelization/mappers/factory.py index 50f056c0..31013320 100644 --- a/autoarray/inversion/pixelization/mappers/factory.py +++ b/autoarray/inversion/pixelization/mappers/factory.py @@ -2,7 +2,6 @@ from autoarray.inversion.pixelization.mappers.mapper_grids import MapperGrids from autoarray.inversion.pixelization.border_relocator import BorderRelocator -from autoarray.operators.over_sampling.over_sampler import OverSampler from autoarray.inversion.regularization.abstract import AbstractRegularization from autoarray.structures.mesh.rectangular_2d import Mesh2DRectangular from autoarray.structures.mesh.delaunay_2d import Mesh2DDelaunay @@ -12,7 +11,6 @@ def mapper_from( mapper_grids: MapperGrids, regularization: Optional[AbstractRegularization], - over_sampler: OverSampler, border_relocator: Optional[BorderRelocator] = None, run_time_dict: Optional[Dict] = None, ): @@ -50,7 +48,6 @@ def mapper_from( if isinstance(mapper_grids.source_plane_mesh_grid, Mesh2DRectangular): return MapperRectangular( mapper_grids=mapper_grids, - over_sampler=over_sampler, border_relocator=border_relocator, regularization=regularization, run_time_dict=run_time_dict, @@ -58,7 +55,6 @@ def mapper_from( elif isinstance(mapper_grids.source_plane_mesh_grid, Mesh2DDelaunay): return MapperDelaunay( mapper_grids=mapper_grids, - over_sampler=over_sampler, border_relocator=border_relocator, regularization=regularization, run_time_dict=run_time_dict, @@ -66,7 +62,6 @@ def mapper_from( elif isinstance(mapper_grids.source_plane_mesh_grid, Mesh2DVoronoi): return MapperVoronoi( mapper_grids=mapper_grids, - over_sampler=over_sampler, border_relocator=border_relocator, regularization=regularization, run_time_dict=run_time_dict, diff --git a/autoarray/inversion/pixelization/mappers/rectangular.py b/autoarray/inversion/pixelization/mappers/rectangular.py index 815e1922..6ae84064 100644 --- a/autoarray/inversion/pixelization/mappers/rectangular.py +++ b/autoarray/inversion/pixelization/mappers/rectangular.py @@ -100,16 +100,16 @@ def pix_sub_weights(self) -> PixSubWeights: are equal to 1.0. """ mappings = geometry_util.grid_pixel_indexes_2d_slim_from( - grid_scaled_2d_slim=np.array(self.source_plane_data_grid), + grid_scaled_2d_slim=np.array(self.source_plane_data_grid.grid_over_sampled), shape_native=self.source_plane_mesh_grid.shape_native, pixel_scales=self.source_plane_mesh_grid.pixel_scales, origin=self.source_plane_mesh_grid.origin, ).astype("int") - mappings = mappings.reshape((len(mappings), 1)) - return PixSubWeights( mappings=mappings.reshape((len(mappings), 1)), sizes=np.ones(len(mappings), dtype="int"), - weights=np.ones((len(self.source_plane_data_grid), 1), dtype="int"), + weights=np.ones( + (len(self.source_plane_data_grid.grid_over_sampled), 1), dtype="int" + ), ) diff --git a/autoarray/inversion/pixelization/mappers/voronoi.py b/autoarray/inversion/pixelization/mappers/voronoi.py index 766a9bcb..b286f5bb 100644 --- a/autoarray/inversion/pixelization/mappers/voronoi.py +++ b/autoarray/inversion/pixelization/mappers/voronoi.py @@ -130,7 +130,8 @@ def pix_sub_weights(self) -> PixSubWeights: """ mappings, sizes, weights = mapper_util.pix_size_weights_voronoi_nn_from( - grid=self.source_plane_data_grid, mesh_grid=self.source_plane_mesh_grid + grid=self.source_plane_data_grid.grid_over_sampled, + mesh_grid=self.source_plane_mesh_grid, ) mappings = mappings.astype("int") diff --git a/autoarray/inversion/pixelization/mesh/rectangular.py b/autoarray/inversion/pixelization/mesh/rectangular.py index 0f4cc204..e5fe9d50 100644 --- a/autoarray/inversion/pixelization/mesh/rectangular.py +++ b/autoarray/inversion/pixelization/mesh/rectangular.py @@ -104,11 +104,19 @@ def mapper_grids_from( self.run_time_dict = run_time_dict - relocated_grid = self.relocated_grid_from( + relocated_grid_over_sampled = self.relocated_grid_from( border_relocator=border_relocator, - source_plane_data_grid=source_plane_data_grid, + source_plane_data_grid=source_plane_data_grid.grid_over_sampled, preloads=preloads, ) + + relocated_grid = Grid2D( + values=source_plane_data_grid, + mask=source_plane_data_grid.mask, + over_sampling_size=source_plane_data_grid.over_sampling_size, + grid_over_sampled=relocated_grid_over_sampled, + ) + mesh_grid = self.mesh_grid_from(source_plane_data_grid=relocated_grid) return MapperGrids( @@ -141,7 +149,7 @@ def mesh_grid_from( by overlaying the `source_plane_data_grid` with the rectangular pixelization. """ return Mesh2DRectangular.overlay_grid( - shape_native=self.shape, grid=source_plane_data_grid + shape_native=self.shape, grid=source_plane_data_grid.grid_over_sampled ) @property diff --git a/autoarray/inversion/pixelization/mesh/triangulation.py b/autoarray/inversion/pixelization/mesh/triangulation.py index 91ee0363..6c499f9f 100644 --- a/autoarray/inversion/pixelization/mesh/triangulation.py +++ b/autoarray/inversion/pixelization/mesh/triangulation.py @@ -70,21 +70,28 @@ def mapper_grids_from( self.run_time_dict = run_time_dict - source_plane_data_grid = self.relocated_grid_from( + relocated_grid_over_sampled = self.relocated_grid_from( border_relocator=border_relocator, - source_plane_data_grid=source_plane_data_grid, + source_plane_data_grid=source_plane_data_grid.grid_over_sampled, preloads=preloads, ) + relocated_grid = Grid2D( + values=source_plane_data_grid, + mask=source_plane_data_grid.mask, + over_sampling_size=source_plane_data_grid.over_sampling_size, + grid_over_sampled=relocated_grid_over_sampled, + ) + relocated_source_plane_mesh_grid = self.relocated_mesh_grid_from( border_relocator=border_relocator, - source_plane_data_grid=source_plane_data_grid, + source_plane_data_grid=relocated_grid_over_sampled, source_plane_mesh_grid=source_plane_mesh_grid, ) try: source_plane_mesh_grid = self.mesh_grid_from( - source_plane_data_grid=source_plane_data_grid, + source_plane_data_grid=relocated_grid_over_sampled, source_plane_mesh_grid=relocated_source_plane_mesh_grid, ) except ValueError as e: @@ -92,7 +99,7 @@ def mapper_grids_from( return MapperGrids( mask=mask, - source_plane_data_grid=source_plane_data_grid, + source_plane_data_grid=relocated_grid, source_plane_mesh_grid=source_plane_mesh_grid, image_plane_mesh_grid=image_plane_mesh_grid, adapt_data=adapt_data, diff --git a/autoarray/plot/get_visuals/two_d.py b/autoarray/plot/get_visuals/two_d.py index 816a9ed8..02f8ee6b 100644 --- a/autoarray/plot/get_visuals/two_d.py +++ b/autoarray/plot/get_visuals/two_d.py @@ -183,11 +183,13 @@ def via_mapper_for_source_from(self, mapper: MapperRectangular) -> Visuals2D: ) grid = self.get( - "grid", mapper.source_plane_data_grid, "mapper_source_plane_data_grid" + "grid", + mapper.source_plane_data_grid.grid_over_sampled, + "mapper_source_plane_data_grid", ) try: - border_grid = mapper.mapper_grids.source_plane_data_grid[ + border_grid = mapper.mapper_grids.source_plane_data_grid.grid_over_sampled[ mapper.border_relocator.sub_border_slim ] border = self.get("border", border_grid) diff --git a/autoarray/plot/mat_plot/two_d.py b/autoarray/plot/mat_plot/two_d.py index 19566050..95f6eb67 100644 --- a/autoarray/plot/mat_plot/two_d.py +++ b/autoarray/plot/mat_plot/two_d.py @@ -610,7 +610,7 @@ def _plot_rectangular_mapper( visuals_2d.plot_via_plotter( plotter=self, - grid_indexes=mapper.source_plane_data_grid, + grid_indexes=mapper.source_plane_data_grid.grid_over_sampled, mapper=mapper, geometry=mapper.mapper_grids.mask.geometry, ) @@ -694,7 +694,7 @@ def _plot_delaunay_mapper( visuals_2d.plot_via_plotter( plotter=self, - grid_indexes=mapper.source_plane_data_grid, + grid_indexes=mapper.source_plane_data_grid.grid_over_sampled, mapper=mapper, geometry=mapper.mapper_grids.mask.geometry, ) @@ -777,7 +777,7 @@ def _plot_voronoi_mapper( visuals_2d.plot_via_plotter( plotter=self, - grid_indexes=mapper.source_plane_data_grid, + grid_indexes=mapper.source_plane_data_grid.grid_over_sampled, mapper=mapper, geometry=mapper.mapper_grids.mask.geometry, ) diff --git a/autoarray/plot/visuals/two_d.py b/autoarray/plot/visuals/two_d.py index 9a5629c9..e92b4100 100644 --- a/autoarray/plot/visuals/two_d.py +++ b/autoarray/plot/visuals/two_d.py @@ -100,6 +100,6 @@ def plot_via_plotter(self, plotter, grid_indexes=None, mapper=None, geometry=Non else: plotter.index_scatter.scatter_grid_indexes( - grid=mapper.source_plane_data_grid, + grid=mapper.source_plane_data_grid.grid_over_sampled, indexes=indexes, ) diff --git a/test_autoarray/conftest.py b/test_autoarray/conftest.py index 0d5437d7..1dbe19e1 100644 --- a/test_autoarray/conftest.py +++ b/test_autoarray/conftest.py @@ -84,6 +84,11 @@ def make_grid_2d_7x7(): return fixtures.make_grid_2d_7x7() +@pytest.fixture(name="grid_2d_sub_1_7x7") +def make_grid_2d_sub_1_7x7(): + return fixtures.make_grid_2d_sub_1_7x7() + + @pytest.fixture(name="grid_2d_irregular_7x7") def make_grid_2d_irregular_7x7(): return fixtures.make_grid_2d_irregular_7x7() diff --git a/test_autoarray/inversion/inversion/imaging/test_inversion_imaging_util.py b/test_autoarray/inversion/inversion/imaging/test_inversion_imaging_util.py index 495b6886..957c68c3 100644 --- a/test_autoarray/inversion/inversion/imaging/test_inversion_imaging_util.py +++ b/test_autoarray/inversion/inversion/imaging/test_inversion_imaging_util.py @@ -193,12 +193,11 @@ def test__data_vector_via_w_tilde_data_two_methods_agree(): mapper_grids = pixelization.mapper_grids_from( mask=mask, border_relocator=None, - source_plane_data_grid=grid.grid_over_sampled, + source_plane_data_grid=grid, ) mapper = aa.Mapper( mapper_grids=mapper_grids, - over_sampler=grid.over_sampler, regularization=None, ) @@ -269,14 +268,7 @@ def test__curvature_matrix_via_w_tilde_two_methods_agree(): source_plane_data_grid=mask.derive_grid.unmasked, ) - over_sampler = aa.OverSampler( - mask=mask, - sub_size=1, - ) - - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) mapping_matrix = mapper.mapping_matrix @@ -321,12 +313,11 @@ def test__curvature_matrix_via_w_tilde_preload_two_methods_agree(): mapper_grids = pixelization.mapper_grids_from( mask=mask, border_relocator=None, - source_plane_data_grid=grid.grid_over_sampled, + source_plane_data_grid=grid, ) mapper = aa.Mapper( mapper_grids=mapper_grids, - over_sampler=grid.over_sampler, regularization=None, ) diff --git a/test_autoarray/inversion/inversion/test_abstract.py b/test_autoarray/inversion/inversion/test_abstract.py index 48f89851..4bb153b7 100644 --- a/test_autoarray/inversion/inversion/test_abstract.py +++ b/test_autoarray/inversion/inversion/test_abstract.py @@ -114,7 +114,7 @@ def test__curvature_matrix__via_w_tilde__identical_to_mapping(): pixel_scales=2.0, ) - grid = aa.Grid2D.from_mask(mask=mask) + grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=1) mesh_0 = aa.mesh.Rectangular(shape=(3, 3)) mesh_1 = aa.mesh.Rectangular(shape=(4, 4)) @@ -135,14 +135,8 @@ def test__curvature_matrix__via_w_tilde__identical_to_mapping(): reg = aa.reg.Constant(coefficient=1.0) - over_sampler = aa.OverSampler(mask=mask, sub_size=1) - - mapper_0 = aa.Mapper( - mapper_grids=mapper_grids_0, over_sampler=over_sampler, regularization=reg - ) - mapper_1 = aa.Mapper( - mapper_grids=mapper_grids_1, over_sampler=over_sampler, regularization=reg - ) + mapper_0 = aa.Mapper(mapper_grids=mapper_grids_0, regularization=reg) + mapper_1 = aa.Mapper(mapper_grids=mapper_grids_1, regularization=reg) image = aa.Array2D.no_mask(values=np.random.random((7, 7)), pixel_scales=1.0) noise_map = aa.Array2D.no_mask(values=np.random.random((7, 7)), pixel_scales=1.0) @@ -184,7 +178,7 @@ def test__curvature_matrix_via_w_tilde__includes_source_interpolation__identical pixel_scales=2.0, ) - grid = aa.Grid2D.from_mask(mask=mask) + grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=1) mesh_0 = aa.mesh.Delaunay() mesh_1 = aa.mesh.Delaunay() @@ -216,14 +210,8 @@ def test__curvature_matrix_via_w_tilde__includes_source_interpolation__identical reg = aa.reg.Constant(coefficient=1.0) - over_sampler = aa.OverSampler(mask=mask, sub_size=1) - - mapper_0 = aa.Mapper( - mapper_grids=mapper_grids_0, over_sampler=over_sampler, regularization=reg - ) - mapper_1 = aa.Mapper( - mapper_grids=mapper_grids_1, over_sampler=over_sampler, regularization=reg - ) + mapper_0 = aa.Mapper(mapper_grids=mapper_grids_0, regularization=reg) + mapper_1 = aa.Mapper(mapper_grids=mapper_grids_1, regularization=reg) image = aa.Array2D.no_mask(values=np.random.random((7, 7)), pixel_scales=1.0) noise_map = aa.Array2D.no_mask(values=np.random.random((7, 7)), pixel_scales=1.0) diff --git a/test_autoarray/inversion/pixelization/mappers/test_abstract.py b/test_autoarray/inversion/pixelization/mappers/test_abstract.py index 1baf2f5f..8e154b21 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_abstract.py +++ b/test_autoarray/inversion/pixelization/mappers/test_abstract.py @@ -180,9 +180,7 @@ def test__interpolated_array_from(grid_2d_7x7): source_plane_mesh_grid=mesh_grid, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=None, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) interpolated_array_via_mapper = mapper.interpolated_array_from( values=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), @@ -204,6 +202,7 @@ def test__mapped_to_source_from(grid_2d_7x7): values=[[0.1, 0.1], [1.1, 0.6], [2.1, 0.1], [0.4, 1.1], [1.1, 7.1], [2.1, 1.1]], shape_native=(3, 2), pixel_scales=1.0, + over_sampling_size=1, ) mesh_grid = aa.Mesh2DDelaunay(values=mesh_grid) @@ -214,11 +213,7 @@ def test__mapped_to_source_from(grid_2d_7x7): source_plane_mesh_grid=mesh_grid, ) - over_sampler = aa.OverSampler(mask=grid_2d_7x7.mask, sub_size=1) - - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) array_slim = aa.Array2D.no_mask( [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], diff --git a/test_autoarray/inversion/pixelization/mappers/test_delaunay.py b/test_autoarray/inversion/pixelization/mappers/test_delaunay.py index 3aaaefb6..dd8a654f 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_delaunay.py +++ b/test_autoarray/inversion/pixelization/mappers/test_delaunay.py @@ -2,26 +2,23 @@ import autoarray as aa -def test__pix_indexes_for_sub_slim_index__matches_util(grid_2d_7x7): +def test__pix_indexes_for_sub_slim_index__matches_util(grid_2d_sub_1_7x7): mesh_grid = aa.Grid2D.no_mask( values=[[0.1, 0.1], [1.1, 0.6], [2.1, 0.1], [0.4, 1.1], [1.1, 7.1], [2.1, 1.1]], shape_native=(3, 2), pixel_scales=1.0, + over_sampling_size=1, ) mesh_grid = aa.Mesh2DDelaunay(values=mesh_grid) mapper_grids = aa.MapperGrids( - mask=grid_2d_7x7.mask, - source_plane_data_grid=grid_2d_7x7, + mask=grid_2d_sub_1_7x7.mask, + source_plane_data_grid=grid_2d_sub_1_7x7, source_plane_mesh_grid=mesh_grid, ) - over_sampler = aa.OverSampler(mask=grid_2d_7x7.mask, sub_size=1) - - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) simplex_index_for_sub_slim_index = mapper.delaunay.find_simplex( mapper.source_plane_data_grid diff --git a/test_autoarray/inversion/pixelization/mappers/test_factory.py b/test_autoarray/inversion/pixelization/mappers/test_factory.py index 7bbeacb9..e5018c54 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_factory.py +++ b/test_autoarray/inversion/pixelization/mappers/test_factory.py @@ -20,23 +20,20 @@ def test__rectangular_mapper(): ) # Slightly manipulate input grid so sub gridding is evidence in first source pixel. - over_sampler = aa.OverSampler(mask=mask, sub_size=2) - grid_over_sampled = over_sampler.uniform_over_sampled - grid_over_sampled[0, 0] = -2.0 - grid_over_sampled[0, 1] = 2.0 + grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=2) + grid.grid_over_sampled[0, 0] = -2.0 + grid.grid_over_sampled[0, 1] = 2.0 mesh = aa.mesh.Rectangular(shape=(3, 3)) mapper_grids = mesh.mapper_grids_from( mask=mask, border_relocator=None, - source_plane_data_grid=grid_over_sampled, + source_plane_data_grid=grid, source_plane_mesh_grid=None, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert isinstance(mapper, aa.MapperRectangular) assert mapper.image_plane_mesh_grid == None @@ -73,10 +70,10 @@ def test__delaunay_mapper(): ) # Slightly manipulate input grid so sub gridding is evidence in first source pixel. - over_sampler = aa.OverSampler(mask=mask, sub_size=2) - grid_over_sampled = over_sampler.uniform_over_sampled - grid_over_sampled[0, 0] = -2.0 - grid_over_sampled[0, 1] = 2.0 + grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=2) + + grid.grid_over_sampled[0, 0] = -2.0 + grid.grid_over_sampled[0, 1] = 2.0 mesh = aa.mesh.Delaunay() image_mesh = aa.image_mesh.Overlay(shape=(3, 3)) @@ -87,13 +84,11 @@ def test__delaunay_mapper(): mapper_grids = mesh.mapper_grids_from( mask=mask, border_relocator=None, - source_plane_data_grid=grid_over_sampled, + source_plane_data_grid=grid, source_plane_mesh_grid=image_plane_mesh_grid, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert isinstance(mapper, aa.MapperDelaunay) assert (mapper.source_plane_mesh_grid == image_plane_mesh_grid).all() @@ -131,10 +126,10 @@ def test__voronoi_mapper(): ) # Slightly manipulate input grid so sub gridding is evidence in first source pixel. - over_sampler = aa.OverSampler(mask=mask, sub_size=2) - grid_over_sampled = over_sampler.uniform_over_sampled - grid_over_sampled[0, 0] = -2.0 - grid_over_sampled[0, 1] = 2.0 + grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=2) + + grid.grid_over_sampled[0, 0] = -2.0 + grid.grid_over_sampled[0, 1] = 2.0 mesh = aa.mesh.Voronoi() image_mesh = aa.image_mesh.Overlay(shape=(3, 3)) @@ -145,13 +140,11 @@ def test__voronoi_mapper(): mapper_grids = mesh.mapper_grids_from( mask=mask, border_relocator=None, - source_plane_data_grid=grid_over_sampled, + source_plane_data_grid=grid, source_plane_mesh_grid=image_plane_mesh_grid, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert (mapper.source_plane_mesh_grid == image_plane_mesh_grid).all() assert mapper.source_plane_mesh_grid.origin == pytest.approx((0.0, 0.0), 1.0e-4) diff --git a/test_autoarray/inversion/pixelization/mappers/test_rectangular.py b/test_autoarray/inversion/pixelization/mappers/test_rectangular.py index 2f945024..4901477d 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_rectangular.py +++ b/test_autoarray/inversion/pixelization/mappers/test_rectangular.py @@ -18,24 +18,23 @@ def test__pix_indexes_for_sub_slim_index__matches_util(): ], pixel_scales=1.0, shape_native=(3, 3), + over_sampling_size=1, ) - mesh_grid = aa.Mesh2DRectangular.overlay_grid(shape_native=(3, 3), grid=grid) + mesh_grid = aa.Mesh2DRectangular.overlay_grid( + shape_native=(3, 3), grid=grid.grid_over_sampled + ) mapper_grids = aa.MapperGrids( mask=grid.mask, source_plane_data_grid=grid, source_plane_mesh_grid=mesh_grid ) - over_sampler = aa.OverSampler(mask=grid.mask, sub_size=1) - - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) pix_indexes_for_sub_slim_index_util = np.array( [ aa.util.geometry.grid_pixel_indexes_2d_slim_from( - grid_scaled_2d_slim=np.array(grid), + grid_scaled_2d_slim=np.array(grid.grid_over_sampled), shape_native=mesh_grid.shape_native, pixel_scales=mesh_grid.pixel_scales, origin=mesh_grid.origin, @@ -48,21 +47,19 @@ def test__pix_indexes_for_sub_slim_index__matches_util(): ).all() -def test__pixel_signals_from__matches_util(grid_2d_7x7, image_7x7): - mesh_grid = aa.Mesh2DRectangular.overlay_grid(shape_native=(3, 3), grid=grid_2d_7x7) - - over_sampler = aa.OverSampler(mask=grid_2d_7x7.mask, sub_size=1) +def test__pixel_signals_from__matches_util(grid_2d_sub_1_7x7, image_7x7): + mesh_grid = aa.Mesh2DRectangular.overlay_grid( + shape_native=(3, 3), grid=grid_2d_sub_1_7x7.grid_over_sampled + ) mapper_grids = aa.MapperGrids( - mask=grid_2d_7x7.mask, - source_plane_data_grid=grid_2d_7x7, + mask=grid_2d_sub_1_7x7.mask, + source_plane_data_grid=grid_2d_sub_1_7x7, source_plane_mesh_grid=mesh_grid, adapt_data=image_7x7, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) pixel_signals = mapper.pixel_signals_from(signal_scale=2.0) @@ -72,7 +69,7 @@ def test__pixel_signals_from__matches_util(grid_2d_7x7, image_7x7): pix_indexes_for_sub_slim_index=mapper.pix_indexes_for_sub_slim_index, pix_size_for_sub_slim_index=mapper.pix_sizes_for_sub_slim_index, pixel_weights=mapper.pix_weights_for_sub_slim_index, - slim_index_for_sub_slim_index=over_sampler.slim_for_sub_slim, + slim_index_for_sub_slim_index=grid_2d_sub_1_7x7.over_sampler.slim_for_sub_slim, adapt_data=np.array(image_7x7), ) diff --git a/test_autoarray/inversion/pixelization/mappers/test_voronoi.py b/test_autoarray/inversion/pixelization/mappers/test_voronoi.py index 9a84e7ef..8b54842e 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_voronoi.py +++ b/test_autoarray/inversion/pixelization/mappers/test_voronoi.py @@ -3,26 +3,25 @@ import autoarray as aa -def test__pix_indexes_for_sub_slim_index__matches_util(grid_2d_7x7): +def test__pix_indexes_for_sub_slim_index__matches_util(grid_2d_sub_1_7x7): source_plane_mesh_grid = aa.Grid2D.no_mask( values=[[0.1, 0.1], [1.1, 0.6], [2.1, 0.1], [0.4, 1.1], [1.1, 7.1], [2.1, 1.1]], shape_native=(3, 2), pixel_scales=1.0, + over_sampling_size=1, ) source_plane_mesh_grid = aa.Mesh2DVoronoi( values=source_plane_mesh_grid, ) - over_sampler = aa.OverSampler(mask=grid_2d_7x7.mask, sub_size=1) - source_plane_mesh_grid = aa.Mesh2DVoronoi( values=source_plane_mesh_grid, ) mapper_grids = aa.MapperGrids( - mask=grid_2d_7x7.mask, - source_plane_data_grid=grid_2d_7x7, + mask=grid_2d_sub_1_7x7.mask, + source_plane_data_grid=grid_2d_sub_1_7x7, source_plane_mesh_grid=source_plane_mesh_grid, ) pytest.importorskip( @@ -30,16 +29,14 @@ def test__pix_indexes_for_sub_slim_index__matches_util(grid_2d_7x7): reason="Voronoi C library not installed, see util.nn README.md", ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=over_sampler, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) ( pix_indexes_for_sub_slim_index_util, sizes, weights, ) = aa.util.mapper.pix_size_weights_voronoi_nn_from( - grid=grid_2d_7x7, mesh_grid=source_plane_mesh_grid + grid=grid_2d_sub_1_7x7, mesh_grid=source_plane_mesh_grid ) assert ( diff --git a/test_autoarray/inversion/pixelization/mesh/test_abstract.py b/test_autoarray/inversion/pixelization/mesh/test_abstract.py index ca431fe8..c00b6817 100644 --- a/test_autoarray/inversion/pixelization/mesh/test_abstract.py +++ b/test_autoarray/inversion/pixelization/mesh/test_abstract.py @@ -29,9 +29,7 @@ def test__grid_is_relocated_via_border(grid_2d_7x7): source_plane_mesh_grid=image_mesh, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=None, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert grid[8, 0] != mapper.source_plane_data_grid[8, 0] assert mapper.source_plane_data_grid[8, 0] < 5.0 @@ -48,9 +46,7 @@ def test__grid_is_relocated_via_border(grid_2d_7x7): source_plane_mesh_grid=image_mesh, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=None, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert isinstance(mapper, aa.MapperDelaunay) assert image_mesh[0, 0] != mapper.source_plane_mesh_grid[0, 0] @@ -67,9 +63,7 @@ def test__grid_is_relocated_via_border(grid_2d_7x7): source_plane_mesh_grid=image_mesh, ) - mapper = aa.Mapper( - mapper_grids=mapper_grids, over_sampler=None, regularization=None - ) + mapper = aa.Mapper(mapper_grids=mapper_grids, regularization=None) assert isinstance(mapper, aa.MapperDelaunay) assert image_mesh[0, 0] != mapper.source_plane_mesh_grid[0, 0] diff --git a/test_autoarray/inversion/plot/test_mapper_plotters.py b/test_autoarray/inversion/plot/test_mapper_plotters.py index 85ac07f8..7990a900 100644 --- a/test_autoarray/inversion/plot/test_mapper_plotters.py +++ b/test_autoarray/inversion/plot/test_mapper_plotters.py @@ -67,9 +67,12 @@ def test__get_2d__via_mapper_for_source_from(rectangular_mapper_7x7_3x3): assert mapper_plotter.visuals_2d.origin == None assert get_2d.origin.in_list == [(0.0, 0.0)] - assert (get_2d.grid == rectangular_mapper_7x7_3x3.source_plane_data_grid).all() + assert ( + get_2d.grid + == rectangular_mapper_7x7_3x3.source_plane_data_grid.grid_over_sampled + ).all() assert (get_2d.mesh_grid == rectangular_mapper_7x7_3x3.source_plane_mesh_grid).all() - border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid[ + border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid.grid_over_sampled[ rectangular_mapper_7x7_3x3.border_relocator.sub_border_slim ] assert (get_2d.border == border_grid).all() diff --git a/test_autoarray/plot/get_visuals/test_two_d.py b/test_autoarray/plot/get_visuals/test_two_d.py index c74a2ff0..51e81838 100644 --- a/test_autoarray/plot/get_visuals/test_two_d.py +++ b/test_autoarray/plot/get_visuals/test_two_d.py @@ -107,9 +107,10 @@ def test__via_mapper_for_source_from(rectangular_mapper_7x7_3x3): assert visuals_2d.origin == (1.0, 1.0) assert ( - visuals_2d_via.grid == rectangular_mapper_7x7_3x3.source_plane_data_grid + visuals_2d_via.grid + == rectangular_mapper_7x7_3x3.source_plane_data_grid.grid_over_sampled ).all() - border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid[ + border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid.grid_over_sampled[ rectangular_mapper_7x7_3x3.border_relocator.sub_border_slim ] assert (visuals_2d_via.border == border_grid).all()