@@ -196,8 +196,8 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map(
196196 noise_map_path = Path (test_data_path ) / "noise_map_30x30.fits" ,
197197 )
198198
199- assert dataset .data .shape_native == (15 , 15 )
200- assert dataset .noise_map .shape_native == (15 , 15 )
199+ assert dataset .data .shape_native == (16 , 16 )
200+ assert dataset .noise_map .shape_native == (16 , 16 )
201201 assert dataset .pixel_scales == (0.6 , 0.6 )
202202 assert dataset .psf .kernel .shape_native == (5 , 5 )
203203
@@ -410,117 +410,117 @@ def test__psf_not_odd_x_odd_kernel__raises_error():
410410 noise_map = noise_map ,
411411 psf = psf ,
412412 )
413-
414-
415- def test__convolve_over_sample_size__validation_and_plumbing ():
416- data = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
417- noise_map = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
418- kernel_fine = aa .Array2D .no_mask (values = np .ones ((9 , 9 )), pixel_scales = 0.5 )
419- psf = aa .Convolver (kernel = kernel_fine )
420-
421- # convolve size must be a plain int.
422- with pytest .raises (TypeError ):
423- aa .Imaging (
424- data = data ,
425- noise_map = noise_map ,
426- psf = psf ,
427- over_sample_size_lp = 2 ,
428- convolve_over_sample_size_lp = 2.0 ,
429- )
430-
431- # k x s coupling: every over_sample_size entry must be divisible by the
432- # convolve size — a non-divisible int raises, divisible ints and adaptive
433- # arrays are legal.
434- with pytest .raises (aa .exc .DatasetException ):
435- aa .Imaging (
436- data = data ,
437- noise_map = noise_map ,
438- psf = psf ,
439- over_sample_size_lp = 3 ,
440- convolve_over_sample_size_lp = 2 ,
441- )
442-
443- sub_size_adaptive = np .full (fill_value = 2 , shape = data .shape_slim )
444- sub_size_adaptive [0 ] = 4
445-
446- dataset_adaptive = aa .Imaging (
447- data = data ,
448- noise_map = noise_map ,
449- psf = psf ,
450- over_sample_size_lp = aa .Array2D (values = sub_size_adaptive , mask = data .mask ),
451- convolve_over_sample_size_lp = 2 ,
452- )
453- assert dataset_adaptive .convolve_over_sample_size_lp == 2
454-
455- sub_size_bad = np .full (fill_value = 2 , shape = data .shape_slim )
456- sub_size_bad [0 ] = 3
457-
458- with pytest .raises (aa .exc .DatasetException ):
459- aa .Imaging (
460- data = data ,
461- noise_map = noise_map ,
462- psf = psf ,
463- over_sample_size_lp = aa .Array2D (values = sub_size_bad , mask = data .mask ),
464- convolve_over_sample_size_lp = 2 ,
465- )
466-
467- # Differing lp / pixelization convolve sizes are not supported (single PSF kernel).
468- with pytest .raises (aa .exc .DatasetException ):
469- aa .Imaging (
470- data = data ,
471- noise_map = noise_map ,
472- psf = psf ,
473- over_sample_size_lp = 2 ,
474- over_sample_size_pixelization = 4 ,
475- convolve_over_sample_size_lp = 2 ,
476- convolve_over_sample_size_pixelization = 4 ,
477- )
478-
479- # Valid dataset: the psf carries the convolve size and apply_mask preserves it,
480- # precomputing the fine state and building the blurring grid at the fine resolution.
481- dataset = aa .Imaging (
482- data = data ,
483- noise_map = noise_map ,
484- psf = psf ,
485- over_sample_size_lp = 2 ,
486- convolve_over_sample_size_lp = 2 ,
487- )
488-
489- assert dataset .convolve_over_sample_size_lp == 2
490- assert dataset .psf .convolve_over_sample_size == 2
491-
492- mask = aa .Mask2D .circular (shape_native = (11 , 11 ), pixel_scales = 1.0 , radius = 3.5 )
493- masked = dataset .apply_mask (mask = mask )
494-
495- assert masked .convolve_over_sample_size_lp == 2
496- assert masked .psf .convolve_over_sample_size == 2
497- assert masked .psf ._state is not None
498- assert masked .psf ._state .sub_slim_to_fine_slim is not None
499-
500- # The blurring grid footprint uses the kernel's image-resolution shape (5x5 for a
501- # 9x9 fine kernel at s=2) and is evaluated at the fine resolution.
502- blurring_mask = mask .derive_mask .blurring_from (
503- kernel_shape_native = (5 , 5 ), allow_padding = True
504- )
505- assert np .array (masked .grids .blurring .over_sampled ).shape == (
506- blurring_mask .pixels_in_mask * 4 ,
507- 2 ,
508- )
509-
510-
511- def test__convolve_over_sample_size__sparse_operator_guard ():
512- data = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
513- noise_map = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
514- kernel_fine = aa .Array2D .no_mask (values = np .ones ((9 , 9 )), pixel_scales = 0.5 )
515- psf = aa .Convolver (kernel = kernel_fine )
516-
517- dataset = aa .Imaging (
518- data = data ,
519- noise_map = noise_map ,
520- psf = psf ,
521- over_sample_size_pixelization = 2 ,
522- convolve_over_sample_size_pixelization = 2 ,
523- )
524-
525- with pytest .raises (aa .exc .DatasetException ):
526- dataset .apply_sparse_operator ()
413+
414+
415+ def test__convolve_over_sample_size__validation_and_plumbing ():
416+ data = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
417+ noise_map = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
418+ kernel_fine = aa .Array2D .no_mask (values = np .ones ((9 , 9 )), pixel_scales = 0.5 )
419+ psf = aa .Convolver (kernel = kernel_fine )
420+
421+ # convolve size must be a plain int.
422+ with pytest .raises (TypeError ):
423+ aa .Imaging (
424+ data = data ,
425+ noise_map = noise_map ,
426+ psf = psf ,
427+ over_sample_size_lp = 2 ,
428+ convolve_over_sample_size_lp = 2.0 ,
429+ )
430+
431+ # k x s coupling: every over_sample_size entry must be divisible by the
432+ # convolve size — a non-divisible int raises, divisible ints and adaptive
433+ # arrays are legal.
434+ with pytest .raises (aa .exc .DatasetException ):
435+ aa .Imaging (
436+ data = data ,
437+ noise_map = noise_map ,
438+ psf = psf ,
439+ over_sample_size_lp = 3 ,
440+ convolve_over_sample_size_lp = 2 ,
441+ )
442+
443+ sub_size_adaptive = np .full (fill_value = 2 , shape = data .shape_slim )
444+ sub_size_adaptive [0 ] = 4
445+
446+ dataset_adaptive = aa .Imaging (
447+ data = data ,
448+ noise_map = noise_map ,
449+ psf = psf ,
450+ over_sample_size_lp = aa .Array2D (values = sub_size_adaptive , mask = data .mask ),
451+ convolve_over_sample_size_lp = 2 ,
452+ )
453+ assert dataset_adaptive .convolve_over_sample_size_lp == 2
454+
455+ sub_size_bad = np .full (fill_value = 2 , shape = data .shape_slim )
456+ sub_size_bad [0 ] = 3
457+
458+ with pytest .raises (aa .exc .DatasetException ):
459+ aa .Imaging (
460+ data = data ,
461+ noise_map = noise_map ,
462+ psf = psf ,
463+ over_sample_size_lp = aa .Array2D (values = sub_size_bad , mask = data .mask ),
464+ convolve_over_sample_size_lp = 2 ,
465+ )
466+
467+ # Differing lp / pixelization convolve sizes are not supported (single PSF kernel).
468+ with pytest .raises (aa .exc .DatasetException ):
469+ aa .Imaging (
470+ data = data ,
471+ noise_map = noise_map ,
472+ psf = psf ,
473+ over_sample_size_lp = 2 ,
474+ over_sample_size_pixelization = 4 ,
475+ convolve_over_sample_size_lp = 2 ,
476+ convolve_over_sample_size_pixelization = 4 ,
477+ )
478+
479+ # Valid dataset: the psf carries the convolve size and apply_mask preserves it,
480+ # precomputing the fine state and building the blurring grid at the fine resolution.
481+ dataset = aa .Imaging (
482+ data = data ,
483+ noise_map = noise_map ,
484+ psf = psf ,
485+ over_sample_size_lp = 2 ,
486+ convolve_over_sample_size_lp = 2 ,
487+ )
488+
489+ assert dataset .convolve_over_sample_size_lp == 2
490+ assert dataset .psf .convolve_over_sample_size == 2
491+
492+ mask = aa .Mask2D .circular (shape_native = (11 , 11 ), pixel_scales = 1.0 , radius = 3.5 )
493+ masked = dataset .apply_mask (mask = mask )
494+
495+ assert masked .convolve_over_sample_size_lp == 2
496+ assert masked .psf .convolve_over_sample_size == 2
497+ assert masked .psf ._state is not None
498+ assert masked .psf ._state .sub_slim_to_fine_slim is not None
499+
500+ # The blurring grid footprint uses the kernel's image-resolution shape (5x5 for a
501+ # 9x9 fine kernel at s=2) and is evaluated at the fine resolution.
502+ blurring_mask = mask .derive_mask .blurring_from (
503+ kernel_shape_native = (5 , 5 ), allow_padding = True
504+ )
505+ assert np .array (masked .grids .blurring .over_sampled ).shape == (
506+ blurring_mask .pixels_in_mask * 4 ,
507+ 2 ,
508+ )
509+
510+
511+ def test__convolve_over_sample_size__sparse_operator_guard ():
512+ data = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
513+ noise_map = aa .Array2D .no_mask (values = np .ones ((11 , 11 )), pixel_scales = 1.0 )
514+ kernel_fine = aa .Array2D .no_mask (values = np .ones ((9 , 9 )), pixel_scales = 0.5 )
515+ psf = aa .Convolver (kernel = kernel_fine )
516+
517+ dataset = aa .Imaging (
518+ data = data ,
519+ noise_map = noise_map ,
520+ psf = psf ,
521+ over_sample_size_pixelization = 2 ,
522+ convolve_over_sample_size_pixelization = 2 ,
523+ )
524+
525+ with pytest .raises (aa .exc .DatasetException ):
526+ dataset .apply_sparse_operator ()
0 commit comments