Skip to content

Commit

Permalink
all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 15, 2024
1 parent eabb866 commit 9ebe6f8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 67 deletions.
1 change: 0 additions & 1 deletion autoarray/config/visualize/plots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dataset: # Settings for plots of all datasets
noise_map: false # Plot the individual noise-map of every dataset?
signal_to_noise_map: false # Plot the individual signal-to-noise-map of every dataset?
over_sampling: false # Plot the over-sampling sub-size, used to evaluate light profiles, of every dataset?
over_sampling_non_uniform: false # Plot the over-sampling sub-size, used to evaluate non uniform grids, of every dataset?
over_sampling_pixelization: false # Plot the over-sampling sub-size, used to evaluate pixelizations, of every dataset?
imaging: # Settings for plots of imaging datasets (e.g. ImagingPlotter)
psf: false
Expand Down
4 changes: 0 additions & 4 deletions autoarray/dataset/over_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def __init__(
the image data. This grid is used specifically for pixelizations computed via the `inversion` module, which
can benefit from using different oversampling schemes than the normal grid.
- `grid_non_uniform`: A grid of (y,x) coordinates which are mapped from the image pixel centres but have had
their values deflected to become non-uniform. This is used to compute over sampled light profiles of lensed
sources in PyAutoLens.
Different calculations typically benefit from different over sampling, which this class enables
the customization of.
Expand Down
13 changes: 0 additions & 13 deletions autoarray/dataset/plot/imaging_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def figures_2d(
psf: bool = False,
signal_to_noise_map: bool = False,
over_sampling: bool = False,
over_sampling_non_uniform: bool = False,
over_sampling_pixelization: bool = False,
title_str: Optional[str] = None,
):
Expand Down Expand Up @@ -136,17 +135,6 @@ def figures_2d(
),
)

if over_sampling_non_uniform:
self.mat_plot_2d.plot_array(
array=self.dataset.grids.non_uniform.over_sampling_size,
visuals_2d=self.get_visuals_2d(),
auto_labels=AutoLabels(
title=title_str or f"Over Sampling (Non Uniform)",
filename="over_sampling_non_uniform",
cb_unit="",
),
)

if over_sampling_pixelization:
self.mat_plot_2d.plot_array(
array=self.dataset.grids.pixelization.over_sampling_size,
Expand Down Expand Up @@ -231,7 +219,6 @@ def subplot_dataset(self):
self.figures_2d(signal_to_noise_map=True)

self.figures_2d(over_sampling=True)
self.figures_2d(over_sampling_non_uniform=True)
self.figures_2d(over_sampling_pixelization=True)

self.mat_plot_2d.output.subplot_to_figure(auto_filename="subplot_dataset")
Expand Down
15 changes: 14 additions & 1 deletion autoarray/structures/decorators/to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,31 @@ def via_grid_2d(self, result) -> Union[Grid2D, List[Grid2D]]:
The input result (e.g. of a decorated function) that is converted to a Grid2D or list of Grid2D objects.
"""
if not isinstance(result, list):
try:
grid_over_sampled = result.grid_over_sampled
except AttributeError:
grid_over_sampled = None

return Grid2D(
values=result,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
grid_over_sampled=grid_over_sampled,
)

try:
grid_over_sampled_list = [res.grid_over_sampled for res in result]
except AttributeError:
grid_over_sampled_list = [None] * len(result)

return [
Grid2D(
values=res,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
grid_over_sampled=grid_over_sampled,
)
for res in result
for res, grid_over_sampled in zip(result, grid_over_sampled_list)
]

def via_grid_2d_irr(self, result) -> Union[Grid2DIrregular, List[Grid2DIrregular]]:
Expand Down
25 changes: 17 additions & 8 deletions autoarray/structures/grids/uniform_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from autoarray.geometry import geometry_util
from autoarray.operators.over_sampling import over_sample_util

from autoarray import exc
from autoarray import type as ty


Expand All @@ -26,7 +27,6 @@ def __init__(
mask: Mask2D,
store_native: bool = False,
over_sampling_size: Union[int, Array2D] = 4,
over_sampling_non_uniform: Union[int, Array2D] = 4,
grid_over_sampled: Optional[Grid2D] = None,
*args,
**kwargs,
Expand Down Expand Up @@ -166,10 +166,6 @@ def __init__(

grid_2d_util.check_grid_2d(grid_2d=values)

# self.over_sampling_non_uniform = (
# over_sampling_non_uniform or OverSampling(sub_size=4)
# )

if isinstance(over_sampling_size, int):
over_sampling_size = np.full(
fill_value=over_sampling_size, shape=mask.shape_slim
Expand Down Expand Up @@ -1064,6 +1060,8 @@ def padded_grid_from(self, kernel_shape_native: Tuple[int, int]) -> "Grid2D":
kernel_shape_native
The 2D shape of the kernel which convolves signal from masked pixels to unmasked pixels.
"""
if kernel_shape_native[0] % 2 == 0 or kernel_shape_native[1] % 2 == 0:
raise exc.KernelException("Kernel2D Kernel2D must be odd")

shape = self.mask.shape

Expand All @@ -1077,11 +1075,22 @@ def padded_grid_from(self, kernel_shape_native: Tuple[int, int]) -> "Grid2D":
pixel_scales=self.mask.pixel_scales,
)

return Grid2D.from_mask(
mask=padded_mask,
over_sampling_size=4,
pad_width = (
(padded_shape[0] - shape[0]) // 2,
(padded_shape[1] - shape[1]) // 2,
)

over_sampling_size = np.pad(
self.over_sampling_size.native,
pad_width,
mode="constant",
constant_values=1,
)

over_sampling_size[over_sampling_size == 0] = 1

return Grid2D.from_mask(mask=padded_mask, over_sampling_size=over_sampling_size)

@cached_property
def is_uniform(self) -> bool:
"""
Expand Down
2 changes: 0 additions & 2 deletions test_autoarray/dataset/plot/test_imaging_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test__individual_attributes_are_output(
psf=True,
signal_to_noise_map=True,
over_sampling=True,
over_sampling_non_uniform=True,
over_sampling_pixelization=True,
)

Expand All @@ -44,7 +43,6 @@ def test__individual_attributes_are_output(
assert path.join(plot_path, "psf.png") in plot_patch.paths
assert path.join(plot_path, "signal_to_noise_map.png") in plot_patch.paths
assert path.join(plot_path, "over_sampling.png") in plot_patch.paths
assert path.join(plot_path, "over_sampling_non_uniform.png") in plot_patch.paths
assert path.join(plot_path, "over_sampling_pixelization.png") in plot_patch.paths

plot_patch.paths = []
Expand Down
29 changes: 2 additions & 27 deletions test_autoarray/inversion/pixelization/test_border_relocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,29 +358,6 @@ def test__relocated_grid_from__outside_border_includes_relocations():
assert relocated_grid[1] == pytest.approx([0.97783243, 0.00968151], 1e-4)


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

over_sampling = aa.OverSampler(
mask=mask, sub_size=np.array(mask.pixels_in_mask * [2])
)
grid = over_sampling.grid_over_sampled
grid[1, :] = [11.1, 1.0]

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

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),
Expand All @@ -389,10 +366,8 @@ def test__relocated_grid_from__positive_origin_included_in_relocate():
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]
grid = aa.Grid2D.from_mask(mask=mask, over_sampling_size=2)
grid.grid_over_sampled[1, :] = [11.1, 1.0]

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

Expand Down
11 changes: 0 additions & 11 deletions test_autoarray/structures/grids/test_uniform_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,6 @@ def test__padded_grid_from():
assert padded_grid.shape == (42, 2)
assert (padded_grid == padded_grid_util).all()

grid_2d = aa.Grid2D.uniform(shape_native=(5, 5), pixel_scales=8.0)

padded_grid = grid_2d.padded_grid_from(kernel_shape_native=(2, 5))

padded_grid_util = aa.util.grid_2d.grid_2d_slim_via_mask_from(
mask_2d=np.full((6, 9), False), pixel_scales=(8.0, 8.0)
)

assert padded_grid.shape == (54, 2)
assert (padded_grid == padded_grid_util).all()


def test__squared_distances_to_coordinate_from():
mask = aa.Mask2D(
Expand Down

0 comments on commit 9ebe6f8

Please sign in to comment.