Skip to content

Commit

Permalink
Merge pull request #257 from e-koch/jy_beam_strip_space
Browse files Browse the repository at this point in the history
Strip whitespace from BUNIT
  • Loading branch information
e-koch committed Dec 23, 2015
2 parents 33f341f + 481b424 commit 5e4b4f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion spectral_cube/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from functools import wraps
import operator
import sys
import re

from astropy import units as u
from astropy.extern import six
Expand Down Expand Up @@ -124,7 +125,8 @@ def __init__(self, data, wcs, mask=None, meta=None, fill_value=np.nan,
if 'BUNIT' in self._meta:

# special case: CASA (sometimes) makes non-FITS-compliant jy/beam headers
if self._meta['BUNIT'].lower() == 'jy/beam':
bunit = re.sub("\s", "", self._meta['BUNIT'].lower())
if bunit == 'jy/beam':
self._unit = u.Jy

if not read_beam:
Expand Down
2 changes: 2 additions & 0 deletions spectral_cube/tests/data/make_test_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ def transpose(d, h, axes):
fits.writeto('vda_JYBEAM_upper.fits', d, h, clobber=True)
h['BUNIT'] = 'Jy/beam'
fits.writeto('vda_Jybeam_lower.fits', d, h, clobber=True)
h['BUNIT'] = ' Jy / beam '
fits.writeto('vda_Jybeam_whitespace.fits', d, h, clobber=True)
15 changes: 13 additions & 2 deletions spectral_cube/tests/test_spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def test_bad_median_apply(self):
# from the cube.median method that does "the right thing"
#
# for regular median, we expect a failure, which is why we don't use
# regular median.
# regular median.

scmed = self.c.apply_numpy_function(np.median, axis=0)
if StrictVersion(np.__version__) <= StrictVersion('1.9.3'):
Expand Down Expand Up @@ -1022,7 +1022,18 @@ def test_jybeam_lower():
assert hasattr(cube, 'beam')
np.testing.assert_almost_equal(cube.beam.sr.value,
(((1*u.arcsec/np.sqrt(8*np.log(2)))**2).to(u.sr)*2*np.pi).value)


# Regression test for #257 (https://github.com/radio-astro-tools/spectral-cube/pull/257)
def test_jybeam_whitespace():

cube, data = cube_and_raw('vda_Jybeam_whitespace.fits')

assert cube.unit == u.Jy
if RADIO_BEAM_INSTALLED:
assert hasattr(cube, 'beam')
np.testing.assert_almost_equal(cube.beam.sr.value,
(((1*u.arcsec/np.sqrt(8*np.log(2)))**2).to(u.sr)*2*np.pi).value)

@pytest.mark.skipif("not RADIO_BEAM_INSTALLED")
def test_beam_proj_meta():

Expand Down

0 comments on commit 5e4b4f1

Please sign in to comment.