Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 15, 2024
1 parent 9ebe6f8 commit d4a8ef3
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 149 deletions.
13 changes: 7 additions & 6 deletions autoarray/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -414,15 +418,14 @@ 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),
)

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(),
)
Expand All @@ -431,15 +434,14 @@ 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),
)

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(),
)
Expand All @@ -448,15 +450,14 @@ 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),
)

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(),
)
Expand Down
8 changes: 7 additions & 1 deletion autoarray/inversion/mock/mock_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions autoarray/inversion/pixelization/mappers/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
):
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions autoarray/inversion/pixelization/mappers/delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions autoarray/inversion/pixelization/mappers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
):
Expand Down Expand Up @@ -50,23 +48,20 @@ 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,
)
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,
)
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,
Expand Down
8 changes: 4 additions & 4 deletions autoarray/inversion/pixelization/mappers/rectangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
)
3 changes: 2 additions & 1 deletion autoarray/inversion/pixelization/mappers/voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 11 additions & 3 deletions autoarray/inversion/pixelization/mesh/rectangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions autoarray/inversion/pixelization/mesh/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,36 @@ 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:
raise e

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,
Expand Down
6 changes: 4 additions & 2 deletions autoarray/plot/get_visuals/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions autoarray/plot/mat_plot/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion autoarray/plot/visuals/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
5 changes: 5 additions & 0 deletions test_autoarray/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit d4a8ef3

Please sign in to comment.