diff --git a/.travis.yml b/.travis.yml index 31962e638..49f8aac35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,29 +23,16 @@ env: matrix: include: - - python: 3.7 - env: TOXENV='py37-test' - name: "Python 3.7 with minimal dependencies" + - language: c + os: osx + env: PYTHON_VERSION=3.7 TOXENV='py37-test-all' + name: "Python 3.7 with all dependencies (except CASA) on MacOS X" - - python: 3.7 - env: TOXENV='py37-test-all' - name: "Python 3.7 with all dependencies (except CASA)" + - language: c + os: windows + env: PYTHON_VERSION=3.7 TOXENV='py37-test-all' + name: "Python 3.7 with all dependencies (except CASA) on Windows" - - python: 3.6 - env: TOXENV='py36-test-casa' - name: "Python 3.6 with minimal dependencies and CASA" - - - python: 3.6 - env: TOXENV='py36-test-casa-dev' - name: "Python 3.6, CASA, and dev versions of key dependencies" - - - python: 3.8 - env: TOXENV='py38-test-all-dev' - name: "Python 3.8, all dependencies, and dev versions of key dependencies" - - - python: 3.8 - env: TOXENV='build_docs' - name: "Documentation" before_install: # We need a full clone to make sure setuptools_scm @@ -53,8 +40,19 @@ before_install: - git fetch --unshallow . - git fetch --depth=1000000 - - export DISPLAY=:99.0 - - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1920x1200x24 -ac +extension GLX +render -noreset + - if [[ $TRAVIS_OS_NAME == linux ]]; then + export DISPLAY=:99.0; + /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1920x1200x24 -ac +extension GLX +render -noreset; + fi + +install: + # language: python is only available for Linux, so for other platforms + # we need to use ci-helpers to set up Python. + - if [[ $TRAVIS_OS_NAME == osx || $TRAVIS_OS_NAME == windows ]]; then + git clone git://github.com/astropy/ci-helpers.git; + source ci-helpers/travis/setup_conda.sh; + fi + script: - pip install tox diff --git a/spectral_cube/io/tests/test_casa_wcs.py b/spectral_cube/io/tests/test_casa_wcs.py index 380a6ec57..34c0976c0 100644 --- a/spectral_cube/io/tests/test_casa_wcs.py +++ b/spectral_cube/io/tests/test_casa_wcs.py @@ -90,6 +90,7 @@ def header_copy_with(**kwargs): ALL_HEADERS = [ + header_copy_with(), header_copy_with(CTYPE1='GLON-TAN', CTYPE2='GLAT-TAN'), header_copy_with(CTYPE1='SLON-TAN', CTYPE2='SLAT-TAN'), header_copy_with(CTYPE1='ELON-TAN', CTYPE2='ELAT-TAN'), diff --git a/spectral_cube/spectral_cube.py b/spectral_cube/spectral_cube.py index 1726a66de..f3a81c17c 100644 --- a/spectral_cube/spectral_cube.py +++ b/spectral_cube/spectral_cube.py @@ -15,6 +15,7 @@ from pathlib import PosixPath import six from six.moves import zip, range +import dask.array import astropy.wcs from astropy import units as u @@ -1315,7 +1316,11 @@ def unmasked_data(self, view): data : Quantity instance The unmasked data """ - return u.Quantity(self._data[view], self.unit, copy=False) + values = self._data[view] + # Astropy Quantities don't play well with dask arrays with shape () + if isinstance(values, dask.array.core.Array) and values.shape == (): + values = values.compute() + return u.Quantity(values, self.unit, copy=False) def unmasked_copy(self): """ diff --git a/spectral_cube/tests/data/basic.image/logtable/table.dat b/spectral_cube/tests/data/basic.image/logtable/table.dat new file mode 100644 index 000000000..26a18b65d Binary files /dev/null and b/spectral_cube/tests/data/basic.image/logtable/table.dat differ diff --git a/spectral_cube/tests/data/basic.image/logtable/table.f0 b/spectral_cube/tests/data/basic.image/logtable/table.f0 new file mode 100644 index 000000000..d32529b77 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/logtable/table.f0 differ diff --git a/spectral_cube/tests/data/basic.image/logtable/table.info b/spectral_cube/tests/data/basic.image/logtable/table.info new file mode 100644 index 000000000..dfeff77ec --- /dev/null +++ b/spectral_cube/tests/data/basic.image/logtable/table.info @@ -0,0 +1,4 @@ +Type = Log message +SubType = + +Repository for software-generated logging messages diff --git a/spectral_cube/tests/data/basic.image/logtable/table.lock b/spectral_cube/tests/data/basic.image/logtable/table.lock new file mode 100644 index 000000000..9d46a6b56 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/logtable/table.lock differ diff --git a/spectral_cube/tests/data/basic.image/mask0/table.dat b/spectral_cube/tests/data/basic.image/mask0/table.dat new file mode 100644 index 000000000..4e94b635c Binary files /dev/null and b/spectral_cube/tests/data/basic.image/mask0/table.dat differ diff --git a/spectral_cube/tests/data/basic.image/mask0/table.f0 b/spectral_cube/tests/data/basic.image/mask0/table.f0 new file mode 100644 index 000000000..944ae2f7c Binary files /dev/null and b/spectral_cube/tests/data/basic.image/mask0/table.f0 differ diff --git a/spectral_cube/tests/data/basic.image/mask0/table.f0_TSM0 b/spectral_cube/tests/data/basic.image/mask0/table.f0_TSM0 new file mode 100644 index 000000000..0c53fce8e --- /dev/null +++ b/spectral_cube/tests/data/basic.image/mask0/table.f0_TSM0 @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/spectral_cube/tests/data/basic.image/mask0/table.info b/spectral_cube/tests/data/basic.image/mask0/table.info new file mode 100644 index 000000000..a0c62c858 --- /dev/null +++ b/spectral_cube/tests/data/basic.image/mask0/table.info @@ -0,0 +1,3 @@ +Type = Paged Array +SubType = + diff --git a/spectral_cube/tests/data/basic.image/mask0/table.lock b/spectral_cube/tests/data/basic.image/mask0/table.lock new file mode 100644 index 000000000..8d83ce8a7 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/mask0/table.lock differ diff --git a/spectral_cube/tests/data/basic.image/table.dat b/spectral_cube/tests/data/basic.image/table.dat new file mode 100644 index 000000000..14d151f32 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/table.dat differ diff --git a/spectral_cube/tests/data/basic.image/table.f0 b/spectral_cube/tests/data/basic.image/table.f0 new file mode 100644 index 000000000..fb7f0dbd9 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/table.f0 differ diff --git a/spectral_cube/tests/data/basic.image/table.f0_TSM0 b/spectral_cube/tests/data/basic.image/table.f0_TSM0 new file mode 100644 index 000000000..2b61b064c Binary files /dev/null and b/spectral_cube/tests/data/basic.image/table.f0_TSM0 differ diff --git a/spectral_cube/tests/data/basic.image/table.info b/spectral_cube/tests/data/basic.image/table.info new file mode 100644 index 000000000..cbab78e3a --- /dev/null +++ b/spectral_cube/tests/data/basic.image/table.info @@ -0,0 +1,3 @@ +Type = Image +SubType = + diff --git a/spectral_cube/tests/data/basic.image/table.lock b/spectral_cube/tests/data/basic.image/table.lock new file mode 100644 index 000000000..8d83ce8a7 Binary files /dev/null and b/spectral_cube/tests/data/basic.image/table.lock differ diff --git a/spectral_cube/tests/test_casafuncs.py b/spectral_cube/tests/test_casafuncs.py index b0987052d..afe684d3e 100644 --- a/spectral_cube/tests/test_casafuncs.py +++ b/spectral_cube/tests/test_casafuncs.py @@ -6,6 +6,7 @@ import pytest import numpy as np from numpy.testing import assert_allclose +from astropy.tests.helper import assert_quantity_allclose from astropy import units as u @@ -24,6 +25,8 @@ except ImportError: CASA_INSTALLED = False +DATA = os.path.join(os.path.dirname(__file__), 'data') + def make_casa_testimage(infile, outname): @@ -69,6 +72,29 @@ def filename(request): return request.getfixturevalue(request.param) +def test_casa_read_basic(): + + # Check that SpectralCube.read works for an example CASA dataset stored + # in the tests directory. This test should NOT require CASA, whereas a + # number of tests below require CASA to generate test datasets. The present + # test is to ensure CASA is not required for reading. + + cube = SpectralCube.read(os.path.join(DATA, 'basic.image')) + assert cube.shape == (3, 4, 5) + assert_allclose(cube.wcs.pixel_to_world_values(1, 2, 3), + [2.406271e+01, 2.993521e+01, 1.421911e+09]) + + # Carry out an operation to make sure the underlying data array works + + cube.moment0() + + # Slice the dataset + + assert_quantity_allclose(cube.unmasked_data[0, 0, :], + [1, 1, 1, 1, 1] * u.Jy / u.beam) + assert_quantity_allclose(cube.unmasked_data[0, 1, 2], 1 * u.Jy / u.beam) + + @pytest.mark.skipif(not CASA_INSTALLED, reason='CASA tests must be run in a CASA environment.') @pytest.mark.parametrize('filename', ('data_adv', 'data_advs', 'data_sdav', 'data_vad', 'data_vsad'), diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py index 3c56bc44b..dde4acaa0 100644 --- a/spectral_cube/tests/test_spectral_cube.py +++ b/spectral_cube/tests/test_spectral_cube.py @@ -44,6 +44,7 @@ except ImportError: casaOK = False +WINDOWS = sys.platform == 'win32' # needed to test for warnings later warnings.simplefilter('always', UserWarning) @@ -2072,6 +2073,7 @@ def update_function(): print("Update Function Call") +@pytest.mark.skipif('WINDOWS') def test_smooth_update_function_parallel(capsys, data_adv): pytest.importorskip('joblib') diff --git a/tox.ini b/tox.ini index 7479f58d7..5dcf582b3 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ extras = all: all commands = pip freeze - pytest --open-files --pyargs spectral_cube {toxinidir}/docs --cov spectral_cube --cov-config={toxinidir}/.coveragerc {posargs} + pytest -v --open-files --pyargs spectral_cube.io {toxinidir}/docs --cov spectral_cube --cov-config={toxinidir}/.coveragerc {posargs} [testenv:build_docs] changedir =