From 305f50eda2fc74f397e49f1384dd0d88a751a1d3 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 16 Dec 2024 15:36:16 +0000 Subject: [PATCH] simplify grid over sampled API --- autoarray/fixtures.py | 2 +- autoarray/inversion/pixelization/border_relocator.py | 8 ++++---- autoarray/inversion/pixelization/mappers/delaunay.py | 6 +++--- .../inversion/pixelization/mappers/rectangular.py | 4 ++-- autoarray/inversion/pixelization/mappers/voronoi.py | 2 +- autoarray/inversion/pixelization/mesh/rectangular.py | 2 +- .../inversion/pixelization/mesh/triangulation.py | 4 ++-- autoarray/operators/over_sampling/decorator.py | 4 ++-- autoarray/plot/get_visuals/two_d.py | 4 ++-- autoarray/plot/mat_plot/two_d.py | 6 +++--- autoarray/plot/visuals/two_d.py | 2 +- autoarray/structures/decorators/to_grid.py | 12 ++++++------ autoarray/structures/grids/uniform_2d.py | 8 ++++---- .../inversion/pixelization/mappers/test_factory.py | 12 ++++++------ .../pixelization/mappers/test_rectangular.py | 6 +++--- .../inversion/pixelization/test_border_relocator.py | 12 ++++++------ .../inversion/plot/test_mapper_plotters.py | 4 ++-- .../operators/over_sample/test_decorator.py | 2 +- test_autoarray/plot/get_visuals/test_two_d.py | 4 ++-- 19 files changed, 52 insertions(+), 52 deletions(-) diff --git a/autoarray/fixtures.py b/autoarray/fixtures.py index 7e76c9b6..ff684ec4 100644 --- a/autoarray/fixtures.py +++ b/autoarray/fixtures.py @@ -359,7 +359,7 @@ def make_regularization_matern_kernel(): def make_rectangular_mesh_grid_3x3(): return aa.Mesh2DRectangular.overlay_grid( - grid=make_grid_2d_sub_2_7x7().grid_over_sampled, shape_native=(3, 3) + grid=make_grid_2d_sub_2_7x7().over_sampled, shape_native=(3, 3) ) diff --git a/autoarray/inversion/pixelization/border_relocator.py b/autoarray/inversion/pixelization/border_relocator.py index dfdf5610..6870f9a3 100644 --- a/autoarray/inversion/pixelization/border_relocator.py +++ b/autoarray/inversion/pixelization/border_relocator.py @@ -276,16 +276,16 @@ def relocated_grid_from(self, grid: Grid2D) -> Grid2D: border_grid=np.array(grid[self.border_slim]), ) - grid_over_sampled = grid_2d_util.relocated_grid_via_jit_from( - grid=np.array(grid.grid_over_sampled), - border_grid=np.array(grid.grid_over_sampled[self.sub_border_slim]), + over_sampled = grid_2d_util.relocated_grid_via_jit_from( + grid=np.array(grid.over_sampled), + border_grid=np.array(grid.over_sampled[self.sub_border_slim]), ) return Grid2D( values=values, mask=grid.mask, over_sampling_size=self.sub_size, - grid_over_sampled=grid_over_sampled, + over_sampled=over_sampled, ) def relocated_mesh_grid_from( diff --git a/autoarray/inversion/pixelization/mappers/delaunay.py b/autoarray/inversion/pixelization/mappers/delaunay.py index b579a1eb..f18c3b39 100644 --- a/autoarray/inversion/pixelization/mappers/delaunay.py +++ b/autoarray/inversion/pixelization/mappers/delaunay.py @@ -112,13 +112,13 @@ def pix_sub_weights(self) -> PixSubWeights: delaunay = self.delaunay simplex_index_for_sub_slim_index = delaunay.find_simplex( - self.source_plane_data_grid.grid_over_sampled + self.source_plane_data_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.grid_over_sampled + self.source_plane_data_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, @@ -130,7 +130,7 @@ def pix_sub_weights(self) -> PixSubWeights: weights = mapper_util.pixel_weights_delaunay_from( source_plane_data_grid=np.array( - self.source_plane_data_grid.grid_over_sampled + self.source_plane_data_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, diff --git a/autoarray/inversion/pixelization/mappers/rectangular.py b/autoarray/inversion/pixelization/mappers/rectangular.py index 6001792f..9a78c1b8 100644 --- a/autoarray/inversion/pixelization/mappers/rectangular.py +++ b/autoarray/inversion/pixelization/mappers/rectangular.py @@ -100,7 +100,7 @@ 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_over_sampled), + grid_scaled_2d_slim=np.array(self.source_plane_data_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, @@ -112,6 +112,6 @@ def pix_sub_weights(self) -> PixSubWeights: mappings=mappings, sizes=np.ones(len(mappings), dtype="int"), weights=np.ones( - (len(self.source_plane_data_grid.grid_over_sampled), 1), dtype="int" + (len(self.source_plane_data_grid.over_sampled), 1), dtype="int" ), ) diff --git a/autoarray/inversion/pixelization/mappers/voronoi.py b/autoarray/inversion/pixelization/mappers/voronoi.py index b286f5bb..c8e54cbf 100644 --- a/autoarray/inversion/pixelization/mappers/voronoi.py +++ b/autoarray/inversion/pixelization/mappers/voronoi.py @@ -130,7 +130,7 @@ def pix_sub_weights(self) -> PixSubWeights: """ mappings, sizes, weights = mapper_util.pix_size_weights_voronoi_nn_from( - grid=self.source_plane_data_grid.grid_over_sampled, + grid=self.source_plane_data_grid.over_sampled, mesh_grid=self.source_plane_mesh_grid, ) diff --git a/autoarray/inversion/pixelization/mesh/rectangular.py b/autoarray/inversion/pixelization/mesh/rectangular.py index acfb8680..e6bf2d0a 100644 --- a/autoarray/inversion/pixelization/mesh/rectangular.py +++ b/autoarray/inversion/pixelization/mesh/rectangular.py @@ -142,7 +142,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.grid_over_sampled + shape_native=self.shape, grid=source_plane_data_grid.over_sampled ) @property diff --git a/autoarray/inversion/pixelization/mesh/triangulation.py b/autoarray/inversion/pixelization/mesh/triangulation.py index 9696af07..453f762e 100644 --- a/autoarray/inversion/pixelization/mesh/triangulation.py +++ b/autoarray/inversion/pixelization/mesh/triangulation.py @@ -78,13 +78,13 @@ def mapper_grids_from( relocated_mesh_grid = self.relocated_mesh_grid_from( border_relocator=border_relocator, - source_plane_data_grid=relocated_grid.grid_over_sampled, + 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=relocated_grid.grid_over_sampled, + source_plane_data_grid=relocated_grid.over_sampled, source_plane_mesh_grid=relocated_mesh_grid, ) except ValueError as e: diff --git a/autoarray/operators/over_sampling/decorator.py b/autoarray/operators/over_sampling/decorator.py index 1e1e5bd8..c028ee31 100644 --- a/autoarray/operators/over_sampling/decorator.py +++ b/autoarray/operators/over_sampling/decorator.py @@ -52,9 +52,9 @@ def wrapper( return func(obj=obj, grid=grid, *args, **kwargs) if obj is not None: - values = func(obj, grid.grid_over_sampled, *args, **kwargs) + values = func(obj, grid.over_sampled, *args, **kwargs) else: - values = func(grid.grid_over_sampled, *args, **kwargs) + values = func(grid.over_sampled, *args, **kwargs) return grid.over_sampler.binned_array_2d_from(array=values) diff --git a/autoarray/plot/get_visuals/two_d.py b/autoarray/plot/get_visuals/two_d.py index 02f8ee6b..c2b99a17 100644 --- a/autoarray/plot/get_visuals/two_d.py +++ b/autoarray/plot/get_visuals/two_d.py @@ -184,12 +184,12 @@ def via_mapper_for_source_from(self, mapper: MapperRectangular) -> Visuals2D: grid = self.get( "grid", - mapper.source_plane_data_grid.grid_over_sampled, + mapper.source_plane_data_grid.over_sampled, "mapper_source_plane_data_grid", ) try: - border_grid = mapper.mapper_grids.source_plane_data_grid.grid_over_sampled[ + border_grid = mapper.mapper_grids.source_plane_data_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 95f6eb67..24b62e6e 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_over_sampled, + grid_indexes=mapper.source_plane_data_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_over_sampled, + grid_indexes=mapper.source_plane_data_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_over_sampled, + grid_indexes=mapper.source_plane_data_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 e92b4100..d1da534f 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_over_sampled, + grid=mapper.source_plane_data_grid.over_sampled, indexes=indexes, ) diff --git a/autoarray/structures/decorators/to_grid.py b/autoarray/structures/decorators/to_grid.py index 0ea63190..62d7b870 100644 --- a/autoarray/structures/decorators/to_grid.py +++ b/autoarray/structures/decorators/to_grid.py @@ -23,19 +23,19 @@ def via_grid_2d(self, result) -> Union[Grid2D, List[Grid2D]]: """ if not isinstance(result, list): try: - grid_over_sampled = result.grid_over_sampled + over_sampled = result.over_sampled except AttributeError: - grid_over_sampled = None + over_sampled = None return Grid2D( values=result, mask=self.mask, over_sampling_size=self.over_sampling_size, - grid_over_sampled=grid_over_sampled, + over_sampled=over_sampled, ) try: - grid_over_sampled_list = [res.grid_over_sampled for res in result] + grid_over_sampled_list = [res.over_sampled for res in result] except AttributeError: grid_over_sampled_list = [None] * len(result) @@ -44,9 +44,9 @@ def via_grid_2d(self, result) -> Union[Grid2D, List[Grid2D]]: values=res, mask=self.mask, over_sampling_size=self.over_sampling_size, - grid_over_sampled=grid_over_sampled, + over_sampled=over_sampled, ) - for res, grid_over_sampled in zip(result, grid_over_sampled_list) + for res, over_sampled in zip(result, grid_over_sampled_list) ] def via_grid_2d_irr(self, result) -> Union[Grid2DIrregular, List[Grid2DIrregular]]: diff --git a/autoarray/structures/grids/uniform_2d.py b/autoarray/structures/grids/uniform_2d.py index 36fba67b..523a9645 100644 --- a/autoarray/structures/grids/uniform_2d.py +++ b/autoarray/structures/grids/uniform_2d.py @@ -27,7 +27,7 @@ def __init__( mask: Mask2D, store_native: bool = False, over_sampling_size: Union[int, Array2D] = 4, - grid_over_sampled: Optional[Grid2D] = None, + over_sampled: Optional[Grid2D] = None, *args, **kwargs, ): @@ -177,8 +177,8 @@ def __init__( self.over_sampler = OverSampler(sub_size=over_sampling_size, mask=mask) - if grid_over_sampled is None: - self.grid_over_sampled = ( + if over_sampled is None: + self.over_sampled = ( over_sample_util.grid_2d_slim_over_sampled_via_mask_from( mask_2d=np.array(self.mask), pixel_scales=self.mask.pixel_scales, @@ -188,7 +188,7 @@ def __init__( ) else: - self.grid_over_sampled = grid_over_sampled + self.over_sampled = over_sampled @classmethod def no_mask( diff --git a/test_autoarray/inversion/pixelization/mappers/test_factory.py b/test_autoarray/inversion/pixelization/mappers/test_factory.py index e5018c54..83fc4940 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_factory.py +++ b/test_autoarray/inversion/pixelization/mappers/test_factory.py @@ -21,8 +21,8 @@ def test__rectangular_mapper(): # Slightly manipulate input grid so sub gridding is evidence in first source pixel. 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 + grid.over_sampled[0, 0] = -2.0 + grid.over_sampled[0, 1] = 2.0 mesh = aa.mesh.Rectangular(shape=(3, 3)) @@ -72,8 +72,8 @@ def test__delaunay_mapper(): # Slightly manipulate input grid so sub gridding is evidence in first source pixel. 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 + grid.over_sampled[0, 0] = -2.0 + grid.over_sampled[0, 1] = 2.0 mesh = aa.mesh.Delaunay() image_mesh = aa.image_mesh.Overlay(shape=(3, 3)) @@ -128,8 +128,8 @@ def test__voronoi_mapper(): # Slightly manipulate input grid so sub gridding is evidence in first source pixel. 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 + grid.over_sampled[0, 0] = -2.0 + grid.over_sampled[0, 1] = 2.0 mesh = aa.mesh.Voronoi() image_mesh = aa.image_mesh.Overlay(shape=(3, 3)) diff --git a/test_autoarray/inversion/pixelization/mappers/test_rectangular.py b/test_autoarray/inversion/pixelization/mappers/test_rectangular.py index 4901477d..aee46356 100644 --- a/test_autoarray/inversion/pixelization/mappers/test_rectangular.py +++ b/test_autoarray/inversion/pixelization/mappers/test_rectangular.py @@ -22,7 +22,7 @@ def test__pix_indexes_for_sub_slim_index__matches_util(): ) mesh_grid = aa.Mesh2DRectangular.overlay_grid( - shape_native=(3, 3), grid=grid.grid_over_sampled + shape_native=(3, 3), grid=grid.over_sampled ) mapper_grids = aa.MapperGrids( @@ -34,7 +34,7 @@ def test__pix_indexes_for_sub_slim_index__matches_util(): 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_over_sampled), + grid_scaled_2d_slim=np.array(grid.over_sampled), shape_native=mesh_grid.shape_native, pixel_scales=mesh_grid.pixel_scales, origin=mesh_grid.origin, @@ -49,7 +49,7 @@ def test__pix_indexes_for_sub_slim_index__matches_util(): 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 + shape_native=(3, 3), grid=grid_2d_sub_1_7x7.over_sampled ) mapper_grids = aa.MapperGrids( diff --git a/test_autoarray/inversion/pixelization/test_border_relocator.py b/test_autoarray/inversion/pixelization/test_border_relocator.py index e4861954..6eccee10 100644 --- a/test_autoarray/inversion/pixelization/test_border_relocator.py +++ b/test_autoarray/inversion/pixelization/test_border_relocator.py @@ -328,7 +328,7 @@ def test__relocated_grid_from__inside_border_no_relocations(): grid = aa.Grid2D.from_mask( mask=mask, over_sampling_size=np.array(mask.pixels_in_mask * [2]) ) - grid.grid_over_sampled[1, :] = [0.1, 0.1] + grid.over_sampled[1, :] = [0.1, 0.1] border_relocator = aa.BorderRelocator( mask=mask, sub_size=np.array(mask.pixels_in_mask * [2]) @@ -336,7 +336,7 @@ def test__relocated_grid_from__inside_border_no_relocations(): relocated_grid = border_relocator.relocated_grid_from(grid=grid) - assert (relocated_grid.grid_over_sampled[1] == np.array([0.1, 0.1])).all() + assert (relocated_grid.over_sampled[1] == np.array([0.1, 0.1])).all() def test__relocated_grid_from__outside_border_includes_relocations(): @@ -347,7 +347,7 @@ def test__relocated_grid_from__outside_border_includes_relocations(): grid = aa.Grid2D.from_mask( mask=mask, over_sampling_size=np.array(mask.pixels_in_mask * [2]) ) - grid.grid_over_sampled[1, :] = [10.1, 0.1] + grid.over_sampled[1, :] = [10.1, 0.1] border_relocator = aa.BorderRelocator( mask=mask, sub_size=np.array(mask.pixels_in_mask * [2]) @@ -355,7 +355,7 @@ def test__relocated_grid_from__outside_border_includes_relocations(): relocated_grid = border_relocator.relocated_grid_from(grid=grid) - assert relocated_grid.grid_over_sampled[1] == pytest.approx( + assert relocated_grid.over_sampled[1] == pytest.approx( [0.97783243, 0.00968151], 1e-4 ) @@ -369,10 +369,10 @@ def test__relocated_grid_from__positive_origin_included_in_relocate(): ) grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=2) - grid.grid_over_sampled[1, :] = [11.1, 1.0] + grid.over_sampled[1, :] = [11.1, 1.0] border_relocator = aa.BorderRelocator(mask=mask, sub_size=grid.over_sampling_size) relocated_grid = border_relocator.relocated_grid_from(grid=grid) - assert relocated_grid.grid_over_sampled[1] == pytest.approx([1.97783243, 1.0], 1e-4) + assert relocated_grid.over_sampled[1] == pytest.approx([1.97783243, 1.0], 1e-4) diff --git a/test_autoarray/inversion/plot/test_mapper_plotters.py b/test_autoarray/inversion/plot/test_mapper_plotters.py index 7990a900..00b72457 100644 --- a/test_autoarray/inversion/plot/test_mapper_plotters.py +++ b/test_autoarray/inversion/plot/test_mapper_plotters.py @@ -69,10 +69,10 @@ def test__get_2d__via_mapper_for_source_from(rectangular_mapper_7x7_3x3): assert get_2d.origin.in_list == [(0.0, 0.0)] assert ( get_2d.grid - == rectangular_mapper_7x7_3x3.source_plane_data_grid.grid_over_sampled + == rectangular_mapper_7x7_3x3.source_plane_data_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.grid_over_sampled[ + border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid.over_sampled[ rectangular_mapper_7x7_3x3.border_relocator.sub_border_slim ] assert (get_2d.border == border_grid).all() diff --git a/test_autoarray/operators/over_sample/test_decorator.py b/test_autoarray/operators/over_sample/test_decorator.py index 7091ba66..c98de7db 100644 --- a/test_autoarray/operators/over_sample/test_decorator.py +++ b/test_autoarray/operators/over_sample/test_decorator.py @@ -34,7 +34,7 @@ def test__in_grid_2d__over_sample_uniform__out_ndarray_1d(): mask_sub_2 = aa.Mask2D(mask=mask_sub_2, pixel_scales=(0.5, 0.5)) - grid = aa.Grid2D(values=grid_2d.grid_over_sampled, mask=mask_sub_2) + grid = aa.Grid2D(values=grid_2d.over_sampled, mask=mask_sub_2) ndarray_1d_via_grid = obj.ndarray_1d_from(grid=grid) diff --git a/test_autoarray/plot/get_visuals/test_two_d.py b/test_autoarray/plot/get_visuals/test_two_d.py index 51e81838..af576f41 100644 --- a/test_autoarray/plot/get_visuals/test_two_d.py +++ b/test_autoarray/plot/get_visuals/test_two_d.py @@ -108,9 +108,9 @@ 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.grid_over_sampled + == rectangular_mapper_7x7_3x3.source_plane_data_grid.over_sampled ).all() - border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid.grid_over_sampled[ + border_grid = rectangular_mapper_7x7_3x3.mapper_grids.source_plane_data_grid.over_sampled[ rectangular_mapper_7x7_3x3.border_relocator.sub_border_slim ] assert (visuals_2d_via.border == border_grid).all()