Skip to content

Commit

Permalink
Attempts to define _data as original array; Doesn't work where __new_…
Browse files Browse the repository at this point in the history
…_ isn't called
  • Loading branch information
e-koch committed Sep 2, 2020
1 parent 13842d0 commit 6e0e91c
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions spectral_cube/lower_dimensional_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from . import spectral_axis
from .io.core import LowerDimensionalObjectWrite
from .utils import SliceWarning, BeamWarning, SmoothingWarning, FITSWarning
from .cube_utils import convert_bunit
from . import cube_utils
from . import wcs_utils
from .masks import BooleanArrayMask, MaskBase

Expand All @@ -26,7 +26,6 @@
MultiBeamMixinClass, BeamMixinClass,
HeaderMixinClass
)
from . import cube_utils

__all__ = ['LowerDimensionalObject', 'Projection', 'Slice', 'OneDSpectrum']
class LowerDimensionalObject(u.Quantity, BaseNDClass, HeaderMixinClass):
Expand Down Expand Up @@ -89,6 +88,10 @@ def __getitem__(self, key, **kwargs):
else:
newwcs = None

print(new_qty)
print(new_qty._data)
print(new_qty.value)

new = self.__class__(value=new_qty.value,
unit=new_qty.unit,
copy=False,
Expand Down Expand Up @@ -132,13 +135,13 @@ def array(self):
Get a pure array representation of the LDO. Useful when multiplying
and using numpy indexing tricks.
"""
return np.asarray(self)
return self.filled_data[:].value

@property
def _data(self):
# the _data property is required by several other mixins
# (which probably means defining it here is a bad design)
return self.array
# @property
# def _data(self):
# # the _data property is required by several other mixins
# # (which probably means defining it here is a bad design)
# return self.__data

@property
def quantity(self):
Expand All @@ -152,8 +155,8 @@ def value(self):
"""
Get a unitless numpy array with the mask applied.
"""
# return np.asarray(self.filled_data[:])
return np.asarray(self)
return np.asarray(self.filled_data[:])
# return np.asarray(self)

def to(self, unit, equivalencies=[], freq=None):
"""
Expand Down Expand Up @@ -297,8 +300,16 @@ def __new__(cls, value, unit=None, dtype=None, copy=True, wcs=None,
if wcs is not None and wcs.wcs.naxis != 2:
raise ValueError("wcs should have two dimension")

self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)
# self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
# copy=copy).view(cls)

self = super().__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)

# self = cls.__new__(cls, value, unit=unit, dtype=dtype,
# copy=copy).view(cls)

self._data = np.asarray(value)
self._wcs = wcs
self._meta = {} if meta is None else meta
self._wcs_tolerance = wcs_tolerance
Expand Down Expand Up @@ -427,7 +438,7 @@ def from_hdu(hdu):
mywcs = wcs.WCS(hdu.header)

if "BUNIT" in hdu.header:
unit = convert_bunit(hdu.header["BUNIT"])
unit = cube_utils.convert_bunit(hdu.header["BUNIT"])
meta["BUNIT"] = hdu.header["BUNIT"]
else:
unit = None
Expand Down Expand Up @@ -661,8 +672,13 @@ def __new__(cls, value, unit=None, dtype=None, copy=True, wcs=None,
if wcs is not None and wcs.wcs.naxis != 1:
raise ValueError("wcs should have two dimension")

self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)
self = super().__new__(cls, value, unit=unit, dtype=dtype,
copy=copy).view(cls)

# self = u.Quantity.__new__(cls, value, unit=unit, dtype=dtype,
# copy=copy).view(cls)

self._data = np.asarray(value)
self._wcs = wcs
self._meta = {} if meta is None else meta
self._wcs_tolerance = wcs_tolerance
Expand Down Expand Up @@ -705,7 +721,7 @@ def from_hdu(hdu):
mywcs = wcs.WCS(hdu.header)

if "BUNIT" in hdu.header:
unit = convert_bunit(hdu.header["BUNIT"])
unit = cube_utils.convert_bunit(hdu.header["BUNIT"])
meta["BUNIT"] = hdu.header["BUNIT"]
else:
unit = None
Expand Down

0 comments on commit 6e0e91c

Please sign in to comment.