Skip to content

Commit

Permalink
Merge pull request #66 from keflavich/issue66
Browse files Browse the repository at this point in the history
check_endian code in _get_filled_data is buggy
  • Loading branch information
keflavich committed Aug 27, 2014
2 parents 4463179 + cd936b7 commit 049005f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
- ASTROPY_VERSION=stable
- CONDA_INSTALL='conda install -c astropy-ci-extras --yes'
- PIP_INSTALL='pip install'
- BOTTLENECK=no
matrix:
- SETUP_CMD='egg_info'

Expand All @@ -34,7 +35,7 @@ matrix:
# Try Astropy development version
- python: 2.7
env: ASTROPY_VERSION=development SETUP_CMD='test'
- python: 3.3
- python: 3.4
env: ASTROPY_VERSION=development SETUP_CMD='test'

# Try all python versions with the latest numpy
Expand All @@ -59,6 +60,12 @@ matrix:
- python: 2.7
env: NUMPY_VERSION=1.5 SETUP_CMD='test'

# Test with bottleneck
- python: 2.7
env: ASTROPY_VERSION=stable SETUP_CMD='test' bottleneck=yes NUMPY_VERSION=1.8
- python: 3.4
env: ASTROPY_VERSION=stable SETUP_CMD='test' bottleneck=yes NUMPY_VERSION=1.8

before_install:

# Use utf8 encoding. Should be default, but this is insurance against
Expand Down Expand Up @@ -90,6 +97,10 @@ install:
# YT
- if [[ $SETUP_CMD != egg_info ]] && [[ $TRAVIS_PYTHON_VERSION == 2.7 ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL numpy=$NUMPY_VERSION yt; fi

# Bottleneck
# asmeurer currently (8/26/2014) supports numpy 1.8
- if [[ $SETUP_CMD != egg_info ]] && [[ $BOTTLENECK == yes ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL --channel https://conda.binstar.org/asmeurer bottleneck; fi

# OPTIONAL DEPENDENCIES
# Here you can add any dependencies your package may have. You can use
# conda for packages available through conda, or pip for any other
Expand Down
4 changes: 3 additions & 1 deletion spectral_cube/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ def median(self, axis=None, **kwargs):
projection=True,
check_endian=True, **kwargs)
except ImportError:
return self.apply_function(np.median, axis=axis, **kwargs)
result = self.apply_function(np.median, axis=axis, **kwargs)

return result

def percentile(self, q, axis=None, **kwargs):
"""
Expand Down
40 changes: 40 additions & 0 deletions spectral_cube/tests/test_spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
yt_version = StrictVersion('0.0.0')
ytOK = False

try:
import bottleneck
bottleneckOK = True
except ImportError:
bottleneckOK = False


def cube_and_raw(filename):
p = path(filename)
Expand Down Expand Up @@ -475,3 +481,37 @@ def test_ds9region():

#region = 'circle(2,2,2)'
#subcube = cube.subcube_from_ds9region(region)

@pytest.mark.skipif(not bottleneckOK, reason='Bottleneck could not be imported')
def test_endians():
"""
Test that the endianness checking returns something in Native form
(this is only needed for non-numpy functions that worry about the
endianness of their data)
WARNING: Because the endianness is machine-dependent, this may fail on
different architectures! This is because numpy automatically converts
little-endian to native in the dtype parameter; I need a workaround for
this.
"""
big = np.array([[[1],[2]]], dtype='>f4')
lil = np.array([[[1],[2]]], dtype='<f4')
mywcs = WCS(naxis=3)
mywcs.wcs.ctype[0] = 'RA'
mywcs.wcs.ctype[1] = 'DEC'
mywcs.wcs.ctype[2] = 'VELO'

bigcube = SpectralCube(data=big, wcs=mywcs)
xbig = bigcube._get_filled_data(check_endian=True)

lilcube = SpectralCube(data=lil, wcs=mywcs)
xlil = lilcube._get_filled_data(check_endian=True)

assert xbig.dtype.byteorder == '='
assert xlil.dtype.byteorder == '='

xbig = bigcube._get_filled_data(check_endian=False)
xlil = lilcube._get_filled_data(check_endian=False)

assert xbig.dtype.byteorder == '>'
assert xlil.dtype.byteorder == '='

0 comments on commit 049005f

Please sign in to comment.