From ba29473cb2ce24115d7773ee59d7fc66314c202c Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Feb 2026 19:00:34 +0000 Subject: [PATCH 1/6] Kernel2D.from_gaussian -> Convolver.from_gaussian --- autogalaxy/__init__.py | 2 +- autogalaxy/galaxy/galaxy.py | 2 +- autogalaxy/profiles/light/linear/abstract.py | 2 +- autogalaxy/profiles/light/snr/abstract.py | 2 +- test_autogalaxy/imaging/test_simulate_and_fit_imaging.py | 6 +++--- test_autogalaxy/imaging/test_simulator.py | 2 +- test_autogalaxy/profiles/light/test_snr.py | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/autogalaxy/__init__.py b/autogalaxy/__init__.py index 6f677c9a7..571bf7fbb 100644 --- a/autogalaxy/__init__.py +++ b/autogalaxy/__init__.py @@ -38,6 +38,7 @@ from autoarray.structures.grids.uniform_2d import Grid2D # noqa from autoarray.structures.grids.irregular_2d import Grid2DIrregular # noqa from autoarray.operators.over_sampling.over_sampler import OverSampler # noqa +from autoarray.operators.convolver import Convolver from autoarray.inversion.mesh.interpolator.rectangular import ( InterpolatorRectangular, ) # noqa @@ -48,7 +49,6 @@ from autoarray.structures.vectors.irregular import VectorYX2DIrregular # noqa from autoarray.layout.region import Region1D # noqa from autoarray.layout.region import Region2D # noqa -from autoarray.structures.arrays.kernel_2d import Kernel2D # noqa from autoarray.structures.visibilities import Visibilities # noqa from autoarray.structures.visibilities import VisibilitiesNoiseMap # noqa from autoarray.inversion.mesh.mesh_geometry.rectangular import ( diff --git a/autogalaxy/galaxy/galaxy.py b/autogalaxy/galaxy/galaxy.py index 63ca30d07..23e47f7f1 100644 --- a/autogalaxy/galaxy/galaxy.py +++ b/autogalaxy/galaxy/galaxy.py @@ -455,7 +455,7 @@ def set_snr_of_snr_light_profiles( grid: aa.type.Grid2DLike, exposure_time: float, background_sky_level: float = 0.0, - psf: Optional[aa.Kernel2D] = None, + psf: Optional[aa.Convolver] = None, ): """ Iterate over every galaxy finding all `LightProfileSNR` light profiles and set their `intensity` values to diff --git a/autogalaxy/profiles/light/linear/abstract.py b/autogalaxy/profiles/light/linear/abstract.py index 26eccf333..44eba6abf 100644 --- a/autogalaxy/profiles/light/linear/abstract.py +++ b/autogalaxy/profiles/light/linear/abstract.py @@ -142,7 +142,7 @@ def __init__( self, grid: aa.type.Grid1D2DLike, blurring_grid: aa.type.Grid1D2DLike, - psf: Optional[aa.Kernel2D], + psf: Optional[aa.Convolver], light_profile_list: List[LightProfileLinear], regularization=Optional[aa.reg.Regularization], settings=aa.Settings(), diff --git a/autogalaxy/profiles/light/snr/abstract.py b/autogalaxy/profiles/light/snr/abstract.py index 064db9b81..e3de3f423 100644 --- a/autogalaxy/profiles/light/snr/abstract.py +++ b/autogalaxy/profiles/light/snr/abstract.py @@ -54,7 +54,7 @@ def set_intensity_from( grid: aa.type.Grid2DLike, exposure_time: float, background_sky_level: float = 0.0, - psf: Optional[aa.Kernel2D] = None, + psf: Optional[aa.Convolver] = None, ): """ Set the `intensity` of the light profile as follows: diff --git a/test_autogalaxy/imaging/test_simulate_and_fit_imaging.py b/test_autogalaxy/imaging/test_simulate_and_fit_imaging.py index 0c476b7c1..9083cb5f6 100644 --- a/test_autogalaxy/imaging/test_simulate_and_fit_imaging.py +++ b/test_autogalaxy/imaging/test_simulate_and_fit_imaging.py @@ -15,7 +15,7 @@ def test__perfect_fit__chi_squared_0(): over_sample_size=1, ) - psf = ag.Kernel2D.from_gaussian( + psf = ag.Convolver.from_gaussian( shape_native=(3, 3), pixel_scales=0.2, sigma=0.75, normalize=True ) @@ -86,7 +86,7 @@ def test__perfect_fit__chi_squared_0(): def test__simulate_imaging_data_and_fit__known_likelihood(): grid = ag.Grid2D.uniform(shape_native=(31, 31), pixel_scales=0.2) - psf = ag.Kernel2D.from_gaussian( + psf = ag.Convolver.from_gaussian( shape_native=(3, 3), pixel_scales=0.2, sigma=0.75, normalize=True ) @@ -144,7 +144,7 @@ def test__simulate_imaging_data_and_fit__linear_light_profiles_agree_with_standa over_sample_size=1, ) - psf = ag.Kernel2D.from_gaussian( + psf = ag.Convolver.from_gaussian( shape_native=(3, 3), pixel_scales=0.2, sigma=0.75, normalize=True ) diff --git a/test_autogalaxy/imaging/test_simulator.py b/test_autogalaxy/imaging/test_simulator.py index 1b9aacd9e..c9457f6ca 100644 --- a/test_autogalaxy/imaging/test_simulator.py +++ b/test_autogalaxy/imaging/test_simulator.py @@ -83,7 +83,7 @@ def test__from_fits__all_imaging_data_structures_are_flipped_for_ds9(): def test__simulator__via_galaxies_from(): - psf = ag.Kernel2D.from_gaussian(shape_native=(7, 7), sigma=0.5, pixel_scales=0.05) + psf = ag.Convolver.from_gaussian(shape_native=(7, 7), sigma=0.5, pixel_scales=0.05) grid = ag.Grid2D.uniform(shape_native=(20, 20), pixel_scales=0.05) diff --git a/test_autogalaxy/profiles/light/test_snr.py b/test_autogalaxy/profiles/light/test_snr.py index 515dc45df..b60a3daf6 100644 --- a/test_autogalaxy/profiles/light/test_snr.py +++ b/test_autogalaxy/profiles/light/test_snr.py @@ -21,7 +21,7 @@ def test__signal_to_noise_via_simulator_correct(): assert 8.0 < dataset.signal_to_noise_max < 11.5 - psf = ag.Kernel2D.from_gaussian( + psf = ag.Convolver.from_gaussian( shape_native=(3, 3), sigma=2.0, pixel_scales=0.2, normalize=True ) From 5aceb00bd26a4780200a4a9e28b26dba7ec9ae9d Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Feb 2026 19:02:05 +0000 Subject: [PATCH 2/6] ralce all Kernel2Ds --- test_autogalaxy/imaging/test_simulator.py | 3 ++- test_autogalaxy/operate/test_image.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test_autogalaxy/imaging/test_simulator.py b/test_autogalaxy/imaging/test_simulator.py index c9457f6ca..5916eea99 100644 --- a/test_autogalaxy/imaging/test_simulator.py +++ b/test_autogalaxy/imaging/test_simulator.py @@ -137,7 +137,8 @@ def test__simulator__simulate_imaging_from_galaxy__source_galaxy__compare_to_ima grid = ag.Grid2D.uniform(shape_native=(11, 11), pixel_scales=0.2) - psf = ag.Kernel2D.no_mask(values=[[1.0]], pixel_scales=0.2) + kernel = ag.Array2D.no_mask(values=[[1.0]], pixel_scales=0.2) + psf = ag.Convolver(kernel=kernel) simulator = ag.SimulatorImaging( psf=psf, diff --git a/test_autogalaxy/operate/test_image.py b/test_autogalaxy/operate/test_image.py index d879b7ec9..a8281a2d9 100644 --- a/test_autogalaxy/operate/test_image.py +++ b/test_autogalaxy/operate/test_image.py @@ -95,11 +95,15 @@ def test__x1_galaxies__padded_image__compare_to_galaxy_images_using_padded_grid_ def test__unmasked_blurred_image_2d_from(): - psf = ag.Kernel2D.no_mask( + + + kernel = ag.Array2D.no_mask( values=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0], [0.0, 0.0, 0.0]])), pixel_scales=1.0, ) + psf = ag.Convolver(kernel=kernel) + mask = ag.Mask2D( mask=[[True, True, True], [True, False, True], [True, True, True]], pixel_scales=1.0, @@ -138,7 +142,7 @@ def test__unmasked_blurred_image_2d_from(): image_2d_operated = padded_grid.mask.unmasked_blurred_array_from( padded_array=image_2d_operated, - psf=ag.Kernel2D.no_blur(pixel_scales=1.0), + psf=ag.Convolver.no_blur(pixel_scales=1.0), image_shape=grid.mask.shape, ) @@ -239,10 +243,11 @@ def test__blurred_image_2d_list_from( def test__unmasked_blurred_image_2d_list_from(): - psf = ag.Kernel2D.no_mask( + kernel = ag.Array2D.no_mask( values=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0], [0.0, 0.0, 0.0]])), pixel_scales=1.0, ) + psf = ag.Convolver(kernel=kernel) mask = ag.Mask2D( mask=[[True, True, True], [True, False, True], [True, True, True]], From cc729376845a1175b3743d5c903aeda40bd568ae Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Feb 2026 19:07:13 +0000 Subject: [PATCH 3/6] putting psf.kernel instead of just psf --- autogalaxy/imaging/simulator.py | 4 ++-- autogalaxy/operate/image.py | 4 ++-- test_autogalaxy/operate/test_image.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/autogalaxy/imaging/simulator.py b/autogalaxy/imaging/simulator.py index 73981655b..68f19cf28 100644 --- a/autogalaxy/imaging/simulator.py +++ b/autogalaxy/imaging/simulator.py @@ -48,7 +48,7 @@ def via_galaxies_from( ) image = galaxies.padded_image_2d_from( - grid=grid, psf_shape_2d=self.psf.shape_native + grid=grid, psf_shape_2d=self.psf.kernel.shape_native ) over_sample_size = grid.over_sample_size.resized_from( @@ -58,5 +58,5 @@ def via_galaxies_from( dataset = self.via_image_from(image=image, over_sample_size=over_sample_size) return dataset.trimmed_after_convolution_from( - kernel_shape=self.psf.shape_native + kernel_shape=self.psf.kernel.shape_native ) diff --git a/autogalaxy/operate/image.py b/autogalaxy/operate/image.py index 0973002b9..d8190c51a 100644 --- a/autogalaxy/operate/image.py +++ b/autogalaxy/operate/image.py @@ -138,7 +138,7 @@ def unmasked_blurred_image_2d_from(self, grid, psf): psf The PSF the light object 2D image is convolved with. """ - padded_grid = grid.padded_grid_from(kernel_shape_native=psf.shape_native) + padded_grid = grid.padded_grid_from(kernel_shape_native=psf.kernel.shape_native) padded_image_2d_not_operated = self.image_2d_from( grid=padded_grid, operated_only=False @@ -290,7 +290,7 @@ def unmasked_blurred_image_2d_list_from( psf The PSF the light object 2D image is convolved with. """ - padded_grid = grid.padded_grid_from(kernel_shape_native=psf.shape_native) + padded_grid = grid.padded_grid_from(kernel_shape_native=psf.kernel.shape_native) padded_image_2d_list = self.image_2d_list_from(grid=padded_grid) diff --git a/test_autogalaxy/operate/test_image.py b/test_autogalaxy/operate/test_image.py index a8281a2d9..71eca29e0 100644 --- a/test_autogalaxy/operate/test_image.py +++ b/test_autogalaxy/operate/test_image.py @@ -130,7 +130,7 @@ def test__unmasked_blurred_image_2d_from(): light_not_operated = ag.lp.Gaussian(intensity=1.0) light_operated = ag.lp_operated.Gaussian(intensity=1.0) - padded_grid = grid.padded_grid_from(kernel_shape_native=psf.shape_native) + padded_grid = grid.padded_grid_from(kernel_shape_native=psf.kernel.shape_native) image_2d_not_operated = light_not_operated.image_2d_from(grid=padded_grid) @@ -259,7 +259,7 @@ def test__unmasked_blurred_image_2d_list_from(): lp_0 = ag.lp.Sersic(intensity=1.0) lp_1 = ag.lp.Sersic(intensity=2.0) - padded_grid = grid.padded_grid_from(kernel_shape_native=psf.shape_native) + padded_grid = grid.padded_grid_from(kernel_shape_native=psf.kernel.shape_native) manual_blurred_image_0 = lp_0.image_2d_from(grid=padded_grid) manual_blurred_image_0 = psf.convolved_image_from( From c8783a3d7fa0dfa0c51eeb9c945cdb74e49fd0c6 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Feb 2026 19:18:37 +0000 Subject: [PATCH 4/6] fix edge case wher epsf shape is 1 --- autogalaxy/aggregator/imaging/imaging.py | 5 +++-- autogalaxy/galaxy/to_inversion.py | 2 +- autogalaxy/imaging/model/plotter_interface.py | 2 +- autogalaxy/operate/image.py | 8 ++++---- test_autogalaxy/imaging/test_simulator.py | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/autogalaxy/aggregator/imaging/imaging.py b/autogalaxy/aggregator/imaging/imaging.py index dae4ed718..3abd90288 100644 --- a/autogalaxy/aggregator/imaging/imaging.py +++ b/autogalaxy/aggregator/imaging/imaging.py @@ -59,9 +59,10 @@ def values_from(hdu: int, cls): noise_map = values_from(hdu=2, cls=aa.Array2D) try: - psf = values_from(hdu=3, cls=aa.Kernel2D) + kernel = values_from(hdu=3, cls=aa.Array2D) + psf = aa.Convolver(kernel=kernel) except (TypeError, IndexError): - psf = None + kernel = None dataset = aa.Imaging( data=data, diff --git a/autogalaxy/galaxy/to_inversion.py b/autogalaxy/galaxy/to_inversion.py index 927ed4ef4..2ef24c01b 100644 --- a/autogalaxy/galaxy/to_inversion.py +++ b/autogalaxy/galaxy/to_inversion.py @@ -90,7 +90,7 @@ def _xp(self): return np @property - def psf(self) -> Optional[aa.Kernel2D]: + def psf(self) -> Optional[aa.Convolver]: """ Returns the PSF of the imaging dataset, if the inversion is performed on an imaging dataset. diff --git a/autogalaxy/imaging/model/plotter_interface.py b/autogalaxy/imaging/model/plotter_interface.py index a8655856b..4c38fea61 100644 --- a/autogalaxy/imaging/model/plotter_interface.py +++ b/autogalaxy/imaging/model/plotter_interface.py @@ -132,7 +132,7 @@ def should_plot(name): image_list = [ dataset.data.native_for_fits, dataset.noise_map.native_for_fits, - dataset.psf.native_for_fits, + dataset.psf.kernel.native_for_fits, dataset.grids.lp.over_sample_size.native_for_fits.astype("float"), dataset.grids.pixelization.over_sample_size.native_for_fits.astype( "float" diff --git a/autogalaxy/operate/image.py b/autogalaxy/operate/image.py index d8190c51a..b51bc2085 100644 --- a/autogalaxy/operate/image.py +++ b/autogalaxy/operate/image.py @@ -33,7 +33,7 @@ def _blurred_image_2d_from( self, image_2d: aa.Array2D, blurring_image_2d: aa.Array2D, - psf: aa.Kernel2D, + psf: aa.Convolver, xp=np, ) -> aa.Array2D: @@ -46,7 +46,7 @@ def blurred_image_2d_from( self, grid: aa.Grid2D, blurring_grid: aa.Grid2D, - psf: aa.Kernel2D = None, + psf: aa.Convolver = None, xp=np, ) -> aa.Array2D: """ @@ -216,7 +216,7 @@ def blurred_image_2d_list_from( self, grid: aa.Grid2D, blurring_grid: aa.Grid2D, - psf: aa.Kernel2D = None, + psf: aa.Convolver = None, ) -> List[aa.Array2D]: """ Evaluate the light object's list of 2D images from a input 2D grid of coordinates and convolve each image with @@ -267,7 +267,7 @@ def blurred_image_2d_list_from( return blurred_image_2d_list def unmasked_blurred_image_2d_list_from( - self, grid: aa.Grid2D, psf: aa.Kernel2D + self, grid: aa.Grid2D, psf: aa.Convolver ) -> List[aa.Array2D]: """ Evaluate the light object's list of 2D images from a input 2D grid of coordinates and convolve it with a PSF, diff --git a/test_autogalaxy/imaging/test_simulator.py b/test_autogalaxy/imaging/test_simulator.py index 5916eea99..3b09d0057 100644 --- a/test_autogalaxy/imaging/test_simulator.py +++ b/test_autogalaxy/imaging/test_simulator.py @@ -52,7 +52,7 @@ def test__from_fits__all_imaging_data_structures_are_flipped_for_ds9(): assert (dataset.data.native == np.array([[0.0, 0.0], [1.0, 0.0]])).all() assert (dataset.noise_map.native == np.array([[1.0, 1.0], [2.0, 1.0]])).all() - assert dataset.psf.native == pytest.approx( + assert dataset.psf.kernel.native == pytest.approx( np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]), 1.0e-4 ) From 76e5037ec0373372dbc0ebf5e1011d8be4a556f5 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Feb 2026 20:03:05 +0000 Subject: [PATCH 5/6] fix final unit tests --- autogalaxy/aggregator/imaging/imaging.py | 1 + test_autogalaxy/imaging/test_simulator.py | 4 ++-- test_autogalaxy/operate/test_image.py | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autogalaxy/aggregator/imaging/imaging.py b/autogalaxy/aggregator/imaging/imaging.py index 3abd90288..648058ea5 100644 --- a/autogalaxy/aggregator/imaging/imaging.py +++ b/autogalaxy/aggregator/imaging/imaging.py @@ -63,6 +63,7 @@ def values_from(hdu: int, cls): psf = aa.Convolver(kernel=kernel) except (TypeError, IndexError): kernel = None + psf = None dataset = aa.Imaging( data=data, diff --git a/test_autogalaxy/imaging/test_simulator.py b/test_autogalaxy/imaging/test_simulator.py index 3b09d0057..a0f2f8659 100644 --- a/test_autogalaxy/imaging/test_simulator.py +++ b/test_autogalaxy/imaging/test_simulator.py @@ -112,7 +112,7 @@ def test__simulator__via_galaxies_from(): assert dataset.data.native[10, 10] == pytest.approx( imaging_via_image.data.native[10, 10], 1.0e-4 ) - assert dataset.psf == pytest.approx(imaging_via_image.psf, 1.0e-4) + assert dataset.psf.kernel == pytest.approx(imaging_via_image.psf.kernel, 1.0e-4) assert dataset.noise_map == pytest.approx(imaging_via_image.noise_map, 1.0e-4) @@ -158,5 +158,5 @@ def test__simulator__simulate_imaging_from_galaxy__source_galaxy__compare_to_ima assert dataset.shape_native == (11, 11) assert dataset.data.array == pytest.approx(imaging_via_image.data.array, 1.0e-4) - assert (dataset.psf == imaging_via_image.psf).all() + assert (dataset.psf.kernel == imaging_via_image.psf.kernel).all() assert dataset.noise_map == pytest.approx(imaging_via_image.noise_map, 1.0e-4) diff --git a/test_autogalaxy/operate/test_image.py b/test_autogalaxy/operate/test_image.py index 71eca29e0..f7fa4ef8d 100644 --- a/test_autogalaxy/operate/test_image.py +++ b/test_autogalaxy/operate/test_image.py @@ -96,7 +96,6 @@ def test__x1_galaxies__padded_image__compare_to_galaxy_images_using_padded_grid_ def test__unmasked_blurred_image_2d_from(): - kernel = ag.Array2D.no_mask( values=(np.array([[0.0, 3.0, 0.0], [0.0, 1.0, 2.0], [0.0, 0.0, 0.0]])), pixel_scales=1.0, From 0b99403905bab75b8751739f667d392774dff16d Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 23 Feb 2026 20:27:03 +0000 Subject: [PATCH 6/6] Update autogalaxy/operate/image.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- autogalaxy/operate/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogalaxy/operate/image.py b/autogalaxy/operate/image.py index b51bc2085..bc51fcf31 100644 --- a/autogalaxy/operate/image.py +++ b/autogalaxy/operate/image.py @@ -216,7 +216,7 @@ def blurred_image_2d_list_from( self, grid: aa.Grid2D, blurring_grid: aa.Grid2D, - psf: aa.Convolver = None, + psf: aa.Convolver, ) -> List[aa.Array2D]: """ Evaluate the light object's list of 2D images from a input 2D grid of coordinates and convolve each image with