Skip to content
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
16 changes: 9 additions & 7 deletions lib/iris/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,16 +1141,18 @@ def _get_cube(self):
aux_coords_and_dims = [(deepcopy(coord), dims) for coord, dims in self._aux_coords_and_dims]
kwargs = dict(zip(iris.cube.CubeMetadata._fields, signature.defn))

# Create fully masked data i.e. all missing.
# Create fully masked data, i.e. all missing.
# (The CubeML checksum doesn't respect the mask, so we zero the
# underlying data to ensure repeatable checksums.)
if signature.data_manager is None:
# Must zero the data in order to avoid random checksums.
data = numpy.ma.zeros(self._shape, dtype=signature.data_type)
data.fill_value = signature.mdi
data = numpy.ma.MaskedArray(numpy.zeros(self._shape,
signature.data_type),
mask=numpy.ones(self._shape, 'bool'),
fill_value=signature.mdi)
else:
# With dtype=object, ma.empty DOES initialise the memory (all None).
data = numpy.ma.empty(self._shape, dtype=object)
data = numpy.ma.MaskedArray(numpy.zeros(self._shape, 'object'),
mask=numpy.ones(self._shape, 'bool'))

data.mask = True
cube = iris.cube.Cube(data,
dim_coords_and_dims=dim_coords_and_dims,
aux_coords_and_dims=aux_coords_and_dims,
Expand Down
13 changes: 8 additions & 5 deletions lib/iris/fileformats/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,16 @@ def load(self, proxy_array):

# Create fully masked data (all missing)
try:
data = numpy.ma.zeros(array_shape, dtype=self.data_type.newbyteorder('='), fill_value=self.mdi)
data.mask = True
raw_data = numpy.empty(array_shape,
dtype=self.data_type.newbyteorder('='))
mask = numpy.ones(array_shape, dtype=numpy.bool)
data = numpy.ma.MaskedArray(raw_data, mask=mask,
fill_value=self.mdi)
except ValueError:
raise DataManager.ArrayTooBigForAddressSpace(
'Cannot create an array of shape %r as it will not fit in memory. Try reducing the shape '
'of the proxy array by using indexing.' % (array_shape, )
)
'Cannot create an array of shape %r as it will not fit in'
' memory. Consider using indexing to select a subset of'
' the Cube.'.format(array_shape))

for index, proxy in numpy.ndenumerate(proxy_array):
if proxy not in [None, 0]: # 0 can come from slicing masked proxy; numpy.array(masked_constant).
Expand Down