Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors Point Spread Function (PSF) convolution handling in the autoarray package by replacing the Kernel2D class with a new Convolver class that separates kernel data from convolution logic. The refactoring aims to simplify PSF handling by introducing a ConvolverState class to manage FFT-related state and removing legacy padding parameters.
Changes:
- Replaced
Kernel2Dwith a newConvolverclass that wraps anArray2Dkernel and manages convolution operations - Introduced
ConvolverStateto encapsulate FFT-related precomputed values (shapes, masks, FFT kernels) - Removed
disable_fft_padparameter fromImagingdataset and related methods throughout the codebase
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| autoarray/operators/convolver.py | Complete refactoring from Kernel2D to Convolver and ConvolverState classes |
| autoarray/dataset/imaging/dataset.py | Updated to use Convolver, removed disable_fft_pad logic, added psf_setup_state parameter |
| autoarray/dataset/imaging/simulator.py | Changed PSF type from Kernel2D to Convolver |
| autoarray/dataset/grids.py | Updated to use Convolver and access blurring mask through state |
| autoarray/dataset/preprocess.py | Moved kernel rescaling logic from Kernel2D method to standalone function |
| test_autoarray/structures/arrays/test_kernel_2d.py | File deleted (530 lines removed) |
| test_autoarray/operators/test_convolver.py | New test file with migrated tests (315 lines added) |
| test_autoarray/inversion/inversion/test_abstract.py | Updated tests to create Convolver from Array2D kernel |
| test_autoarray/dataset/imaging/test_dataset.py | Updated assertions to access psf.kernel instead of psf directly |
| autoarray/init.py | Changed import from Kernel2D to Convolver |
Comments suppressed due to low confidence (8)
autoarray/operators/convolver.py:111
- The docstring states "The
Convolveris a subclass ofArray2D" but Convolver is not actually a subclass of Array2D - it simply contains a kernel which is an Array2D. This misleading documentation should be corrected to accurately describe that Convolver wraps or contains an Array2D kernel.
autoarray/operators/convolver.py:167 - The error message contains a redundant duplicate "Convolver Convolver" instead of just "Convolver kernel". This should be corrected to "Convolver kernel must be odd" for clarity.
autoarray/operators/convolver.py:44 - Typo in documentation: "thi sfunction" should be "this function".
autoarray/structures/grids/uniform_2d.py:1089 - The error message contains a redundant duplicate "Convolver Convolver" instead of just "Convolver kernel". This should be corrected to "Convolver kernel must be odd" for clarity.
raise exc.KernelException("Convolver Convolver must be odd")
autoarray/operators/convolver.py:160
- When
kernelis None andnormalizeis True, this line will raise an AttributeError trying to accessself.kernel._array. Additionally, whenkernelis None anduse_fftis False, line 164 will raise an AttributeError trying to accessself.kernel.shape_native. The Convolver should handle None kernel gracefully or the calling code should ensure kernel is never None.
autoarray/operators/convolver.py:135 - The docstring mentions a "mask" parameter that no longer exists in the Convolver constructor signature. The documentation should be updated to remove references to the removed "mask" parameter and the removed "header" parameter.
autoarray/operators/convolver.py:143 - The docstring mentions "mask" and "header" parameters (lines 131-135) that no longer exist in the Convolver constructor signature. Additionally, the "*args, **kwargs" reference on line 142 suggests these are passed to an Array2D constructor, but Convolver is no longer a subclass of Array2D. The documentation should be updated to remove these outdated parameter descriptions.
autoarray/operators/convolver.py:167 - The condition
if not use_fft:will evaluate to True whenuse_fftis None (the default value), causing the odd-dimension check to be enforced even when FFT convolution is intended. This check should only apply when real-space convolution is explicitly requested. The condition should beif use_fft is False:to distinguish between False (explicitly real-space) and None (use config default, which may be FFT).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
autoarray/dataset/imaging/dataset.py
Outdated
| psf = Convolver( | ||
| kernel=kernel, | ||
| ) |
There was a problem hiding this comment.
When psf_path is None, kernel is set to None and passed to the Convolver constructor. However, Convolver.__init__ expects a non-None kernel parameter (it immediately accesses kernel._array if normalize is True). This will cause an AttributeError when creating an Imaging dataset without a PSF. A None check should be added, or the Convolver creation should be conditional on whether kernel is None.
| @@ -95,7 +95,7 @@ def __init__( | |||
| psf = psf.normalized | |||
There was a problem hiding this comment.
The Convolver class does not have a normalized property or method, but line 95 attempts to access it. This will cause an AttributeError. The normalization should be handled differently, perhaps by passing normalize=True to the Convolver constructor or by calling a normalization method if one exists.
| [[0.0, 1.0, 0.0], [1.0, 1.0, 1.0], [0.0, 1.0, 0.0]], pixel_scales=1.0 | ||
| ) | ||
|
|
||
| psf = aa.Convolver(kernel=kernel, pixel_scales=1.0) |
There was a problem hiding this comment.
The Convolver constructor does not accept a pixel_scales parameter, but line 195 attempts to pass it. This will cause a TypeError. The pixel_scales should be removed from this call, as the kernel already contains pixel scale information.
| psf = aa.Convolver(kernel=kernel, pixel_scales=1.0) | |
| psf = aa.Convolver(kernel=kernel) |
| except exc.MaskException: | ||
| self._blurring = None | ||
| self._blurring = Grid2D.from_mask( | ||
| mask=self.psf._state.blurring_mask, |
There was a problem hiding this comment.
Accessing self.psf._state.blurring_mask directly assumes that _state has already been initialized. However, _state is None by default in the Convolver and is only set up when the Imaging constructor is called with psf_setup_state=True (which only happens in apply_mask). When Imaging is created in other contexts (e.g., from_fits, simulator), _state will be None, causing an AttributeError. The code should call self.psf.state_from(self.mask) instead to ensure the state is created if it doesn't exist.
| mask=self.psf._state.blurring_mask, | |
| mask=self.psf.state_from(self.mask).blurring_mask, |
| fft_shape=fft_shape, | ||
| ) | ||
| psf = Convolver( | ||
| kernel=psf.kernel, state=state, normalize=use_normalized_psf |
There was a problem hiding this comment.
The kernel is normalized twice when psf_setup_state=True and use_normalized_psf=True. First at line 119-121 by directly modifying psf.kernel._array, then again at line 128 by passing normalize=use_normalized_psf to the Convolver constructor. This double normalization will produce incorrect kernel values. Either remove the normalization at lines 119-121 and rely on the Convolver constructor's normalize parameter, or don't pass normalize=use_normalized_psf to the constructor.
| kernel=psf.kernel, state=state, normalize=use_normalized_psf | |
| kernel=psf.kernel, state=state, normalize=False |
This pull request refactors how Point Spread Function (PSF) convolution is handled in the
autoarraypackage, replacing the previousKernel2Dimplementation with a newConvolverclass. The changes simplify and modernize the PSF handling, remove legacy padding logic, and update interfaces throughout the dataset and simulator modules.PSF and convolution refactor:
Kernel2DwithConvolverthroughout the codebase, including imports, class attributes, and function parameters inautoarray/dataset/imaging/dataset.py,autoarray/dataset/imaging/simulator.py, andautoarray/dataset/grids.py. [1] [2] [3] [4]ConvolverStateand explicitly normalize the kernel array, improving clarity and control over PSF setup.Convolver's kernel and state directly, including changes to FITS input/output and simulator defaults. [1] [2] [3]Removal of legacy padding logic:
disable_fft_pad) in dataset initialization and related methods, simplifying the interface and removing unnecessary complexity. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Interface and method updates:
disable_fft_padand the transition toConvolver, ensuring consistency and clarity for users. [1] [2]Convolver's kernel and state in sparse operator and blurring grid calculations. [1] [2] [3]These changes modernize the PSF handling, streamline the codebase, and make the convolution logic more robust and maintainable.