Skip to content

Commit

Permalink
Define .quantity and .value to return filled_data and use the mask
Browse files Browse the repository at this point in the history
  • Loading branch information
e-koch committed Sep 2, 2020
1 parent 80304b1 commit a591ea9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions spectral_cube/lower_dimensional_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ def quantity(self):
"""
Get a pure `~astropy.units.Quantity` representation of the LDO.
"""
return u.Quantity(self)
return u.Quantity(self.filled_data[:])

@property
def value(self):
"""
Get a unitless numpy array with the mask applied.
"""
return np.asarray(self.filled_data[:])

def to(self, unit, equivalencies=[], freq=None):
"""
Expand Down Expand Up @@ -248,22 +255,22 @@ def _initial_set_mask(self, mask):
matters: ``self`` must have ``_wcs``, for example.
"""
if mask is None:
mask = BooleanArrayMask(np.ones_like(self.value, dtype=bool),
self._wcs, shape=self.value.shape)
mask = BooleanArrayMask(np.isfinite(self.array),
self._wcs, shape=self.array.shape)
elif isinstance(mask, np.ndarray):
if mask.shape != self.value.shape:
if mask.shape != self.array.shape:
raise ValueError("Mask shape must match the {0} shape."
.format(self.__class__.__name__)
)
mask = BooleanArrayMask(mask, self._wcs, shape=self.value.shape)
mask = BooleanArrayMask(mask, self._wcs, shape=self.array.shape)
elif isinstance(mask, MaskBase):
pass
else:
raise TypeError("mask of type {} is not a supported mask "
"type.".format(type(mask)))

# Validate the mask before setting
mask._validate_wcs(new_data=self.value, new_wcs=self._wcs,
mask._validate_wcs(new_data=self.array, new_wcs=self._wcs,
wcs_tolerance=self._wcs_tolerance)

self._mask = mask
Expand Down

0 comments on commit a591ea9

Please sign in to comment.