Skip to content

Commit

Permalink
most tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 15, 2024
1 parent a5ddad2 commit eabb866
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 61 deletions.
2 changes: 1 addition & 1 deletion autoarray/dataset/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def blurring(self) -> Optional[Grid2D]:
@cached_property
def border_relocator(self) -> BorderRelocator:
return BorderRelocator(
mask=self.mask, sub_size=self.pixelization.over_sampling.sub_size
mask=self.mask, sub_size=self.pixelization.over_sampling_size
)


Expand Down
18 changes: 11 additions & 7 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_2_7x7():
return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sampling_size=2)


def make_grid_2d_7x7_simple():
grid_2d_7x7 = make_grid_2d_7x7()
grid_2d_7x7[0] = np.array([1.0, 1.0])
Expand Down Expand Up @@ -351,7 +355,7 @@ def make_regularization_matern_kernel():

def make_rectangular_mesh_grid_3x3():
return aa.Mesh2DRectangular.overlay_grid(
grid=make_over_sampler_2d_7x7().over_sampled_grid, shape_native=(3, 3)
grid=make_grid_2d_sub_2_7x7().grid_over_sampled, shape_native=(3, 3)
)


Expand Down Expand Up @@ -410,15 +414,15 @@ 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_over_sampler_2d_7x7().over_sampled_grid,
source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled,
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_over_sampler_2d_7x7(),
over_sampler=make_grid_2d_sub_2_7x7().over_sampler,
border_relocator=make_border_relocator_2d_7x7(),
regularization=make_regularization_constant(),
)
Expand All @@ -427,15 +431,15 @@ 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_over_sampler_2d_7x7().over_sampled_grid,
source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled,
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_over_sampler_2d_7x7(),
over_sampler=make_grid_2d_sub_2_7x7().over_sampler,
border_relocator=make_border_relocator_2d_7x7(),
regularization=make_regularization_constant(),
)
Expand All @@ -444,15 +448,15 @@ 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_over_sampler_2d_7x7().over_sampled_grid,
source_plane_data_grid=make_grid_2d_sub_2_7x7().grid_over_sampled,
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_over_sampler_2d_7x7(),
over_sampler=make_grid_2d_sub_2_7x7().over_sampler,
border_relocator=make_border_relocator_2d_7x7(),
regularization=make_regularization_constant(),
)
Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/linear_obj/func_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def unique_mappings(self) -> UniqueMappings:
For a `LinearObjFuncList` every data pixel's group of sub-pixels maps directly to the linear function.
"""

sub_size = np.max(self.grid.over_sampling.sub_size)
sub_size = np.max(self.grid.over_sampling_size)

# TODO : This shape slim is prob unreliable and needs to be divided by sub_size**2

Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/pixelization/image_mesh/hilbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def super_resolution_grid_from(img_2d, mask, mask_radius, pixel_scales, sub_scal

over_sampler = OverSampler(mask=new_mask, sub_size=sub_scale)

new_grid = over_sampler.over_sampled_grid
new_grid = over_sampler.uniform_over_sampled

new_img = griddata(
points=grid, values=img_2d.ravel(), xi=new_grid, fill_value=0.0, method="linear"
Expand Down
4 changes: 2 additions & 2 deletions autoarray/inversion/plot/inversion_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def figures_2d_of_pixelization(
self.mat_plot_2d.plot_array(
array=array,
visuals_2d=self.get_visuals_2d_for_data(),
grid_indexes=mapper_plotter.mapper.over_sampler.over_sampled_grid,
grid_indexes=mapper_plotter.mapper.over_sampler.uniform_over_sampled,
auto_labels=AutoLabels(
title="Data Subtracted", filename="data_subtracted"
),
Expand All @@ -200,7 +200,7 @@ def figures_2d_of_pixelization(
self.mat_plot_2d.plot_array(
array=array,
visuals_2d=self.get_visuals_2d_for_data(),
grid_indexes=mapper_plotter.mapper.over_sampler.over_sampled_grid,
grid_indexes=mapper_plotter.mapper.over_sampler.uniform_over_sampled,
auto_labels=AutoLabels(
title="Reconstructed Image", filename="reconstructed_image"
),
Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/plot/mapper_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def subplot_image_and_mapper(
)

self.mat_plot_2d.index_scatter.scatter_grid_indexes(
grid=self.mapper.over_sampler.over_sampled_grid,
grid=self.mapper.over_sampler.uniform_over_sampled,
indexes=indexes,
)

Expand Down
2 changes: 1 addition & 1 deletion autoarray/operators/over_sampling/over_sample_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def sub_size_radial_bins_from(
return sub_size


# @numba_util.jit()
@numba_util.jit()
def grid_2d_slim_over_sampled_via_mask_from(
mask_2d: np.ndarray,
pixel_scales: ty.PixelScales,
Expand Down
13 changes: 13 additions & 0 deletions autoarray/operators/over_sampling/over_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,16 @@ def slim_for_sub_slim(self) -> np.ndarray:
return over_sample_util.slim_index_for_sub_slim_index_via_mask_2d_from(
mask_2d=np.array(self.mask), sub_size=np.array(self.sub_size)
).astype("int")

@property
def uniform_over_sampled(self):
from autoarray.structures.grids.irregular_2d import Grid2DIrregular

grid = over_sample_util.grid_2d_slim_over_sampled_via_mask_from(
mask_2d=np.array(self.mask),
pixel_scales=self.mask.pixel_scales,
sub_size=np.array(self.sub_size).astype("int"),
origin=self.mask.origin,
)

return Grid2DIrregular(values=grid)
2 changes: 1 addition & 1 deletion autoarray/plot/mat_plot/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def plot_grid(
ax = self.setup_subplot()

if plot_over_sampled_grid:
grid_plot = grid.over_sampler.over_sampled_grid
grid_plot = grid.over_sampler.uniform_over_sampled
else:
grid_plot = grid

Expand Down
2 changes: 1 addition & 1 deletion autoarray/structures/decorators/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def mask(self) -> Union[Mask1D, Mask2D]:
return self.grid.mask

@property
def over_sampling(self) -> np.ndarray:
def over_sampling_size(self) -> np.ndarray:
return self.grid.over_sampling_size

def via_grid_2d(self, result):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,17 @@ def test__data_vector_via_w_tilde_data_two_methods_agree():
# TODO : Use pytest.parameterize

for sub_size in range(1, 3):
over_sampler = aa.OverSampler(
mask=mask,
sub_size=sub_size,
)

grid = over_sampler.over_sampled_grid
grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=sub_size)

mapper_grids = pixelization.mapper_grids_from(
mask=mask, border_relocator=None, source_plane_data_grid=grid
mask=mask,
border_relocator=None,
source_plane_data_grid=grid.grid_over_sampled,
)

mapper = aa.Mapper(
mapper_grids=mapper_grids,
over_sampler=over_sampler,
over_sampler=grid.over_sampler,
regularization=None,
)

Expand Down Expand Up @@ -236,7 +233,7 @@ def test__data_vector_via_w_tilde_data_two_methods_agree():
pix_sizes_for_sub_slim_index=mapper.pix_sizes_for_sub_slim_index,
pix_weights_for_sub_slim_index=mapper.pix_weights_for_sub_slim_index,
pix_pixels=mapper.params,
sub_size=np.array(over_sampler.sub_size),
sub_size=np.array(grid.over_sampling_size),
)

data_vector_via_w_tilde = (
Expand Down Expand Up @@ -319,20 +316,17 @@ def test__curvature_matrix_via_w_tilde_preload_two_methods_agree():
pixelization = aa.mesh.Rectangular(shape=(20, 20))

for sub_size in range(1, 2, 3):
over_sampler = aa.OverSampler(
mask=mask,
sub_size=sub_size,
)

grid = over_sampler.over_sampled_grid
grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=sub_size)

mapper_grids = pixelization.mapper_grids_from(
mask=mask, border_relocator=None, source_plane_data_grid=grid
mask=mask,
border_relocator=None,
source_plane_data_grid=grid.grid_over_sampled,
)

mapper = aa.Mapper(
mapper_grids=mapper_grids,
over_sampler=over_sampler,
over_sampler=grid.over_sampler,
regularization=None,
)

Expand All @@ -358,7 +352,7 @@ def test__curvature_matrix_via_w_tilde_preload_two_methods_agree():
pix_sizes_for_sub_slim_index=mapper.pix_sizes_for_sub_slim_index,
pix_weights_for_sub_slim_index=mapper.pix_weights_for_sub_slim_index,
pix_pixels=mapper.params,
sub_size=np.array(over_sampler.sub_size),
sub_size=np.array(grid.over_sampling_size),
)

curvature_matrix_via_w_tilde = aa.util.inversion_imaging.curvature_matrix_via_w_tilde_curvature_preload_imaging_from(
Expand Down
24 changes: 12 additions & 12 deletions test_autoarray/inversion/pixelization/mappers/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ 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)
over_sampled_grid = over_sampler.over_sampled_grid
over_sampled_grid[0, 0] = -2.0
over_sampled_grid[0, 1] = 2.0
grid_over_sampled = over_sampler.uniform_over_sampled
grid_over_sampled[0, 0] = -2.0
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=over_sampled_grid,
source_plane_data_grid=grid_over_sampled,
source_plane_mesh_grid=None,
)

Expand Down Expand Up @@ -74,9 +74,9 @@ 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)
over_sampled_grid = over_sampler.over_sampled_grid
over_sampled_grid[0, 0] = -2.0
over_sampled_grid[0, 1] = 2.0
grid_over_sampled = over_sampler.uniform_over_sampled
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))
Expand All @@ -87,7 +87,7 @@ def test__delaunay_mapper():
mapper_grids = mesh.mapper_grids_from(
mask=mask,
border_relocator=None,
source_plane_data_grid=over_sampled_grid,
source_plane_data_grid=grid_over_sampled,
source_plane_mesh_grid=image_plane_mesh_grid,
)

Expand Down Expand Up @@ -132,9 +132,9 @@ 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)
over_sampled_grid = over_sampler.over_sampled_grid
over_sampled_grid[0, 0] = -2.0
over_sampled_grid[0, 1] = 2.0
grid_over_sampled = over_sampler.uniform_over_sampled
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))
Expand All @@ -145,7 +145,7 @@ def test__voronoi_mapper():
mapper_grids = mesh.mapper_grids_from(
mask=mask,
border_relocator=None,
source_plane_data_grid=over_sampled_grid,
source_plane_data_grid=grid_over_sampled,
source_plane_mesh_grid=image_plane_mesh_grid,
)

Expand Down
42 changes: 30 additions & 12 deletions test_autoarray/inversion/pixelization/test_border_relocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,16 @@ def test__relocated_grid_from__inside_border_no_relocations():
shape_native=(30, 30), radius=1.0, pixel_scales=(0.1, 0.1)
)

over_sampling = aa.OverSampler(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
grid = aa.Grid2D.from_mask(
mask=mask, over_sampling_size=np.array(mask.pixels_in_mask * [2])
)
grid = over_sampling.over_sampled_grid
grid[1, :] = [0.1, 0.1]
grid.grid_over_sampled[1, :] = [0.1, 0.1]

border_relocator = aa.BorderRelocator(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
)

relocated_grid = border_relocator.relocated_grid_from(grid=grid)
relocated_grid = border_relocator.relocated_grid_from(grid=grid.grid_over_sampled)

assert (relocated_grid[1] == np.array([0.1, 0.1])).all()

Expand All @@ -345,22 +344,21 @@ def test__relocated_grid_from__outside_border_includes_relocations():
shape_native=(30, 30), radius=1.0, pixel_scales=(0.1, 0.1)
)

over_sampling = aa.OverSampler(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
grid = aa.Grid2D.from_mask(
mask=mask, over_sampling_size=np.array(mask.pixels_in_mask * [2])
)
grid = over_sampling.over_sampled_grid
grid[1, :] = [10.1, 0.1]
grid.grid_over_sampled[1, :] = [10.1, 0.1]

border_relocator = aa.BorderRelocator(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
)

relocated_grid = border_relocator.relocated_grid_from(grid=grid)
relocated_grid = border_relocator.relocated_grid_from(grid=grid.grid_over_sampled)

assert relocated_grid[1] == pytest.approx([0.97783243, 0.00968151], 1e-4)


def test__relocated_grid_from__positive_origin_included_in_relocate():
def test__relocated_grid_from__positive_origin_includeddfdsd_in_relocate():
mask = aa.Mask2D.circular(
shape_native=(60, 60),
radius=1.0,
Expand All @@ -371,7 +369,7 @@ def test__relocated_grid_from__positive_origin_included_in_relocate():
over_sampling = aa.OverSampler(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
)
grid = over_sampling.over_sampled_grid
grid = over_sampling.grid_over_sampled
grid[1, :] = [11.1, 1.0]

border_relocator = aa.BorderRelocator(
Expand All @@ -381,3 +379,23 @@ def test__relocated_grid_from__positive_origin_included_in_relocate():
relocated_grid = border_relocator.relocated_grid_from(grid=grid)

assert relocated_grid[1] == pytest.approx([1.97783243, 1.0], 1e-4)


def test__relocated_grid_from__positive_origin_included_in_relocate():
mask = aa.Mask2D.circular(
shape_native=(60, 60),
radius=1.0,
pixel_scales=(0.1, 0.1),
centre=(1.0, 1.0),
)

grid = aa.Grid2D.from_mask(
mask=mask, over_sampling_size=np.array(mask.pixels_in_mask * [2])
)
grid.grid_over_sampled[1, :] = [11.1, 0.1]

border_relocator = aa.BorderRelocator(mask=mask, sub_size=grid.over_sampling_size)

relocated_grid = border_relocator.relocated_grid_from(grid=grid.grid_over_sampled)

assert relocated_grid[1] == pytest.approx([1.97783243, 1.0], 1e-4)
Loading

0 comments on commit eabb866

Please sign in to comment.