radio-astro-tools/spectral-cube — pull request #88 by keflavich (2014-05-07 07:21:19+00:00)
Title: ``with_spectral_unit`` does not change mask WCS 

The following example:

```
rest_value = 220394425324.67532 * u.Hz

s = SpectralCube.read('HD163296_13CO.image.fits', format='fits')

s2 = s.spectral_slab(-2 * u.km / u.s, 2 * u.km / u.s,
rest_frequency=rest_value)

s3 = s2.with_spectral_unit(u.km / u.s, rest_value=rest_value,
velocity_convention=u.doppler_radio)

moment_map = s3.moment(order=1)
```

leads to the following exception:

```
Traceback (most recent call last):
File "test_latest.py", line 22, in
moment_map = s3.moment(order=1)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/spectral_cube.py", line 798, in moment
out = dispatch[how](self, order, axis)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/_moments.py", line 187, in moment_auto
return strategy[iterator_strategy(cube, axis)](cube, order, axis)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/_moments.py", line 161, in moment_cubewise
data = cube._get_filled_data() * cube._pix_size()[axis]
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/spectral_cube.py", line 596, in _get_filled_data
view=view)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/masks.py", line 97, in _filled
ex = self.exclude(data=data, wcs=wcs, view=view)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/masks.py", line 45, in exclude
self._validate_wcs(data, wcs)
File "/Users/tom/Desktop/ALMA Python Workshop/radio_cube/spectral-cube/spectral_cube/masks.py", line 236, in _validate_wcs
raise ValueError("WCS does not match mask WCS")
ValueError: WCS does not match mask WCS
```

I think the WCS of the masks should be changed to the requested velocity convention.

This actually makes me wonder, maybe we should always require masks to have WCS that is in the same convention as the data's WCS? Otherwise, if one specifies a mask in velocity and the data has a frequency axis, then when doing e.g. ``cube.data_filled`` the mask cannot be applied to the data without rest frequency information.

Any thoughts on this @ChrisBeaumont @keflavich @low-sky?