Skip to content

Commit 7b8a20d

Browse files
Jammy2211Jammy2211
authored andcommitted
use preloading in Grids
1 parent 3946125 commit 7b8a20d

4 files changed

Lines changed: 64 additions & 9 deletions

File tree

autoarray/dataset/grids.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,70 @@ def __init__(
6161
self.over_sample_size_pixelization = over_sample_size_pixelization
6262
self.psf = psf
6363

64-
self.lp = Grid2D.from_mask(
64+
self._lp = None
65+
self._pixelization = None
66+
self._blurring = None
67+
self._border_relocator = None
68+
69+
self.use_w_tilde = use_w_tilde
70+
71+
@property
72+
def lp(self):
73+
74+
if self._lp is not None:
75+
return self._lp
76+
77+
self._lp = Grid2D.from_mask(
6578
mask=self.mask,
6679
over_sample_size=self.over_sample_size_lp,
6780
)
6881

69-
self.pixelization = Grid2D.from_mask(
82+
return self._lp
83+
84+
@property
85+
def pixelization(self):
86+
if self._pixelization is not None:
87+
return self._pixelization
88+
89+
self._pixelization = Grid2D.from_mask(
7090
mask=self.mask,
7191
over_sample_size=self.over_sample_size_pixelization,
7292
)
7393

94+
return self._pixelization
95+
96+
@property
97+
def blurring(self):
98+
99+
if self._blurring is not None:
100+
return self._blurring
101+
74102
if self.psf is None:
75-
self.blurring = None
103+
self._blurring = None
76104
else:
77105
try:
78-
self.blurring = self.lp.blurring_grid_via_kernel_shape_from(
106+
self._blurring = self.lp.blurring_grid_via_kernel_shape_from(
79107
kernel_shape_native=self.psf.shape_native,
80108
)
81109
except exc.MaskException:
82-
self.blurring = None
110+
self._blurring = None
111+
112+
return self._blurring
83113

84-
self.border_relocator = BorderRelocator(
114+
@property
115+
def border_relocator(self) -> BorderRelocator:
116+
117+
if self._border_relocator is not None:
118+
return self._border_relocator
119+
120+
self._border_relocator = BorderRelocator(
85121
mask=self.mask,
86122
sub_size=self.over_sample_size_pixelization,
87-
use_w_tilde=use_w_tilde,
123+
use_w_tilde=self.use_w_tilde,
88124
)
89125

126+
return self._border_relocator
127+
90128

91129
class GridsInterface:
92130
def __init__(

autoarray/fit/fit_dataset.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ def __init__(
150150
self.dataset = dataset
151151
self.use_mask_in_fit = use_mask_in_fit
152152
self.dataset_model = dataset_model or DatasetModel()
153+
154+
# Ensures preloaded in memory so repeated calls are fast
155+
156+
self.dataset.grids.lp
157+
self.dataset.grids.pixelization
158+
self.dataset.grids.blurring
159+
self.dataset.grids.border_relocator
160+
153161
self._xp = xp
154162

155163
@property

autoarray/operators/over_sampling/over_sample_util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ def grid_2d_slim_over_sampled_via_mask_from(
178178
skipping pixels where sub_size == 0 (to avoid divide-by-zero).
179179
"""
180180

181+
import traceback
182+
183+
def debug_trace():
184+
print("=== FULL CALL TRACE ===")
185+
traceback.print_stack()
186+
print("=======================")
187+
188+
debug_trace()
189+
181190
H, W = mask_2d.shape
182191
sy, sx = pixel_scales
183192
oy, ox = origin

test_autoarray/dataset/abstract/test_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test__apply_over_sampling(image_7x7, noise_map_7x7):
8484
grid_sub_2 = dataset_7x7.grids.lp
8585
grids_pixelization_sub_2 = dataset_7x7.grids.pixelization
8686

87-
dataset_7x7.grids.__dict__["lp"][0][0] = 100.0
88-
dataset_7x7.grids.__dict__["pixelization"][0][0] = 100.0
87+
dataset_7x7.grids.__dict__["_lp"][0][0] = 100.0
88+
dataset_7x7.grids.__dict__["_pixelization"][0][0] = 100.0
8989

9090
assert dataset_7x7.grids.lp[0][0] == pytest.approx(100.0, 1.0e-4)
9191
assert dataset_7x7.grids.pixelization[0][0] == pytest.approx(100.0, 1.0e-4)

0 commit comments

Comments
 (0)