1010def cap_array_2d_for_small_datasets (array_2d , pixel_scales ):
1111 """
1212 Center-crop a 2D autoarray to the small-datasets cap when
13- ``PYAUTO_SMALL_DATASETS=1`` is active.
14-
15- Returns ``(array_2d, pixel_scales)`` unchanged in any of these cases:
16-
17- - ``PYAUTO_SMALL_DATASETS`` is not set to ``"1"``.
18- - ``array_2d.shape_native`` is already at-or-below the cap (16, 16).
19-
20- When the env var is set and the input shape exceeds (16, 16), returns a
21- new ``Array2D`` center-cropped to (16, 16) with ``pixel_scales`` overridden
22- to 0.6 — matching the convention used by ``Mask2D.circular`` and
23- ``Grid2D.uniform`` so the loaded dataset stays shape-consistent with masks
24- and grids built under the same env var.
13+ ``PYAUTO_SMALL_DATASETS=1`` is active, and relabel it at the capped
14+ pixel scale.
15+
16+ Returns ``(array_2d, pixel_scales)`` unchanged only when
17+ ``PYAUTO_SMALL_DATASETS`` is not set to ``"1"``.
18+
19+ When the env var is set, ``pixel_scales`` is always overridden to 0.6 —
20+ matching the convention used by ``Mask2D.circular`` and ``Grid2D.uniform``
21+ so the loaded dataset stays shape-consistent with masks and grids built
22+ under the same env var — and the shape is handled per case:
23+
24+ - Input shape exceeds (16, 16): center-cropped to (16, 16).
25+ - Input shape is already at-or-below the cap: kept as-is, because a capped
26+ simulator wrote it at 0.6 already. Only the scale is corrected.
27+
28+ That second case must still rebuild the ``Array2D``, not just return a
29+ corrected scalar: the array is constructed by the caller before this call
30+ and carries its own geometry, so an uncorrected array would keep the
31+ caller's uncapped scale no matter what scalar is returned. Leaving it
32+ uncorrected mislabels the frame 6x (±0.8" instead of ±4.8" for a 16x16
33+ field), which pushes off-centre galaxies outside the frame; their
34+ non-negative linear intensity solve then correctly returns exactly 0.0 and
35+ the failure surfaces far downstream as a collapsed prior rather than as a
36+ geometry error (PyAutoArray #430).
2537
2638 The same env var is honoured for shape construction in
2739 ``Mask2D.circular`` and ``Grid2D.uniform`` (and by ``should_simulate``
@@ -36,12 +48,18 @@ def cap_array_2d_for_small_datasets(array_2d, pixel_scales):
3648 if os .environ .get ("PYAUTO_SMALL_DATASETS" ) != "1" :
3749 return array_2d , pixel_scales
3850
51+ from autoarray .structures .arrays .uniform_2d import Array2D
52+
3953 h , w = array_2d .shape_native
4054 cap_h , cap_w = SMALL_DATASETS_SHAPE_NATIVE
4155 if h <= cap_h and w <= cap_w :
42- return array_2d , pixel_scales
43-
44- from autoarray .structures .arrays .uniform_2d import Array2D
56+ return (
57+ Array2D .no_mask (
58+ values = array_2d .native .array ,
59+ pixel_scales = SMALL_DATASETS_PIXEL_SCALES ,
60+ ),
61+ SMALL_DATASETS_PIXEL_SCALES ,
62+ )
4563
4664 h0 , w0 = (h - cap_h ) // 2 , (w - cap_w ) // 2
4765 cropped = array_2d .native .array [h0 :h0 + cap_h , w0 :w0 + cap_w ]
0 commit comments