Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions autoarray/operators/convolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,10 @@ def from_gaussian(
Parameters
----------
shape_native
The 2D shape of the mask the array is paired with.
The 2D shape of the mask the array is paired with. The kernel is always built at this
size, including when ``PYAUTO_SMALL_DATASETS=1`` is set — a kernel's shape is intrinsic
to the convolution operator, not a dataset size, so the fast-mode dataset cap does not
apply to it.
pixel_scales
The (y,x) arcsecond-to-pixel units conversion factor of every pixel. If this is input as a `float`,
it is converted to a (float, float).
Expand All @@ -718,7 +721,13 @@ def from_gaussian(
``pixel_scales`` input should be the fine resolution (image pixel scale divided by this size).
"""

grid = Grid2D.uniform(shape_native=shape_native, pixel_scales=pixel_scales)
grid = Grid2D.uniform(
shape_native=shape_native,
pixel_scales=pixel_scales,
# The kernel is wrapped in an `Array2D` at `shape_native` below, so letting the
# `PYAUTO_SMALL_DATASETS` cap shrink this grid would leave the two inconsistent.
respect_small_datasets=False,
)
grid_shifted = np.subtract(grid.array, centre)
grid_radius = np.sqrt(np.sum(grid_shifted**2.0, 1))
theta_coordinate_to_profile = np.arctan2(
Expand Down
24 changes: 24 additions & 0 deletions test_autoarray/operators/test_convolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ def test__from_gaussian__normalized__kernel_values_match_expected():
)


def test__from_gaussian__small_datasets__kernel_keeps_full_requested_shape(monkeypatch):
"""
The `PYAUTO_SMALL_DATASETS` fast-mode cap shrinks datasets (and the grids paired with
them) to 16x16, but a convolution kernel's shape is intrinsic to the operator. If the
cap reached the grid the Gaussian is evaluated on, its 256 values would be wrapped in an
`Array2D` at the uncapped `shape_native` of 961, raising an `ArrayException`.
"""
monkeypatch.setenv("PYAUTO_SMALL_DATASETS", "1")

convolver = aa.Convolver.from_gaussian(
shape_native=(31, 31),
pixel_scales=0.1,
sigma=0.1,
)

assert convolver.kernel.shape_native == (31, 31)

image = aa.Array2D.ones(shape_native=(16, 16), pixel_scales=0.1)

blurred_image = convolver.convolved_image_from(image=image, blurring_image=None)

assert blurred_image.shape_native == (16, 16)


def test__normalize__ones_kernel__each_element_equals_one_ninth():

kernel_data = aa.Array2D.ones(shape_native=(3, 3), pixel_scales=1.0)
Expand Down
Loading