Skip to content

Commit ef294b9

Browse files
committed
Include AncillaryVariables and restructure Cube metadata.
1 parent c892fa7 commit ef294b9

9 files changed

Lines changed: 1028 additions & 640 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Cell measures are now handled correctly when a cube is transposed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* CF Ancillary Data are now supported in cubes.

lib/iris/_concatenate.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2013 - 2017, Met Office
1+
# (C) British Crown Copyright 2013 - 2019, Met Office
22
#
33
# This file is part of Iris.
44
#
@@ -301,7 +301,8 @@ def _none_sort(item):
301301
class _CubeSignature(object):
302302
"""
303303
Template for identifying a specific type of :class:`iris.cube.Cube` based
304-
on its metadata, coordinates and cell_measures.
304+
on its metadata and dimensional metadata, including: coordinates,
305+
cell_measures and ancillary_variables.
305306
306307
"""
307308
def __init__(self, cube):
@@ -322,6 +323,7 @@ def __init__(self, cube):
322323
self.ndim = cube.ndim
323324
self.scalar_coords = []
324325
self.cell_measures_and_dims = cube._cell_measures_and_dims
326+
self.ancillary_variables_and_dims = cube._ancillary_variables_and_dims
325327
self.dim_mapping = []
326328

327329
# Determine whether there are any anonymous cube dimensions.
@@ -415,6 +417,8 @@ def match(self, other, error_on_mismatch):
415417
- dimensions metadata
416418
- aux coords metadata
417419
- scalar coords
420+
- cell measures
421+
- ancillary variables
418422
- attributes
419423
- dtype
420424
@@ -471,6 +475,14 @@ def match(self, other, error_on_mismatch):
471475
self.cell_measures_and_dims,
472476
other.cell_measures_and_dims))
473477

478+
# Check ancillary_variables_and_dims
479+
if self.ancillary_variables_and_dims != \
480+
other.ancillary_variables_and_dims:
481+
msgs.append(msg_template.format(
482+
'AncillaryVariables', '',
483+
self.ancillary_variables_and_dims,
484+
other.ancillary_variables_and_dims))
485+
474486
match = not bool(msgs)
475487
if error_on_mismatch and not match:
476488
raise iris.exceptions.ConcatenateError(msgs)
@@ -670,11 +682,15 @@ def concatenate(self):
670682
kwargs = cube_signature.defn._asdict()
671683
new_cm_and_dims = [(deepcopy(cm), dims) for cm, dims
672684
in self._cube._cell_measures_and_dims]
673-
cube = iris.cube.Cube(data,
674-
dim_coords_and_dims=dim_coords_and_dims,
675-
aux_coords_and_dims=aux_coords_and_dims,
676-
cell_measures_and_dims=new_cm_and_dims,
677-
**kwargs)
685+
new_av_and_dims = [(deepcopy(av), dims) for av, dims
686+
in self._cube._ancillary_variables_and_dims]
687+
cube = iris.cube.Cube(
688+
data,
689+
dim_coords_and_dims=dim_coords_and_dims,
690+
aux_coords_and_dims=aux_coords_and_dims,
691+
cell_measures_and_dims=new_cm_and_dims,
692+
ancillary_variables_and_dims=new_av_and_dims,
693+
**kwargs)
678694
else:
679695
# There are no other source-cubes to concatenate
680696
# with this proto-cube.

lib/iris/_merge.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2010 - 2017, Met Office
1+
# (C) British Crown Copyright 2010 - 2019, Met Office
22
#
33
# This file is part of Iris.
44
#
@@ -315,7 +315,8 @@ class _CoordSignature(namedtuple('CoordSignature',
315315

316316
class _CubeSignature(namedtuple('CubeSignature',
317317
['defn', 'data_shape', 'data_type',
318-
'cell_measures_and_dims'])):
318+
'cell_measures_and_dims',
319+
'ancillary_variables_and_dims'])):
319320
"""
320321
Criterion for identifying a specific type of :class:`iris.cube.Cube`
321322
based on its metadata.
@@ -334,6 +335,9 @@ class _CubeSignature(namedtuple('CubeSignature',
334335
* cell_measures_and_dims:
335336
A list of cell_measures and dims for the cube.
336337
338+
* ancillary_variables_and_dims:
339+
A list of ancillary_variables and dims for the cube.
340+
337341
"""
338342

339343
__slots__ = ()
@@ -405,6 +409,9 @@ def match(self, other, error_on_mismatch):
405409
msgs.append(msg.format(self.data_type, other.data_type))
406410
if (self.cell_measures_and_dims != other.cell_measures_and_dims):
407411
msgs.append('cube.cell_measures differ')
412+
if (self.ancillary_variables_and_dims !=
413+
other.ancillary_variables_and_dims):
414+
msgs.append('cube.ancillary_variables differ')
408415

409416
match = not bool(msgs)
410417
if error_on_mismatch and not match:
@@ -1134,6 +1141,10 @@ def __init__(self, cube):
11341141
# they are checked and preserved through merge
11351142
self._cell_measures_and_dims = cube._cell_measures_and_dims
11361143

1144+
# ancillary_variables are not merge candidates
1145+
# they are checked and preserved through merge
1146+
self._ancillary_variables_and_dims = cube._ancillary_variables_and_dims
1147+
11371148
def _report_duplicate(self, nd_indexes, group_by_nd_index):
11381149
# Find the first offending source-cube with duplicate metadata.
11391150
index = [group_by_nd_index[nd_index][1]
@@ -1483,10 +1494,13 @@ def _get_cube(self, data):
14831494

14841495
cms_and_dims = [(deepcopy(cm), dims)
14851496
for cm, dims in self._cell_measures_and_dims]
1497+
av_and_dims = [(deepcopy(av), dims)
1498+
for av, dims in self._ancillary_variables_and_dims]
14861499
cube = iris.cube.Cube(data,
14871500
dim_coords_and_dims=dim_coords_and_dims,
14881501
aux_coords_and_dims=aux_coords_and_dims,
14891502
cell_measures_and_dims=cms_and_dims,
1503+
ancillary_variables_and_dims=av_and_dims,
14901504
**kwargs)
14911505

14921506
# Add on any aux coord factories.
@@ -1607,7 +1621,8 @@ def _build_signature(self, cube):
16071621
"""
16081622

16091623
return _CubeSignature(cube.metadata, cube.shape,
1610-
cube.dtype, cube._cell_measures_and_dims)
1624+
cube.dtype, cube._cell_measures_and_dims,
1625+
cube._ancillary_variables_and_dims)
16111626

16121627
def _add_cube(self, cube, coord_payload):
16131628
"""Create and add the source-cube skeleton to the ProtoCube."""

0 commit comments

Comments
 (0)