Skip to content

Commit

Permalink
Coding standards tweaks to daskified cube.py. (SciTools#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
DPeterK authored and bjlittle committed May 26, 2017
1 parent c0e1878 commit 1c01ab7
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,6 @@ def __init__(self, data, standard_name=None, long_name=None,
if isinstance(data, six.string_types):
raise TypeError('Invalid data type: {!r}.'.format(data))

self.fill_value = fill_value

if is_lazy_data(data):
self._dask_array = data
self._numpy_array = None
Expand All @@ -727,8 +725,6 @@ def __init__(self, data, standard_name=None, long_name=None,
data = np.asarray(data)
self._numpy_array = data

self._dtype = dtype

#: The "standard name" for the Cube's phenomenon.
self.standard_name = standard_name

Expand All @@ -755,6 +751,10 @@ def __init__(self, data, standard_name=None, long_name=None,
# Cell Measures
self._cell_measures_and_dims = []

self.fill_value = fill_value

self._dtype = dtype

identities = set()
if dim_coords_and_dims:
dims = set()
Expand Down Expand Up @@ -1628,10 +1628,10 @@ def core_data(self):
to be decided: should this be public??
"""
if self._numpy_array is not None:
result = self._numpy_array
else:
if self.has_lazy_data():
result = self._dask_array
else:
result = self._numpy_array
return result

@property
Expand Down Expand Up @@ -1671,14 +1671,14 @@ def lazy_data(self):
A lazy array, representing the Cube data array.
"""
if self._numpy_array is not None:
if self.has_lazy_data():
result = self._dask_array
else:
data = self._numpy_array
if isinstance(data, ma.masked_array):
data = array_masked_to_nans(data)
data = data.data
result = da.from_array(data, chunks=data.shape)
else:
result = self._dask_array
return result

@property
Expand Down Expand Up @@ -1714,7 +1714,7 @@ def data(self):
(10, 20)
"""
if self._numpy_array is None:
if self.has_lazy_data():
try:
data = self._dask_array.compute()
mask = np.isnan(data)
Expand Down Expand Up @@ -1759,7 +1759,7 @@ def data(self, value):
self._numpy_array = value

def has_lazy_data(self):
return True if self._numpy_array is None else False
return self._numpy_array is None

@property
def dim_coords(self):
Expand Down Expand Up @@ -2223,12 +2223,10 @@ def new_cell_measure_dims(cm_):
except StopIteration:
first_slice = Ellipsis if self.share_data else None

if self._numpy_array is not None:
cube_data = self._numpy_array
elif self._dask_array is not None:
if self.has_lazy_data():
cube_data = self._dask_array
else:
raise ValueError('This cube has no data, slicing is not supported')
cube_data = self._numpy_array

if first_slice is not None:
data = cube_data[first_slice]
Expand Down Expand Up @@ -2859,12 +2857,14 @@ def transpose(self, new_order=None):
Example usage::
# put the second dimension first, followed by the third dimension,
and finally put the first dimension third cube.transpose([1, 2, 0])
and finally put the first dimension third::
>>> cube.transpose([1, 2, 0])
"""
if new_order is None:
# Passing numpy arrays as new_order works in numpy but not in dask,
# docs specify a list, so ensure a list is used.
# Passing NumPy arrays as new_order works in NumPy but not in dask.
# Dask docs specify a list, so ensure a list is used.
new_order = list(np.arange(self.ndim)[::-1])
elif len(new_order) != self.ndim:
raise ValueError('Incorrect number of dimensions.')
Expand Down

0 comments on commit 1c01ab7

Please sign in to comment.