Skip to content

Commit 6fcbd08

Browse files
Jammy2211Jammy2211
authored andcommitted
add pixel_triplets_from_subpixel_arrays_from
1 parent f1961a5 commit 6fcbd08

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

autoarray/inversion/inversion/imaging/inversion_imaging_util.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
import numpy as np
22

3+
def pixel_triplets_from_subpixel_arrays_from(
4+
pix_indexes_for_sub, # (M_sub, P)
5+
pix_weights_for_sub, # (M_sub, P)
6+
slim_index_for_sub, # (M_sub,)
7+
fft_index_for_masked_pixel, # (N_unmasked,)
8+
sub_fraction_slim, # (N_unmasked,)
9+
):
10+
"""
11+
Build sparse source→image mapping triplets (rows, cols, vals)
12+
for a fixed-size interpolation stencil.
13+
14+
Assumptions:
15+
- Every subpixel maps to exactly P source pixels
16+
- All entries in pix_indexes_for_sub are valid
17+
- No padding / ragged rows needed
18+
"""
19+
import jax.numpy as jnp
20+
21+
22+
M_sub, P = pix_indexes_for_sub.shape
23+
24+
sub_ids = jnp.repeat(jnp.arange(M_sub, dtype=jnp.int32), P)
25+
26+
cols = pix_indexes_for_sub.reshape(-1).astype(jnp.int32)
27+
vals = pix_weights_for_sub.reshape(-1).astype(jnp.float64)
28+
29+
slim_rows = slim_index_for_sub[sub_ids].astype(jnp.int32)
30+
rows = fft_index_for_masked_pixel[slim_rows].astype(jnp.int32)
31+
32+
vals = vals * sub_fraction_slim[slim_rows].astype(jnp.float64)
33+
return rows, cols, vals
34+
335

436
def psf_operator_matrix_dense_from(
537
kernel_native: np.ndarray,

0 commit comments

Comments
 (0)