@@ -292,11 +292,10 @@ def test__from_as_gaussian_via_alma_fits_header_parameters__identical_to_astropy
292292 assert kernel_astropy == pytest .approx (kernel_2d .native ._array , abs = 1e-4 )
293293
294294
295- def test__convolved_array_from__not_odd_x_odd_kernel__raises_error ():
296- kernel_2d = aa .Kernel2D .no_mask (values = [[0.0 , 1.0 ], [1.0 , 2.0 ]], pixel_scales = 1.0 )
295+ def test__not_odd_x_odd_kernel__raises_error ():
297296
298297 with pytest .raises (exc .KernelException ):
299- kernel_2d . convolved_array_from ( np . ones (( 5 , 5 )) )
298+ aa . Kernel2D . no_mask ( values = [[ 0.0 , 1.0 ], [ 1.0 , 2.0 ]], pixel_scales = 1.0 )
300299
301300
302301def test__convolved_array_from ():
@@ -358,34 +357,78 @@ def test__convolved_array_from():
358357 ).all ()
359358
360359
361- def test__convolved_array_from__input_jax_array ():
360+ def test__convolve_image ():
362361
363- array_2d = jnp .array (
364- [
365- [0.0 , 0.0 , 0.0 , 0.0 ],
366- [1.0 , 0.0 , 0.0 , 0.0 ],
367- [0.0 , 0.0 , 0.0 , 1.0 ],
368- [0.0 , 0.0 , 0.0 , 0.0 ],
369- ])
362+ mask = aa .Mask2D .circular (
363+ shape_native = (30 , 30 ), pixel_scales = (1.0 , 1.0 ), radius = 4.0
364+ )
370365
371- kernel_2d = aa .Kernel2D .no_mask (
372- values = [[1.0 , 1.0 , 1.0 ], [2.0 , 2.0 , 1.0 ], [1.0 , 3.0 , 3.0 ]], pixel_scales = 1.0
366+ import scipy .signal
367+
368+ kernel = np .arange (49 ).reshape (7 , 7 )
369+ image = np .arange (900 ).reshape (30 , 30 )
370+
371+ blurred_image_via_scipy = scipy .signal .convolve2d (
372+ image , kernel , mode = "same"
373+ )
374+ blurred_image_via_scipy = aa .Array2D .no_mask (
375+ values = blurred_image_via_scipy , pixel_scales = 1.0
376+ )
377+ blurred_masked_image_via_scipy = aa .Array2D (
378+ values = blurred_image_via_scipy .native , mask = mask
373379 )
374380
375- blurred_array_2d = kernel_2d . convolved_array_from ( array_2d )
381+ # Now reproduce this data using the convolve_image function
376382
377- assert (
378- blurred_array_2d .native
379- == np .array (
380- [
381- [1.0 , 1.0 , 0.0 , 0.0 ],
382- [2.0 , 1.0 , 1.0 , 1.0 ],
383- [3.0 , 3.0 , 2.0 , 2.0 ],
384- [0.0 , 0.0 , 1.0 , 3.0 ],
385- ]
386- )
387- ).all ()
383+ image = aa .Array2D .no_mask (values = np .arange (900 ).reshape (30 , 30 ), pixel_scales = 1.0 )
384+ kernel = aa .Kernel2D .no_mask (values = np .arange (49 ).reshape (7 , 7 ), pixel_scales = 1.0 )
385+
386+ masked_image = aa .Array2D (values = image .native , mask = mask )
387+
388+ blurring_mask = mask .derive_mask .blurring_from (
389+ kernel_shape_native = kernel .shape_native
390+ )
391+
392+ blurring_image = aa .Array2D (values = image .native , mask = blurring_mask )
393+
394+ blurred_masked_im_1 = kernel .convolve_image (
395+ image = masked_image , blurring_image = blurring_image
396+ )
397+
398+ assert blurred_masked_image_via_scipy == pytest .approx (blurred_masked_im_1 .array , 1e-4 )
399+
400+
401+ def test__compare_to_full_2d_convolution__no_blurring_image ():
402+ # Setup a blurred data, using the PSF to perform the convolution in 2D, then masks it to make a 1d array.
403+
404+ import scipy .signal
405+
406+ mask = aa .Mask2D .circular (
407+ shape_native = (30 , 30 ), pixel_scales = (1.0 , 1.0 ), radius = 4.0
408+ )
409+ kernel = aa .Kernel2D .no_mask (values = np .arange (49 ).reshape (7 , 7 ), pixel_scales = 1.0 )
410+ image = aa .Array2D .no_mask (values = np .arange (900 ).reshape (30 , 30 ), pixel_scales = 1.0 )
411+
412+ blurring_mask = mask .derive_mask .blurring_from (
413+ kernel_shape_native = kernel .shape_native
414+ )
415+ blurred_image_via_scipy = scipy .signal .convolve2d (
416+ image .native * blurring_mask , kernel .native , mode = "same"
417+ )
418+ blurred_image_via_scipy = aa .Array2D .no_mask (
419+ values = blurred_image_via_scipy , pixel_scales = 1.0
420+ )
421+ blurred_masked_image_via_scipy = aa .Array2D (
422+ values = blurred_image_via_scipy .native , mask = mask
423+ )
424+
425+ # Now reproduce this data using the frame convolver_image
388426
427+ masked_image = aa .Array2D (values = image .native , mask = mask )
428+
429+ blurred_masked_im_1 = kernel .convolve_image_no_blurring (image = masked_image )
430+
431+ assert blurred_masked_image_via_scipy == pytest .approx (blurred_masked_im_1 , 1e-4 )
389432
390433
391434def test__convolve_mapping_matrix ():
@@ -509,80 +552,3 @@ def test__convolve_mapping_matrix():
509552 ),
510553 1e-4 ,
511554 )
512-
513-
514- def test__convolve_image ():
515-
516- mask = aa .Mask2D .circular (
517- shape_native = (30 , 30 ), pixel_scales = (1.0 , 1.0 ), radius = 4.0
518- )
519-
520- import scipy .signal
521-
522- kernel = np .arange (49 ).reshape (7 , 7 )
523- image = np .arange (900 ).reshape (30 , 30 )
524-
525- blurred_image_via_scipy = scipy .signal .convolve2d (
526- image , kernel , mode = "same"
527- )
528- blurred_image_via_scipy = aa .Array2D .no_mask (
529- values = blurred_image_via_scipy , pixel_scales = 1.0
530- )
531- blurred_masked_image_via_scipy = aa .Array2D (
532- values = blurred_image_via_scipy .native , mask = mask
533- )
534-
535- # Now reproduce this data using the convolve_image function
536-
537- image = aa .Array2D .no_mask (values = np .arange (900 ).reshape (30 , 30 ), pixel_scales = 1.0 )
538- kernel = aa .Kernel2D .no_mask (values = np .arange (49 ).reshape (7 , 7 ), pixel_scales = 1.0 )
539-
540- masked_image = aa .Array2D (values = image .native , mask = mask )
541-
542- blurring_mask = mask .derive_mask .blurring_from (
543- kernel_shape_native = kernel .shape_native
544- )
545-
546- blurring_image = aa .Array2D (values = image .native , mask = blurring_mask )
547-
548- blurred_masked_im_1 = kernel .convolve_image (
549- image = masked_image , blurring_image = blurring_image
550- )
551-
552- print (blurred_masked_image_via_scipy )
553- print (blurred_masked_im_1 )
554-
555- assert blurred_masked_image_via_scipy == pytest .approx (blurred_masked_im_1 .array , 1e-4 )
556-
557-
558- def test__compare_to_full_2d_convolution__no_blurring_image ():
559- # Setup a blurred data, using the PSF to perform the convolution in 2D, then masks it to make a 1d array.
560-
561- import scipy .signal
562-
563- mask = aa .Mask2D .circular (
564- shape_native = (30 , 30 ), pixel_scales = (1.0 , 1.0 ), radius = 4.0
565- )
566- kernel = aa .Kernel2D .no_mask (values = np .arange (49 ).reshape (7 , 7 ), pixel_scales = 1.0 )
567- image = aa .Array2D .no_mask (values = np .arange (900 ).reshape (30 , 30 ), pixel_scales = 1.0 )
568-
569- blurring_mask = mask .derive_mask .blurring_from (
570- kernel_shape_native = kernel .shape_native
571- )
572- blurred_image_via_scipy = scipy .signal .convolve2d (
573- image .native * blurring_mask , kernel .native , mode = "same"
574- )
575- blurred_image_via_scipy = aa .Array2D .no_mask (
576- values = blurred_image_via_scipy , pixel_scales = 1.0
577- )
578- blurred_masked_image_via_scipy = aa .Array2D (
579- values = blurred_image_via_scipy .native , mask = mask
580- )
581-
582- # Now reproduce this data using the frame convolver_image
583-
584- masked_image = aa .Array2D (values = image .native , mask = mask )
585-
586- blurred_masked_im_1 = kernel .convolve_image_no_blurring (image = masked_image )
587-
588- assert blurred_masked_image_via_scipy == pytest .approx (blurred_masked_im_1 , 1e-4 )
0 commit comments