Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix for 821: test spectral smooth on windows #823

Merged
merged 5 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spectral_cube/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from astropy.utils import data

try:
from distributed.utils_test import client, loop, cluster_fixture # noqa
from distributed.utils_test import client, loop, cluster_fixture, cleanup # noqa
DISTRIBUTED_INSTALLED = True
except ImportError:
DISTRIBUTED_INSTALLED = False
Expand Down
47 changes: 32 additions & 15 deletions spectral_cube/tests/test_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,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):
Expand All @@ -165,19 +183,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
Expand All @@ -187,12 +205,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)


Expand Down