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

Make SpectralCube operate more like a numpy array in some ways #230

Merged
merged 5 commits into from
Aug 15, 2015
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
4 changes: 2 additions & 2 deletions spectral_cube/io/fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def read_data_fits(input, hdu=None, **kwargs):
return array_hdu.data, array_hdu.header


def load_fits_cube(input, hdu=0, meta={}):
def load_fits_cube(input, hdu=0, meta={}, **kwargs):
"""
Read in a cube from a FITS file using astropy.

Expand All @@ -110,7 +110,7 @@ def load_fits_cube(input, hdu=0, meta={}):
Metadata (can be inherited from other readers, for example)
"""

data, header = read_data_fits(input, hdu=hdu)
data, header = read_data_fits(input, hdu=hdu, **kwargs)

if 'BUNIT' in header:
meta['BUNIT'] = header['BUNIT']
Expand Down
3 changes: 2 additions & 1 deletion spectral_cube/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def __invert__(self):
return InvertedMask(self)

def __getitem__(self):
raise NotImplementedError("Slicing not supported by mask class {0}".format(self.__class__.__name__))
raise NotImplementedError("Slicing not supported by mask class {0}"
.format(self.__class__.__name__))

def quicklook(self, view, wcs=None, filename=None, use_aplpy=True):
'''
Expand Down
7 changes: 6 additions & 1 deletion spectral_cube/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ def size(self):
""" Number of elements in the cube """
return self._data.size

@property
def base(self):
""" The data type 'base' of the cube - useful for, e.g., joblib """
return self._data.base

def __len__(self):
return self.shape[0]

Expand Down Expand Up @@ -943,7 +948,7 @@ def __getitem__(self, view):
newwcs = self._wcs.sub([a
for a in (1,2,3)
if a not in [x+1 for x in intslices]])
return OneDSpectrum(value=self.filled_data[view],
return OneDSpectrum(value=self._data[view],
wcs=newwcs,
copy=False,
unit=self.unit,
Expand Down
16 changes: 16 additions & 0 deletions spectral_cube/tests/test_spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import operator
import itertools
import warnings
import mmap

# needed to test for warnings later
warnings.simplefilter('always', UserWarning)
Expand Down Expand Up @@ -601,6 +602,21 @@ def test_read_write_rountrip(tmpdir):
# maximized
assert cube._wcs.to_header_string() == cube2._wcs.to_header_string()

@pytest.mark.parametrize(('memmap', 'base'),
((True, mmap.mmap),
(False, None)))
def test_read_memmap(memmap, base):
cube = SpectralCube.read(path('adv.fits'), memmap=memmap)

bb = cube.base
while hasattr(bb, 'base'):
bb = bb.base

if base is None:
assert bb is None
else:
assert isinstance(bb, base)


def _dummy_cube():
data = np.array([[[0, 1, 2, 3, 4]]])
Expand Down