@@ -162,6 +162,77 @@ def test__from_fits__all_data_in_one_fits_file_multiple_hdus__loads_data_psf_noi
162162 assert dataset .noise_map .mask .pixel_scales == (0.1 , 0.1 )
163163
164164
165+ def test__from_fits__small_datasets_env_caps_data_and_noise_map (
166+ test_data_path , monkeypatch
167+ ):
168+ """When PYAUTO_SMALL_DATASETS=1, Imaging.from_fits center-crops data and
169+ noise_map to (15, 15) at pixel_scales=0.6 so they stay shape-consistent
170+ with masks built via Mask2D.circular under the same env var. PSF is left
171+ alone."""
172+ from astropy .io import fits
173+
174+ fits .writeto (
175+ Path (test_data_path ) / "data_30x30.fits" ,
176+ data = np .ones ((30 , 30 ), dtype = np .float64 ),
177+ overwrite = True ,
178+ )
179+ fits .writeto (
180+ Path (test_data_path ) / "noise_map_30x30.fits" ,
181+ data = 2.0 * np .ones ((30 , 30 ), dtype = np .float64 ),
182+ overwrite = True ,
183+ )
184+ fits .writeto (
185+ Path (test_data_path ) / "psf_5x5.fits" ,
186+ data = (1.0 / 25.0 ) * np .ones ((5 , 5 ), dtype = np .float64 ),
187+ overwrite = True ,
188+ )
189+
190+ monkeypatch .setenv ("PYAUTO_SMALL_DATASETS" , "1" )
191+
192+ dataset = aa .Imaging .from_fits (
193+ pixel_scales = 0.08 ,
194+ data_path = Path (test_data_path ) / "data_30x30.fits" ,
195+ psf_path = Path (test_data_path ) / "psf_5x5.fits" ,
196+ noise_map_path = Path (test_data_path ) / "noise_map_30x30.fits" ,
197+ )
198+
199+ assert dataset .data .shape_native == (15 , 15 )
200+ assert dataset .noise_map .shape_native == (15 , 15 )
201+ assert dataset .pixel_scales == (0.6 , 0.6 )
202+ assert dataset .psf .kernel .shape_native == (5 , 5 )
203+
204+
205+ def test__from_fits__small_datasets_env_unset__shape_unchanged (
206+ test_data_path , monkeypatch
207+ ):
208+ """Sanity: with the env var unset, from_fits returns the on-disk shape
209+ unchanged, even for files larger than the cap."""
210+ from astropy .io import fits
211+
212+ fits .writeto (
213+ Path (test_data_path ) / "data_30x30.fits" ,
214+ data = np .ones ((30 , 30 ), dtype = np .float64 ),
215+ overwrite = True ,
216+ )
217+ fits .writeto (
218+ Path (test_data_path ) / "noise_map_30x30.fits" ,
219+ data = 2.0 * np .ones ((30 , 30 ), dtype = np .float64 ),
220+ overwrite = True ,
221+ )
222+
223+ monkeypatch .delenv ("PYAUTO_SMALL_DATASETS" , raising = False )
224+
225+ dataset = aa .Imaging .from_fits (
226+ pixel_scales = 0.08 ,
227+ data_path = Path (test_data_path ) / "data_30x30.fits" ,
228+ noise_map_path = Path (test_data_path ) / "noise_map_30x30.fits" ,
229+ )
230+
231+ assert dataset .data .shape_native == (30 , 30 )
232+ assert dataset .noise_map .shape_native == (30 , 30 )
233+ assert dataset .pixel_scales == (0.08 , 0.08 )
234+
235+
165236def test__output_to_fits__round_trips_data_psf_noise_map_correctly (
166237 imaging_7x7 , test_data_path
167238):
0 commit comments