Skip to content

Commit

Permalink
simplify API
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 16, 2024
1 parent 305f50e commit 4f7251e
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions autoarray/dataset/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def lp(self) -> Union[Grid1D, Grid2D]:
"""
return Grid2D.from_mask(
mask=self.mask,
over_sampling_size=self.over_sampling.lp,
over_sample_size=self.over_sampling.lp,
)

@cached_property
Expand All @@ -87,7 +87,7 @@ def pixelization(self) -> Grid2D:
"""
return Grid2D.from_mask(
mask=self.mask,
over_sampling_size=self.over_sampling.pixelization,
over_sample_size=self.over_sampling.pixelization,
)

@cached_property
Expand Down Expand Up @@ -117,7 +117,7 @@ def blurring(self) -> Optional[Grid2D]:
@cached_property
def border_relocator(self) -> BorderRelocator:
return BorderRelocator(
mask=self.mask, sub_size=self.pixelization.over_sampling_size
mask=self.mask, sub_size=self.pixelization.over_sample_size
)


Expand Down
2 changes: 1 addition & 1 deletion autoarray/dataset/over_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
This class controls how over sampling is performed for 3 different types of grids:
`grid`: A grids of (y,x) coordinates which aligns with the centre of every image pixel of the image data.
- `grid`: A grids of (y,x) coordinates which aligns with the centre of every image pixel of the image data.
- `grids.pixelization`: A grid of (y,x) coordinates which again align with the centre of every image pixel of
the image data. This grid is used specifically for pixelizations computed via the `inversion` module, which
Expand Down
4 changes: 2 additions & 2 deletions autoarray/dataset/plot/imaging_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def figures_2d(

if over_sampling:
self.mat_plot_2d.plot_array(
array=self.dataset.grids.lp.over_sampling_size,
array=self.dataset.grids.lp.over_sample_size,
visuals_2d=self.get_visuals_2d(),
auto_labels=AutoLabels(
title=title_str or f"Over Sampling (Uniform)",
Expand All @@ -137,7 +137,7 @@ def figures_2d(

if over_sampling_pixelization:
self.mat_plot_2d.plot_array(
array=self.dataset.grids.pixelization.over_sampling_size,
array=self.dataset.grids.pixelization.over_sample_size,
visuals_2d=self.get_visuals_2d(),
auto_labels=AutoLabels(
title=title_str or f"Over Sampling (Pixelization)",
Expand Down
4 changes: 2 additions & 2 deletions autoarray/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def make_grid_2d_7x7():


def make_grid_2d_sub_1_7x7():
return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sampling_size=1)
return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sample_size=1)


def make_grid_2d_sub_2_7x7():
return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sampling_size=2)
return aa.Grid2D.from_mask(mask=make_mask_2d_7x7(), over_sample_size=2)


def make_grid_2d_7x7_simple():
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_size)
sub_size = np.max(self.grid.over_sample_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/border_relocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def relocated_grid_from(self, grid: Grid2D) -> Grid2D:
return Grid2D(
values=values,
mask=grid.mask,
over_sampling_size=self.sub_size,
over_sample_size=self.sub_size,
over_sampled=over_sampled,
)

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

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

def via_grid_2d(self, result):
raise NotImplementedError
Expand Down
4 changes: 2 additions & 2 deletions autoarray/structures/decorators/to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def via_grid_2d(self, result) -> Union[Grid2D, List[Grid2D]]:
return Grid2D(
values=result,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
over_sampled=over_sampled,
)

Expand All @@ -43,7 +43,7 @@ def via_grid_2d(self, result) -> Union[Grid2D, List[Grid2D]]:
Grid2D(
values=res,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
over_sampled=over_sampled,
)
for res, over_sampled in zip(result, grid_over_sampled_list)
Expand Down
72 changes: 36 additions & 36 deletions autoarray/structures/grids/uniform_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
values: Union[np.ndarray, List],
mask: Mask2D,
store_native: bool = False,
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
over_sampled: Optional[Grid2D] = None,
*args,
**kwargs,
Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__(
store_native
If True, the ndarray is stored in its native format [total_y_pixels, total_x_pixels, 2]. This avoids
mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.
over_sampling_size
over_sample_size
The over sampling scheme, which divides the grid into a sub grid of smaller pixels when computing values
(e.g. images) from the grid so as to approximate the 2D line integral of the amount of light that falls
into each pixel.
Expand All @@ -166,16 +166,16 @@ def __init__(

grid_2d_util.check_grid_2d(grid_2d=values)

if isinstance(over_sampling_size, int):
over_sampling_size = np.full(
fill_value=over_sampling_size, shape=mask.shape_slim
if isinstance(over_sample_size, int):
over_sample_size = np.full(
fill_value=over_sample_size, shape=mask.shape_slim
).astype("int")

over_sampling_size = Array2D(values=over_sampling_size, mask=mask)
over_sample_size = Array2D(values=over_sample_size, mask=mask)

from autoarray.operators.over_sampling.over_sampler import OverSampler

self.over_sampler = OverSampler(sub_size=over_sampling_size, mask=mask)
self.over_sampler = OverSampler(sub_size=over_sample_size, mask=mask)

if over_sampled is None:
self.over_sampled = (
Expand All @@ -197,7 +197,7 @@ def no_mask(
pixel_scales: ty.PixelScales,
shape_native: Tuple[int, int] = None,
origin: Tuple[float, float] = (0.0, 0.0),
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) by inputting the grid coordinates in 1D or 2D, automatically
Expand Down Expand Up @@ -244,7 +244,7 @@ def no_mask(
return Grid2D(
values=values,
mask=mask,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
Expand All @@ -255,7 +255,7 @@ def from_yx_1d(
shape_native: Tuple[int, int],
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) by inputting the grid coordinates as 1D y and x values.
Expand Down Expand Up @@ -319,7 +319,7 @@ def from_yx_1d(
shape_native=shape_native,
pixel_scales=pixel_scales,
origin=origin,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
Expand All @@ -329,7 +329,7 @@ def from_yx_2d(
x: Union[np.ndarray, List],
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) by inputting the grid coordinates as 2D y and x values.
Expand Down Expand Up @@ -374,15 +374,15 @@ def from_yx_2d(
values=np.stack((y, x), axis=-1),
pixel_scales=pixel_scales,
origin=origin,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
def from_extent(
cls,
extent: Tuple[float, float, float, float],
shape_native: Tuple[int, int],
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) by inputting the extent of the (y,x) grid coordinates as an input
Expand Down Expand Up @@ -431,7 +431,7 @@ def from_extent(
return Grid2D.no_mask(
values=grid_2d,
pixel_scales=pixel_scales,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
Expand All @@ -440,7 +440,7 @@ def uniform(
shape_native: Tuple[int, int],
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a `Grid2D` (see *Grid2D.__new__*) as a uniform grid of (y,x) values given an input `shape_native` and
Expand Down Expand Up @@ -469,7 +469,7 @@ def uniform(
shape_native=shape_native,
pixel_scales=pixel_scales,
origin=origin,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
Expand All @@ -478,7 +478,7 @@ def bounding_box(
bounding_box: np.ndarray,
shape_native: Tuple[int, int],
buffer_around_corners: bool = False,
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) from an input bounding box with coordinates [y_min, y_max, x_min, x_max],
Expand Down Expand Up @@ -521,14 +521,14 @@ def bounding_box(
shape_native=shape_native,
pixel_scales=pixel_scales,
origin=origin,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
def from_mask(
cls,
mask: Mask2D,
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) from a mask, where only unmasked pixels are included in the grid (if the
Expand All @@ -551,7 +551,7 @@ def from_mask(
return Grid2D(
values=grid_1d,
mask=mask,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
Expand All @@ -560,7 +560,7 @@ def from_fits(
file_path: Union[Path, str],
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Create a Grid2D (see *Grid2D.__new__*) from a mask, where only unmasked pixels are included in the grid (if the
Expand All @@ -580,15 +580,15 @@ def from_fits(
values=grid_2d,
pixel_scales=pixel_scales,
origin=origin,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

@classmethod
def blurring_grid_from(
cls,
mask: Mask2D,
kernel_shape_native: Tuple[int, int],
over_sampling_size: Union[int, Array2D] = 4,
over_sample_size: Union[int, Array2D] = 4,
) -> "Grid2D":
"""
Setup a blurring-grid from a mask, where a blurring grid consists of all pixels that are masked (and
Expand Down Expand Up @@ -676,7 +676,7 @@ def blurring_grid_from(

return cls.from_mask(
mask=blurring_mask,
over_sampling_size=over_sampling_size,
over_sample_size=over_sample_size,
)

def subtracted_from(self, offset: Tuple[(float, float), np.ndarray]) -> "Grid2D":
Expand All @@ -692,11 +692,11 @@ def subtracted_from(self, offset: Tuple[(float, float), np.ndarray]) -> "Grid2D"
return Grid2D(
values=self - np.array(offset),
mask=mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
)

@property
def over_sampling_size(self):
def over_sample_size(self):
return self.over_sampler.sub_size

@property
Expand All @@ -711,7 +711,7 @@ def slim(self) -> "Grid2D":
return Grid2D(
values=self,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
)

@property
Expand All @@ -728,7 +728,7 @@ def native(self) -> "Grid2D":
return Grid2D(
values=self,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
store_native=True,
)

Expand Down Expand Up @@ -766,7 +766,7 @@ def grid_2d_via_deflection_grid_from(self, deflection_grid: "Grid2D") -> "Grid2D
return Grid2D(
values=self - deflection_grid,
mask=self.mask,
over_sampling_size=self.over_sampling_size,
over_sample_size=self.over_sample_size,
)

def blurring_grid_via_kernel_shape_from(
Expand All @@ -786,7 +786,7 @@ def blurring_grid_via_kernel_shape_from(
return Grid2D.blurring_grid_from(
mask=self.mask,
kernel_shape_native=kernel_shape_native,
over_sampling_size=1,
over_sample_size=1,
)

def grid_with_coordinates_within_distance_removed_from(
Expand Down Expand Up @@ -823,7 +823,7 @@ def grid_with_coordinates_within_distance_removed_from(

return Grid2D.from_mask(
mask=mask,
over_sampling_size=self.over_sampling_size.apply_mask(mask=mask),
over_sample_size=self.over_sample_size.apply_mask(mask=mask),
)

def squared_distances_to_coordinate_from(
Expand Down Expand Up @@ -1080,16 +1080,16 @@ def padded_grid_from(self, kernel_shape_native: Tuple[int, int]) -> "Grid2D":
(padded_shape[1] - shape[1]) // 2,
)

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

over_sampling_size[over_sampling_size == 0] = 1
over_sample_size[over_sample_size == 0] = 1

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

@cached_property
def is_uniform(self) -> bool:
Expand Down
Loading

0 comments on commit 4f7251e

Please sign in to comment.