From: Ole Streicher <olebole@debian.org>
Date: Wed, 4 Jan 2023 10:33:50 +0100
Subject: Update test_kernel_smooth to latest github version

Closes: #1026720, #1027396
---
 spectral_cube/tests/test_regrid.py | 47 ++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/spectral_cube/tests/test_regrid.py b/spectral_cube/tests/test_regrid.py
index d832cd8..46d369f 100644
--- a/spectral_cube/tests/test_regrid.py
+++ b/spectral_cube/tests/test_regrid.py
@@ -126,18 +126,36 @@ def test_spectral_smooth(data_522_delta, use_dask):
 
     cube, data = cube_and_raw(data_522_delta, use_dask=use_dask)
 
-    result = cube.spectral_smooth(kernel=convolution.Gaussian1DKernel(1.0), use_memmap=False)
+    kernel = convolution.Gaussian1DKernel(1.0)
+
+    result = cube.spectral_smooth(kernel=kernel, use_memmap=False)
+
+    # check that all values come out right from the cube creation
+    np.testing.assert_almost_equal(cube[2,:,:].value, 1.0)
+    np.testing.assert_almost_equal(cube.unitless_filled_data[:2,:,:], 0.0)
+    np.testing.assert_almost_equal(cube.unitless_filled_data[3:,:,:], 0.0)
+
+    # make sure the kernel comes out right; the convolution test will fail if this is wrong
+    assert kernel.array.size == 9
+    # this was the old astropy normalization
+    # We don't actually need the kernel to match these values, but I'm leaving this here
+    # as a note for future us:
+    # https://github.com/astropy/astropy/pull/13299
+    # the error came about because we were using two different kernel sizes, which resulted in
+    # two different normalizations after the correction in 13299
+    # Before 13299, normalization was not guaranteed.
+    #np.testing.assert_almost_equal(kernel.array[2:-2],
+    #                               np.array([0.05399097, 0.24197072, 0.39894228, 0.24197072, 0.05399097]))
 
     np.testing.assert_almost_equal(result[:,0,0].value,
-                                   convolution.Gaussian1DKernel(1.0,
-                                                                x_size=5).array,
+                                   kernel.array[2:-2],
                                    4)
 
-    result = cube.spectral_smooth(kernel=convolution.Gaussian1DKernel(1.0), use_memmap=True)
+    # second test with memmap=True
+    result = cube.spectral_smooth(kernel=kernel, use_memmap=True)
 
     np.testing.assert_almost_equal(result[:,0,0].value,
-                                   convolution.Gaussian1DKernel(1.0,
-                                                                x_size=5).array,
+                                   kernel.array[2:-2],
                                    4)
 
 def test_catch_kernel_with_units(data_522_delta, use_dask):
@@ -158,19 +176,19 @@ def test_spectral_smooth_4cores(data_522_delta):
 
     cube, data = cube_and_raw(data_522_delta, use_dask=False)
 
-    result = cube.spectral_smooth(kernel=convolution.Gaussian1DKernel(1.0), num_cores=4, use_memmap=True)
+    kernel = convolution.Gaussian1DKernel(1.0)
+    result = cube.spectral_smooth(kernel=kernel, num_cores=4, use_memmap=True)
 
+    assert kernel.array.size == 9
     np.testing.assert_almost_equal(result[:,0,0].value,
-                                   convolution.Gaussian1DKernel(1.0,
-                                                                x_size=5).array,
+                                   kernel.array[2:-2],
                                    4)
 
     # this is one way to test non-parallel mode
-    result = cube.spectral_smooth(kernel=convolution.Gaussian1DKernel(1.0), num_cores=4, use_memmap=False)
+    result = cube.spectral_smooth(kernel=kernel, num_cores=4, use_memmap=False)
 
     np.testing.assert_almost_equal(result[:,0,0].value,
-                                   convolution.Gaussian1DKernel(1.0,
-                                                                x_size=5).array,
+                                   kernel.array[2:-2],
                                    4)
 
     # num_cores = 4 is a contradiction with parallel=False, so we want to make
@@ -180,12 +198,11 @@ def test_spectral_smooth_4cores(data_522_delta):
                                  "multiple cores were: these are incompatible "
                                  "options.  Either specify num_cores=1 or "
                                  "parallel=True")):
-        result = cube.spectral_smooth(kernel=convolution.Gaussian1DKernel(1.0),
+        result = cube.spectral_smooth(kernel=kernel,
                                       num_cores=4, parallel=False)
 
     np.testing.assert_almost_equal(result[:,0,0].value,
-                                   convolution.Gaussian1DKernel(1.0,
-                                                                x_size=5).array,
+                                   kernel.array[2:-2],
                                    4)
 
 
