Skip to content

Commit f1961a5

Browse files
Jammy2211Jammy2211
authored andcommitted
switch to inversion_imaging_util.w_tilde_data_imaging_from
1 parent c43b0f0 commit f1961a5

4 files changed

Lines changed: 22 additions & 90 deletions

File tree

autoarray/dataset/imaging/dataset.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,12 @@ def apply_over_sampling(
474474

475475
return dataset
476476

477-
def apply_w_tilde(self, disable_fft_pad: bool = False):
477+
def apply_w_tilde(
478+
self,
479+
batch_size: int = 128,
480+
disable_fft_pad: bool = False,
481+
use_jax: bool = False,
482+
):
478483
"""
479484
The w_tilde formalism of the linear algebra equations precomputes the convolution of every pair of masked
480485
noise-map values given the PSF (see `inversion.inversion_util`).
@@ -487,39 +492,19 @@ def apply_w_tilde(self, disable_fft_pad: bool = False):
487492
488493
Returns
489494
-------
490-
WTildeImaging
491-
Precomputed values used for the w tilde formalism of linear algebra calculations.
495+
batch_size
496+
The size of batches used to compute the w-tilde curvature matrix via FFT-based convolution,
497+
which can be reduced to produce lower memory usage at the cost of speed
498+
disable_fft_pad
499+
The FFT PSF convolution is optimal for a certain 2D FFT padding or trimming,
500+
which places the fewest zeros around the image. If this is set to `True`, this optimal padding is not
501+
performed and the image is used as-is. This is normally used to avoid repadding data that has already been
502+
padded.
503+
use_jax
504+
Whether to use JAX to compute W-Tilde. This requires JAX to be installed.
492505
"""
493506

494-
logger.info("IMAGING - Computing W-Tilde... May take a moment.")
495-
496-
try:
497-
import numba
498-
except ModuleNotFoundError:
499-
raise exc.InversionException(
500-
"Inversion w-tilde functionality (pixelized reconstructions) is "
501-
"disabled if numba is not installed.\n\n"
502-
"This is because the run-times without numba are too slow.\n\n"
503-
"Please install numba, which is described at the following web page:\n\n"
504-
"https://pyautolens.readthedocs.io/en/latest/installation/overview.html"
505-
)
506-
507-
(
508-
curvature_preload,
509-
indexes,
510-
lengths,
511-
) = inversion_imaging_numba_util.w_tilde_curvature_preload_imaging_from(
512-
noise_map_native=np.array(self.noise_map.native.array).astype("float64"),
513-
kernel_native=np.array(self.psf.native.array).astype("float64"),
514-
native_index_for_slim_index=np.array(
515-
self.mask.derive_indexes.native_for_slim
516-
).astype("int"),
517-
)
518-
519507
w_tilde = WTildeImaging(
520-
curvature_preload=curvature_preload,
521-
indexes=indexes.astype("int"),
522-
lengths=lengths.astype("int"),
523508
noise_map=self.noise_map,
524509
psf=self.psf,
525510
fft_mask=self.mask,

autoarray/dataset/imaging/w_tilde.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
class WTildeImaging(AbstractWTilde):
1313
def __init__(
1414
self,
15-
curvature_preload: np.ndarray,
16-
indexes: np.ndim,
17-
lengths: np.ndarray,
1815
noise_map: np.ndarray,
1916
psf: np.ndarray,
2017
fft_mask: np.ndarray,
@@ -40,52 +37,13 @@ def __init__(
4037
matrix efficienctly.
4138
"""
4239
super().__init__(
43-
curvature_preload=curvature_preload, fft_mask=fft_mask
40+
curvature_preload=None,
41+
fft_mask=fft_mask
4442
)
4543

46-
self.indexes = indexes
47-
self.lengths = lengths
4844
self.noise_map = noise_map
4945
self.psf = psf
5046

51-
@property
52-
def w_matrix(self):
53-
"""
54-
The matrix `w_tilde_curvature` is a matrix of dimensions [image_pixels, image_pixels] that encodes the PSF
55-
convolution of every pair of image pixels given the noise map. This can be used to efficiently compute the
56-
curvature matrix via the mappings between image and source pixels, in a way that omits having to perform the
57-
PSF convolution on every individual source pixel. This provides a significant speed up for inversions of imaging
58-
datasets.
59-
60-
The limitation of this matrix is that the dimensions of [image_pixels, image_pixels] can exceed many 10s of GB's,
61-
making it impossible to store in memory and its use in linear algebra calculations extremely. The method
62-
`w_tilde_curvature_preload_imaging_from` describes a compressed representation that overcomes this hurdles. It is
63-
advised `w_tilde` and this method are only used for testing.
64-
65-
Parameters
66-
----------
67-
noise_map_native
68-
The two dimensional masked noise-map of values which w_tilde is computed from.
69-
kernel_native
70-
The two dimensional PSF kernel that w_tilde encodes the convolution of.
71-
native_index_for_slim_index
72-
An array of shape [total_x_pixels*sub_size] that maps pixels from the slimmed array to the native array.
73-
74-
Returns
75-
-------
76-
ndarray
77-
A matrix that encodes the PSF convolution values between the noise map that enables efficient calculation of
78-
the curvature matrix.
79-
"""
80-
81-
return inversion_imaging_numba_util.w_tilde_curvature_imaging_from(
82-
noise_map_native=self.noise_map.native.array,
83-
kernel_native=self.psf.native.array,
84-
native_index_for_slim_index=np.array(
85-
self.mask.derive_indexes.native_for_slim
86-
).astype("int"),
87-
)
88-
8947
@property
9048
def psf_operator_matrix_dense(self):
9149

autoarray/dataset/interferometer/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def apply_w_tilde(
195195
if curvature_preload is None:
196196

197197
logger.info(
198-
"INTERFEROMETER - Computing W-Tilde; runtime scales with visibility count and mask resolution, extreme inputs may exceed hours."
198+
"INTERFEROMETER - Computing W-Tilde; runtime scales with visibility count and mask resolution, CPU run times may exceed hours."
199199
)
200200

201201
curvature_preload = inversion_interferometer_util.w_tilde_curvature_preload_interferometer_from(

autoarray/inversion/inversion/imaging/w_tilde.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from autoarray.structures.arrays.uniform_2d import Array2D
1515

1616
from autoarray import exc
17-
from autoarray.inversion.inversion.imaging import inversion_imaging_numba_util
17+
from autoarray.inversion.inversion.imaging import inversion_imaging_util
1818

1919

2020
class InversionImagingWTilde(AbstractInversionImaging):
@@ -49,17 +49,6 @@ def __init__(
4949
the simultaneous linear equations are combined and solved simultaneously.
5050
"""
5151

52-
try:
53-
import numba
54-
except ModuleNotFoundError:
55-
raise exc.InversionException(
56-
"Inversion w-tilde functionality (pixelized reconstructions) is "
57-
"disabled if numba is not installed.\n\n"
58-
"This is because the run-times without numba are too slow.\n\n"
59-
"Please install numba, which is described at the following web page:\n\n"
60-
"https://pyautolens.readthedocs.io/en/latest/installation/overview.html"
61-
)
62-
6352
super().__init__(
6453
dataset=dataset, linear_obj_list=linear_obj_list, settings=settings, xp=xp
6554
)
@@ -68,8 +57,8 @@ def __init__(
6857

6958
@cached_property
7059
def w_tilde_data(self):
71-
return inversion_imaging_numba_util.w_tilde_data_imaging_from(
72-
image_native=np.array(self.data.native.array),
60+
return inversion_imaging_util.w_tilde_data_imaging_from(
61+
image_native=self.data.native.array,
7362
noise_map_native=self.noise_map.native.array,
7463
kernel_native=self.psf.native.array,
7564
native_index_for_slim_index=self.data.mask.derive_indexes.native_for_slim,

0 commit comments

Comments
 (0)