diff --git a/autoarray/operators/convolver.py b/autoarray/operators/convolver.py index ef793f54..702d1f16 100644 --- a/autoarray/operators/convolver.py +++ b/autoarray/operators/convolver.py @@ -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). @@ -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( diff --git a/test_autoarray/operators/test_convolver.py b/test_autoarray/operators/test_convolver.py index 70f26466..43adfab6 100644 --- a/test_autoarray/operators/test_convolver.py +++ b/test_autoarray/operators/test_convolver.py @@ -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)