Skip to content

Commit

Permalink
Allow other array parameters to be passed to MaskedArray through Dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Apr 8, 2016
1 parent 0223207 commit 7443bdb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions satpy/projectable.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ def wrapper(self, *args, **kwargs):


class Dataset(np.ma.MaskedArray):
_array_kwargs = ["mask", "dtype", "copy", "subok", "ndmin", "keep_mask", "hard_mask", "shrink"]
_shared_kwargs = ["fill_value"]

def __new__(cls, data, **info):
# Input array is an already formed ndarray instance
# We first cast to be our class type
obj = np.ma.MaskedArray(data, mask=info.pop("mask", None)).view(cls)
# pull out kwargs that are meant for the masked array
array_kwargs = {k: info.pop(k) for k in cls._array_kwargs if k in info}
array_kwargs.update({k: info[k] for k in cls._shared_kwargs if k in info})
obj = np.ma.MaskedArray(data, **array_kwargs).view(cls)
# add the new attribute to the created instance
obj.info = getattr(data, "info", {})
obj.info.update(info)
Expand All @@ -123,7 +128,7 @@ def _update_info(self, obj):
def _update_from(self, obj):
"""Copies some attributes of obj to self.
"""
np.ma.MaskedArray._update_from(self, obj)
super(Dataset, self)._update_from(obj)
if self.info is None:
self.info = {}
self._update_info(obj)
Expand All @@ -133,7 +138,7 @@ def __array_finalize__(self, obj):
if obj is None:
return
self.info = getattr(self, 'info', {})
np.ma.MaskedArray.__array_finalize__(self, obj)
super(Dataset, self).__array_finalize__(obj)
self._update_info(obj)

@copy_info
Expand Down

0 comments on commit 7443bdb

Please sign in to comment.