Skip to content

Commit c9268b2

Browse files
authored
Merge pull request #166 from Jammy2211/feature/remove_convolver
Feature/remove convolver
2 parents d0c324b + ef5ba9e commit c9268b2

35 files changed

Lines changed: 423 additions & 2062 deletions

File tree

autoarray/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
from .mask.derive.grid_2d import DeriveGrid2D
5555
from .mask.mask_1d import Mask1D
5656
from .mask.mask_2d import Mask2D
57-
from .operators.convolver import Convolver
58-
from .operators.convolver import Convolver
5957
from .operators.transformer import TransformerDFT
6058
from .operators.transformer import TransformerNUFFT
6159
from .operators.over_sampling.decorator import over_sample

autoarray/dataset/imaging/dataset.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from autoarray.dataset.grids import GridsDataset
1010
from autoarray.dataset.imaging.w_tilde import WTildeImaging
1111
from autoarray.structures.arrays.uniform_2d import Array2D
12-
from autoarray.operators.convolver import Convolver
1312
from autoarray.structures.arrays.kernel_2d import Kernel2D
1413
from autoarray.mask.mask_2d import Mask2D
1514
from autoarray import type as ty
@@ -30,7 +29,7 @@ def __init__(
3029
noise_covariance_matrix: Optional[np.ndarray] = None,
3130
over_sample_size_lp: Union[int, Array2D] = 4,
3231
over_sample_size_pixelization: Union[int, Array2D] = 4,
33-
pad_for_convolver: bool = False,
32+
pad_for_psf: bool = False,
3433
use_normalized_psf: Optional[bool] = True,
3534
check_noise_map: bool = True,
3635
):
@@ -77,7 +76,7 @@ def __init__(
7776
over_sample_size_pixelization
7877
How over sampling is performed for the grid which is associated with a pixelization, which is therefore
7978
passed into the calculations performed in the `inversion` module.
80-
pad_for_convolver
79+
pad_for_psf
8180
The PSF convolution may extend beyond the edges of the image mask, which can lead to edge effects in the
8281
convolved image. If `True`, the image and noise-map are padded to ensure the PSF convolution does not
8382
extend beyond the edge of the image.
@@ -90,9 +89,9 @@ def __init__(
9089

9190
self.unmasked = None
9291

93-
self.pad_for_convolver = pad_for_convolver
92+
self.pad_for_psf = pad_for_psf
9493

95-
if pad_for_convolver and psf is not None:
94+
if pad_for_psf and psf is not None:
9695
try:
9796
data.mask.derive_mask.blurring_from(
9897
kernel_shape_native=psf.shape_native
@@ -167,6 +166,9 @@ def __init__(
167166

168167
self.psf = psf
169168

169+
if psf.mask.shape[0] % 2 == 0 or psf.mask.shape[1] % 2 == 0:
170+
raise exc.KernelException("Kernel2D Kernel2D must be odd")
171+
170172
@cached_property
171173
def grids(self):
172174
return GridsDataset(
@@ -176,25 +178,6 @@ def grids(self):
176178
psf=self.psf,
177179
)
178180

179-
@cached_property
180-
def convolver(self):
181-
"""
182-
Returns a `Convolver` from a mask and 2D PSF kernel.
183-
184-
The `Convolver` stores in memory the array indexing between the mask and PSF, enabling efficient 2D PSF
185-
convolution of images and matrices used for linear algebra calculations (see `operators.convolver`).
186-
187-
This uses lazy allocation such that the calculation is only performed when the convolver is used, ensuring
188-
efficient set up of the `Imaging` class.
189-
190-
Returns
191-
-------
192-
Convolver
193-
The convolver given the masked imaging data's mask and PSF.
194-
"""
195-
196-
return Convolver(mask=self.mask, kernel=Kernel2D(values=self.psf._array, mask=self.psf.mask, header=self.psf.header))
197-
198181
@cached_property
199182
def w_tilde(self):
200183
"""
@@ -370,7 +353,7 @@ def apply_mask(self, mask: Mask2D) -> "Imaging":
370353
noise_covariance_matrix=noise_covariance_matrix,
371354
over_sample_size_lp=over_sample_size_lp,
372355
over_sample_size_pixelization=over_sample_size_pixelization,
373-
pad_for_convolver=True,
356+
pad_for_psf=True,
374357
)
375358

376359
dataset.unmasked = unmasked_dataset
@@ -463,7 +446,7 @@ def apply_noise_scaling(
463446
noise_covariance_matrix=self.noise_covariance_matrix,
464447
over_sample_size_lp=self.over_sample_size_lp,
465448
over_sample_size_pixelization=self.over_sample_size_pixelization,
466-
pad_for_convolver=False,
449+
pad_for_psf=False,
467450
check_noise_map=False,
468451
)
469452

@@ -511,7 +494,7 @@ def apply_over_sampling(
511494
over_sample_size_lp=over_sample_size_lp or self.over_sample_size_lp,
512495
over_sample_size_pixelization=over_sample_size_pixelization
513496
or self.over_sample_size_pixelization,
514-
pad_for_convolver=False,
497+
pad_for_psf=False,
515498
check_noise_map=False,
516499
)
517500

autoarray/dataset/interferometer/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,5 @@ def output_to_fits(
276276
)
277277

278278
@property
279-
def convolver(self):
279+
def psf(self):
280280
return None

autoarray/dataset/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def background_noise_map_via_edges_from(image, no_edges):
328328
def psf_with_odd_dimensions_from(psf):
329329
"""
330330
If the PSF kernel has one or two even-sized dimensions, return a PSF object where the kernel has odd-sized
331-
dimensions (odd-sized dimensions are required by a *Convolver*).
331+
dimensions (odd-sized dimensions are required for 2D convolution).
332332
333333
Kernels are rescaled using the scikit-image routine rescale, which performs rescaling via an interpolation
334334
routine. This may lead to loss of accuracy in the PSF kernel and it is advised that users, where possible,

autoarray/fixtures.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ def make_blurring_grid_2d_7x7():
110110
return aa.Grid2D.from_mask(mask=make_blurring_mask_2d_7x7())
111111

112112

113-
# CONVOLVERS #
114-
115-
116-
def make_convolver_7x7():
117-
return aa.Convolver(mask=make_mask_2d_7x7(), kernel=make_psf_3x3())
118-
119-
120113
def make_image_7x7():
121114
return aa.Array2D.ones(shape_native=(7, 7), pixel_scales=(1.0, 1.0))
122115

autoarray/geometry/geometry_util.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]
181181

182182
return pixel_scales
183183

184+
184185
@numba_util.jit()
185186
def central_pixel_coordinates_2d_numba_from(
186187
shape_native: Tuple[int, int],
@@ -205,6 +206,7 @@ def central_pixel_coordinates_2d_numba_from(
205206
"""
206207
return (float(shape_native[0] - 1) / 2, float(shape_native[1] - 1) / 2)
207208

209+
208210
@numba_util.jit()
209211
def central_scaled_coordinate_2d_numba_from(
210212
shape_native: Tuple[int, int],
@@ -305,6 +307,7 @@ def central_scaled_coordinate_2d_from(
305307

306308
return (y_pixel, x_pixel)
307309

310+
308311
def pixel_coordinates_2d_from(
309312
scaled_coordinates_2d: Tuple[float, float],
310313
shape_native: Tuple[int, int],
@@ -589,9 +592,9 @@ def grid_pixel_centres_2d_slim_from(
589592
centres_scaled = np.array(centres_scaled)
590593
pixel_scales = np.array(pixel_scales)
591594
sign = np.array([-1.0, 1.0])
592-
return (
593-
(sign * grid_scaled_2d_slim / pixel_scales) + centres_scaled + 0.5
594-
).astype(int)
595+
return ((sign * grid_scaled_2d_slim / pixel_scales) + centres_scaled + 0.5).astype(
596+
int
597+
)
595598

596599

597600
def grid_pixel_indexes_2d_slim_from(
@@ -647,9 +650,7 @@ def grid_pixel_indexes_2d_slim_from(
647650
)
648651

649652
return (
650-
(grid_pixels_2d_slim * np.array([shape_native[1], 1]))
651-
.sum(axis=1)
652-
.astype(int)
653+
(grid_pixels_2d_slim * np.array([shape_native[1], 1])).sum(axis=1).astype(int)
653654
)
654655

655656

@@ -698,9 +699,7 @@ def grid_scaled_2d_slim_from(
698699
centres_scaled = np.array(centres_scaled)
699700
pixel_scales = np.array(pixel_scales)
700701
sign = np.array([-1, 1])
701-
return (
702-
(grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
703-
)
702+
return (grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
704703

705704

706705
def grid_pixel_centres_2d_from(
@@ -750,9 +749,7 @@ def grid_pixel_centres_2d_from(
750749
centres_scaled = np.array(centres_scaled)
751750
pixel_scales = np.array(pixel_scales)
752751
sign = np.array([-1.0, 1.0])
753-
return (
754-
(sign * grid_scaled_2d / pixel_scales) + centres_scaled + 0.5
755-
).astype(int)
752+
return ((sign * grid_scaled_2d / pixel_scales) + centres_scaled + 0.5).astype(int)
756753

757754

758755
def extent_symmetric_from(

autoarray/inversion/inversion/dataset_interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def __init__(
44
data,
55
noise_map,
66
grids=None,
7-
convolver=None,
7+
psf=None,
88
transformer=None,
99
w_tilde=None,
1010
noise_covariance_matrix=None,
@@ -41,7 +41,7 @@ def __init__(
4141
border_relocator
4242
The border relocator, which relocates coordinates outside the border of the source-plane data grid to its
4343
edge.
44-
convolver
44+
psf
4545
Perform 2D convolution of the imaigng data's PSF when computing the operated mapping matrix.
4646
transformer
4747
Performs a Fourier transform of the image-data from real-space to visibilities when computing the
@@ -59,7 +59,7 @@ def __init__(
5959
self.data = data
6060
self.noise_map = noise_map
6161
self.grids = grids
62-
self.convolver = convolver
62+
self.psf = psf
6363
self.transformer = transformer
6464
self.w_tilde = w_tilde
6565
self.noise_covariance_matrix = noise_covariance_matrix

autoarray/inversion/inversion/factory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def inversion_interferometer_from(
172172
dataset
173173
The dataset (e.g. `Interferometer`) whose data is reconstructed via the `Inversion`.
174174
w_tilde
175-
Object which uses the `Imaging` dataset's PSF / `Convolver` operateor to perform the `Inversion` using the
176-
w-tilde formalism.
175+
Object which uses the `Imaging` dataset's PSF to perform the `Inversion` using the w-tilde formalism.
177176
linear_obj_list
178177
The list of linear objects (e.g. analytic functions, a mapper with a pixelized grid) which reconstruct the
179178
input dataset's data and whose values are solved for via the inversion.

autoarray/inversion/inversion/imaging/abstract.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def __init__(
3232
of the linear object parameters that best reconstruct the dataset to be solved, via linear matrix algebra.
3333
3434
This object contains matrices and vectors which perform an inversion for fits to an `Imaging` dataset. This
35-
includes operations which use a PSF / `Convolver` in order to incorporate blurring into the solved for
36-
linear object pixels.
35+
includes operations which use a PSF in order to incorporate blurring into the solved for linear object pixels.
3736
3837
The inversion may be regularized, whereby the parameters of the linear objects used to reconstruct the data
3938
are smoothed with one another such that their solved for values conform to certain properties (e.g. smoothness
@@ -76,8 +75,8 @@ def __init__(
7675
)
7776

7877
@property
79-
def convolver(self):
80-
return self.dataset.convolver
78+
def psf(self):
79+
return self.dataset.psf
8180

8281
@property
8382
def operated_mapping_matrix_list(self) -> List[np.ndarray]:
@@ -88,15 +87,15 @@ def operated_mapping_matrix_list(self) -> List[np.ndarray]:
8887
This is used to construct the simultaneous linear equations which reconstruct the data.
8988
9089
This property returns the a list of each linear object's blurred mapping matrix, which is computed by
91-
blurring each linear object's `mapping_matrix` property with the `Convolver` operator.
90+
blurring each linear object's `mapping_matrix` property with the `psf` operator.
9291
9392
A linear object may have a `operated_mapping_matrix_override` property, which bypasses the `mapping_matrix`
9493
computation and convolution operator and is directly placed in the `operated_mapping_matrix_list`.
9594
"""
9695

9796
return [
9897
(
99-
self.convolver.convolve_mapping_matrix(
98+
self.psf.convolve_mapping_matrix(
10099
mapping_matrix=linear_obj.mapping_matrix
101100
)
102101
if linear_obj.operated_mapping_matrix_override is None
@@ -139,7 +138,7 @@ def linear_func_operated_mapping_matrix_dict(self) -> Dict:
139138
if linear_func.operated_mapping_matrix_override is not None:
140139
operated_mapping_matrix = linear_func.operated_mapping_matrix_override
141140
else:
142-
operated_mapping_matrix = self.convolver.convolve_mapping_matrix(
141+
operated_mapping_matrix = self.psf.convolve_mapping_matrix(
143142
mapping_matrix=linear_func.mapping_matrix
144143
)
145144

@@ -221,7 +220,7 @@ def mapper_operated_mapping_matrix_dict(self) -> Dict:
221220
mapper_operated_mapping_matrix_dict = {}
222221

223222
for mapper in self.cls_list_from(cls=AbstractMapper):
224-
operated_mapping_matrix = self.convolver.convolve_mapping_matrix(
223+
operated_mapping_matrix = self.psf.convolve_mapping_matrix(
225224
mapping_matrix=mapper.mapping_matrix
226225
)
227226

autoarray/inversion/inversion/imaging/mapping.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ def __init__(
3939
4040
Parameters
4141
----------
42-
noise_map
43-
The noise-map of the observed imaging data which values are solved for.
44-
convolver
45-
The convolver which performs a 2D convolution on the mapping matrix with the imaging data's PSF.
42+
dataset
43+
The dataset containing the image data, noise-map and psf which is fitted by the inversion.
4644
linear_obj_list
4745
The linear objects used to reconstruct the data's observed values. If multiple linear objects are passed
4846
the simultaneous linear equations are combined and solved simultaneously.
@@ -80,7 +78,7 @@ def _data_vector_mapper(self) -> np.ndarray:
8078
mapper = mapper_list[i]
8179
param_range = mapper_param_range_list[i]
8280

83-
operated_mapping_matrix = self.convolver.convolve_mapping_matrix(
81+
operated_mapping_matrix = self.psf.convolve_mapping_matrix(
8482
mapping_matrix=mapper.mapping_matrix
8583
)
8684

@@ -142,7 +140,7 @@ def _curvature_matrix_mapper_diag(self) -> Optional[np.ndarray]:
142140
mapper_i = mapper_list[i]
143141
mapper_param_range_i = mapper_param_range_list[i]
144142

145-
operated_mapping_matrix = self.convolver.convolve_mapping_matrix(
143+
operated_mapping_matrix = self.psf.convolve_mapping_matrix(
146144
mapping_matrix=mapper_i.mapping_matrix
147145
)
148146

0 commit comments

Comments
 (0)