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

Expand test coverage #854

Merged
merged 5 commits into from
Mar 13, 2023
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
64 changes: 46 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,72 @@ jobs:
include:
- os: ubuntu-latest
python-version: 3.9
name: Python 3.9 with minimal dependencies
name: Py3.9 mindeps
toxenv: py39-test
- os: ubuntu-latest
python-version: '3.10'
name: Py3.10 mindeps
toxenv: py310-test
- os: ubuntu-latest
python-version: 3.11
name: Py3.11 mindeps
toxenv: py311-test
- os: ubuntu-latest
python-version: 3.9
name: Python 3.9 with no visualization + coverage
toxenv: py39-test-novis-cov
name: Py3.9 no visualization + coverage
toxenv: py39-test-noviz-cov
- os: ubuntu-latest
python-version: 3.8
name: Python 3.8 with minimal dependencies
name: Py3.8 mindeps
toxenv: py38-test
- os: ubuntu-latest
python-version: 3.7
name: Python 3.7 with minimal dependencies
toxenv: py37-test
python-version: 3.9
name: Py3.9 noviz
toxenv: py39-test-noviz
- os: ubuntu-latest
python-version: 3.9
name: Py3.9 all
toxenv: py39-test-viz-noviz-docs
- os: ubuntu-latest
python-version: 3.9
name: Python 3.9 with all non-visualization dependencies (except CASA)
toxenv: py39-test-novis
name: Py3.9 dev
toxenv: py39-test-dev
- os: ubuntu-latest
python-version: 3.9
name: Py3.9 viz
toxenv: py39-test-viz
#- os: ubuntu-latest
# python-version: 3.9
# name: Py3.9 viz w/yt & glue
# toxenv: py39-test-viz-viz_extra
- os: ubuntu-latest
python-version: 3.9
name: Py3.9 all dev
toxenv: py39-test-viz-noviz-docs-dev
- os: ubuntu-18.04
python-version: 3.8
name: Python 3.8 with minimal dependencies and CASA
name: Py3.8 mindeps and CASA
toxenv: py38-test-casa
- os: ubuntu-latest
python-version: 3.9
name: Python 3.9, all non-visualization dependencies, and dev versions of key dependencies
toxenv: py39-test-novis-dev
name: Py3.9, noviz, dev
toxenv: py39-test-noviz-dev
- os: ubuntu-latest
python-version: 3.8
name: Python 3.8 with all non-visualization dependencies (except CASA)
toxenv: py38-test-novis
name: Py3.8 noviz (except CASA)
toxenv: py38-test-noviz
- os: macos-latest
python-version: 3.9
name: Python 3.9 with all non-visualization dependencies (except CASA) on MacOS X
toxenv: py39-test-novis
name: Py3.9 noviz (except CASA) MacOS X
toxenv: py39-test-noviz
- os: windows-latest
python-version: 3.9
name: Py3.9, noviz Windows
toxenv: py39-test-noviz-dev
- os: windows-latest
python-version: 3.9
name: Python 3.9, all dependencies, and dev versions of key dependencies on Windows
toxenv: py39-test-all-dev-noopenfiles
name: Py3.9, noviz, dev; Windows
toxenv: py39-test-noviz-dev
- os: ubuntu-latest
python-version: 3.9
name: Documentation
Expand Down
34 changes: 18 additions & 16 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,39 @@ install_requires =
test =
pytest-astropy
pytest-cov
regions>=0.7
numpy>=1.24.0
astropy>=5.2.1
docs =
sphinx-astropy
matplotlib
novis =
noviz =
zarr
fsspec
distributed
pvextractor
regions>=0.3
reproject
reproject>=0.9.1
scipy
all =
pytest-astropy
pytest-cov
sphinx-astropy
zarr
fsspec
distributed
viz =
aplpy
glue-core[qt]
matplotlib
pvextractor
regions>=0.3
reproject
scipy
pvextractor
viz_extra =
glue-core[qt]
yt ; python_version<'3.8'
dev =
pvextractor @ git+https://github.com/radio-astro-tools/pvextractor#egg=pvextractor
radio-beam @ git+https://github.com/radio-astro-tools/radio-beam#egg=radio-beam
# installed by tox astropy @ git+https://github.com/astropy/astropy#egg=astropy
#reproject @ git+https://github.com/astropy/reproject#egg=reproject
reproject @ git+https://github.com/keflavich/python-reprojection.git@high_level_wcs#egg=reproject
keflavich marked this conversation as resolved.
Show resolved Hide resolved
regions @ git+https://github.com/astropy/regions#egg=regions

[options.package_data]
spectral_cube.tests =
data/*
data/*/*
data/*
data/*/*

spectral_cube.io.tests = data/*/*

Expand Down
5 changes: 5 additions & 0 deletions spectral_cube/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def meta(self):
def mask(self):
return self._mask

@mask.setter
keflavich marked this conversation as resolved.
Show resolved Hide resolved
def mask(self, value):
self._mask = value


class HeaderMixinClass(object):
"""
A mixin class to provide header updating from WCS objects.
Expand Down
11 changes: 9 additions & 2 deletions spectral_cube/lower_dimensional_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class LowerDimensionalObject(u.Quantity, BaseNDClass, HeaderMixinClass):
Generic class for 1D and 2D objects.
"""

def _new_view(self, obj=None, unit=None, finalize=True):
# FORCE finalization to hack around https://github.com/astropy/astropy/issues/14514#issuecomment-1463935711
try:
return super(LowerDimensionalObject, self)._new_view(obj=obj, unit=unit, finalize=True)
except TypeError:
return super(LowerDimensionalObject, self)._new_view(obj=obj, unit=unit)

@property
def hdu(self):
if self.wcs is None:
Expand Down Expand Up @@ -246,7 +253,7 @@ def __new__(cls, value, unit=None, dtype=None, copy=True, wcs=None,
raise ValueError("value should be a 2-d array")

if wcs is not None and wcs.wcs.naxis != 2:
raise ValueError("wcs should have two dimension")
raise ValueError("wcs should have two dimensions")

self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)
Expand Down Expand Up @@ -599,7 +606,7 @@ def __new__(cls, value, unit=None, dtype=None, copy=True, wcs=None,
raise ValueError("value should be a 1-d array")

if wcs is not None and wcs.wcs.naxis != 1:
raise ValueError("wcs should have two dimension")
raise ValueError("wcs should have one dimension")

self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)
Expand Down
2 changes: 2 additions & 0 deletions spectral_cube/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

try:
from distributed.utils_test import client, loop, cluster_fixture, cleanup, loop_in_thread # noqa
# zarr & fsspec required for writing to disk w/dask
import zarr, fsspec # noqa
DISTRIBUTED_INSTALLED = True
except ImportError:
DISTRIBUTED_INSTALLED = False
Expand Down
18 changes: 14 additions & 4 deletions spectral_cube/tests/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def test_isnan(LDO, data):
def test_self_arith(LDO, data):

image = data
p = LDO(image, copy=False)
p = LDO(image, copy=False, wcs=WCS(naxis=image.ndim))
assert hasattr(p, '_wcs')
assert p.wcs is not None

p2 = p + p

Expand All @@ -159,21 +161,26 @@ def test_self_arith_with_beam(LDO, data):
exp_beam = Beam(1.0 * u.arcsec)

image = data
p = LDO(image, copy=False)
p = LDO(image, copy=False, wcs=WCS(naxis=image.ndim))
p = p.with_beam(exp_beam)
assert hasattr(p, 'beam')
assert hasattr(p, '_wcs')
assert p.wcs is not None

p2 = p + p

assert hasattr(p2, '_wcs')
assert p2.wcs == p.wcs
assert np.all(p2.value==2)
assert hasattr(p2, 'beam')
assert p2.beam == exp_beam

p2 = p - p

assert hasattr(p2, '_wcs')
assert p2.wcs == p.wcs
assert np.all(p2.value==0)
assert hasattr(p2, 'beam')
assert p2.beam == exp_beam


Expand Down Expand Up @@ -743,8 +750,11 @@ def test_1d_slice_round(data_255_delta, use_dask):
assert hasattr(sp, '_fill_value')
assert hasattr(sp.round(), '_fill_value')

assert 'OneDSpectrum' in sp.round().__repr__()
assert 'OneDSpectrum' in sp[1:-1].round().__repr__()
rnd = sp.round()
assert 'OneDSpectrum' in rnd.__repr__()

rndslc = sp[1:-1].round()
assert 'OneDSpectrum' in rndslc.__repr__()


def test_LDO_arithmetic(data_vda, use_dask):
Expand Down
9 changes: 7 additions & 2 deletions spectral_cube/tests/test_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ def test_reproject(use_memmap, data_adv, use_dask):
result = cube.reproject(header_out, use_memmap=use_memmap)

assert result.shape == (cube.shape[0], 5, 4)

# empirically, this is how close we can get after https://github.com/astropy/astropy/pull/14508
tolerance = 1e-12

assert wcs_out.wcs.compare(WCS(header_out).wcs, tolerance=tolerance)
# Check WCS in reprojected matches wcs_out
assert wcs_out.wcs.compare(result.wcs.wcs)
assert wcs_out.wcs.compare(result.wcs.wcs, tolerance=tolerance)
# And that the headers have equivalent WCS info.
result_wcs_from_header = WCS(result.header)
assert result_wcs_from_header.wcs.compare(wcs_out.wcs)
assert result_wcs_from_header.wcs.compare(wcs_out.wcs, tolerance=tolerance)


def test_spectral_smooth(data_522_delta, use_dask):
Expand Down
5 changes: 3 additions & 2 deletions spectral_cube/tests/test_spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ def test_apply_everywhere_plusminus(self, operation, value, data_advs, use_dask)
((operator.div if hasattr(operator,'div') else operator.floordiv, 0.5*u.K),))
def test_apply_everywhere_floordivide(self, operation, value, data_advs, use_dask):
c1, d1 = cube_and_raw(data_advs, use_dask=use_dask)
# floordiv doesn't work, which is why it's NotImplemented
with pytest.raises(u.UnitConversionError):
try:
c1o = c1._apply_everywhere(operation, value)
except Exception as ex:
isinstance(ex, (NotImplementedError, TypeError, u.UnitConversionError))


@pytest.mark.parametrize(('filename', 'trans'), translist, indirect=['filename'])
Expand Down
31 changes: 13 additions & 18 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39}-test{,-all,-dev,-novis,-cov,-noopenfiles}
py{38,39,310,311}-test{,-dev,-noviz,-viz,-viz_extra,-cov,-noopenfiles}
build_docs
codestyle
requires =
Expand All @@ -10,34 +10,29 @@ set_env =
casa: PIP_EXTRA_INDEX_URL = {env:PIP_EXTRA_INDEX_URL:https://casa-pip.nrao.edu/repository/pypi-group/simple}

[testenv]
passenv =
HOME
DISPLAY
LC_ALL
LC_CTYPE
changedir =
.tmp/{envname}
description =
run tests with pytest
passenv = HOME,DISPLAY,LC_ALL,LC_CTYPE,ON_TRAVIS
changedir = .tmp/{envname}
description = run tests with pytest
deps =
dev: git+https://github.com/radio-astro-tools/pvextractor#egg=pvextractor
dev: git+https://github.com/radio-astro-tools/radio-beam#egg=radio-beam
dev: git+https://github.com/astropy/astropy#egg=astropy
dev: git+https://github.com/astropy/reproject#egg=reproject
dev: git+https://github.com/astropy/regions#egg=regions
casa: numpy
casa: scipy
casa: matplotlib
casa: casatools
casa: casatasks
extras =
test
all: all
dev: dev
viz: viz
viz_extra: viz_extra
noviz: noviz
cov: cov
latest: latest
commands =
dev: pip install -U -i https://pypi.anaconda.org/astropy/simple astropy --pre
pip freeze
!cov-!noopenfiles: pytest --open-files --pyargs spectral_cube {toxinidir}/docs {posargs}
!cov-!noopenfiles: pytest --pyargs spectral_cube {toxinidir}/docs {posargs}
noopenfiles: pytest --pyargs spectral_cube {toxinidir}/docs {posargs}
cov: pytest --open-files --pyargs spectral_cube {toxinidir}/docs --cov spectral_cube --cov-config={toxinidir}/setup.cfg {posargs}
cov: pytest --pyargs spectral_cube {toxinidir}/docs --cov spectral_cube --cov-config={toxinidir}/setup.cfg {posargs}
cov: coverage xml -o {toxinidir}/coverage.xml

[testenv:build_docs]
Expand Down