Skip to content

Commit

Permalink
Merge branch 'master' of github.com:radio-astro-tools/spectral-cube
Browse files Browse the repository at this point in the history
Conflicts:
	spectral_cube/spectral_cube.py
  • Loading branch information
keflavich committed Dec 29, 2015
2 parents b25ccb9 + 5e4b4f1 commit a70b3ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 10 additions & 5 deletions 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 Expand Up @@ -1166,10 +1168,13 @@ def with_spectral_unit(self, unit, velocity_convention=None,
newwcs = convert_spectral_axis(self._wcs, unit, out_ctype,
rest_value=rest_value)

newmask = self._mask.with_spectral_unit(unit,
velocity_convention=vc,
rest_value=rest_value)
newmask._wcs = newwcs
if self._mask is not None:
newmask = self._mask.with_spectral_unit(unit,
velocity_convention=vc,
rest_value=rest_value)
newmask._wcs = newwcs
else:
newmask = None

newwcs.wcs.set()
cube = self._new_cube_with(wcs=newwcs, mask=newmask, meta=meta,
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 a70b3ec

Please sign in to comment.