Skip to content

Commit 3aef08a

Browse files
committed
but of typing simplication
1 parent d33ab44 commit 3aef08a

3 files changed

Lines changed: 9 additions & 26 deletions

File tree

autoarray/operators/over_sampling/over_sample_util.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def over_sample_size_convert_to_array_2d_from(
4444
if isinstance(over_sample_size, int):
4545
over_sample_size = np.full(
4646
fill_value=over_sample_size, shape=mask.pixels_in_mask
47-
).astype("int")
47+
)
4848

49-
return Array2D(values=over_sample_size, mask=mask)
49+
return Array2D(values=np.array(over_sample_size).astype("int"), mask=mask)
5050

5151

5252
@numba_util.jit()
@@ -444,23 +444,6 @@ def grid_2d_slim_over_sampled_via_mask_from(
444444

445445
for y1 in range(sub):
446446
for x1 in range(sub):
447-
# if use_jax:
448-
# # while this makes it run, it is very, very slow
449-
# grid_slim = grid_slim.at[sub_index, 0].set(
450-
# -(
451-
# y_scaled
452-
# - y_sub_half
453-
# + y1 * y_sub_step
454-
# + (y_sub_step / 2.0)
455-
# )
456-
# )
457-
# grid_slim = grid_slim.at[sub_index, 1].set(
458-
# x_scaled
459-
# - x_sub_half
460-
# + x1 * x_sub_step
461-
# + (x_sub_step / 2.0)
462-
# )
463-
# else:
464447
grid_slim[sub_index, 0] = -(
465448
y_scaled - y_sub_half + y1 * y_sub_step + (y_sub_step / 2.0)
466449
)

autoarray/operators/over_sampling/over_sampler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def sub_is_uniform(self) -> bool:
154154
Returns True if the sub_size is uniform across all pixels in the mask.
155155
"""
156156
return np.all(
157-
np.isclose(self.sub_size.array, self.sub_size.array[0])
157+
np.isclose(self.sub_size, self.sub_size[0])
158158
)
159159

160160
def tree_flatten(self):
@@ -233,12 +233,12 @@ def binned_array_2d_from(self, array: Array2D) -> "Array2D":
233233

234234
if self.sub_is_uniform:
235235
binned_array_2d = array.reshape(
236-
self.mask.shape_slim, self.sub_size.array[0] ** 2
236+
self.mask.shape_slim, self.sub_size[0] ** 2
237237
).mean(axis=1)
238238
else:
239239

240240
# Define group sizes
241-
group_sizes = jnp.array(self.sub_size.array.astype("int") ** 2)
241+
group_sizes = jnp.array(self.sub_size.array ** 2)
242242

243243
# Compute the cumulative sum of group sizes to get split points
244244
split_indices = jnp.cumsum(group_sizes)
@@ -310,7 +310,7 @@ def sub_mask_native_for_sub_mask_slim(self) -> np.ndarray:
310310
print(derive_indexes_2d.sub_mask_native_for_sub_mask_slim)
311311
"""
312312
return over_sample_util.native_sub_index_for_slim_sub_index_2d_from(
313-
mask_2d=self.mask.array, sub_size=np.array(self.sub_size)
313+
mask_2d=self.mask.array, sub_size=self.sub_size.array
314314
).astype("int")
315315

316316
@cached_property
@@ -363,7 +363,7 @@ def slim_for_sub_slim(self) -> np.ndarray:
363363
print(derive_indexes_2d.slim_for_sub_slim)
364364
"""
365365
return over_sample_util.slim_index_for_sub_slim_index_via_mask_2d_from(
366-
mask_2d=np.array(self.mask), sub_size=np.array(self.sub_size)
366+
mask_2d=np.array(self.mask), sub_size=self.sub_size.array
367367
).astype("int")
368368

369369
@property
@@ -386,7 +386,7 @@ def uniform_over_sampled(self):
386386
grid = over_sample_util.grid_2d_slim_over_sampled_via_mask_from(
387387
mask_2d=np.array(self.mask),
388388
pixel_scales=self.mask.pixel_scales,
389-
sub_size=np.array(self.sub_size).astype("int"),
389+
sub_size=self.sub_size.array.astype("int"),
390390
origin=self.mask.origin,
391391
)
392392

autoarray/structures/grids/uniform_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def __init__(
185185
over_sample_util.grid_2d_slim_over_sampled_via_mask_from(
186186
mask_2d=np.array(self.mask),
187187
pixel_scales=self.mask.pixel_scales,
188-
sub_size=np.array(self.over_sampler.sub_size._array).astype("int"),
188+
sub_size=self.over_sampler.sub_size.array.astype("int"),
189189
origin=self.mask.origin,
190190
)
191191
)

0 commit comments

Comments
 (0)