Skip to content

Merge and non-scalar AuxCoords #3084

@rcomer

Description

@rcomer

Cubes in a cubelist are prevented from merging if they have non-scalar auxcoords with points (or bounds, presumably) that do not match. Example:

import iris
print iris.__version__

dimcoord = iris.coords.DimCoord(range(5), long_name='foo')
scalarcoords = [iris.coords.AuxCoord(x, long_name='bar') for x in [1, 2]]
auxcoords = [iris.coords.AuxCoord(range(x, x + 5),
             long_name='wibble') for x in [3, 6]]

cubes = iris.cube.CubeList([
    iris.cube.Cube([0] * 5, dim_coords_and_dims=[(dimcoord, 0)],
                   aux_coords_and_dims=[(auxcoord, 0), (scalarcoord, None)])
    for auxcoord, scalarcoord in zip(auxcoords, scalarcoords)])

for cube in cubes:
    print cube
print cubes.merge_cube()

Output:

2.0.0
unknown / (unknown)                 (foo: 5)
     Dimension coordinates:
          foo                           x
     Auxiliary coordinates:
          wibble                        x
     Scalar coordinates:
          bar: 1
unknown / (unknown)                 (foo: 5)
     Dimension coordinates:
          foo                           x
     Auxiliary coordinates:
          wibble                        x
     Scalar coordinates:
          bar: 2
Traceback (most recent call last):
<snip>
    raise iris.exceptions.MergeError(msgs)
iris.exceptions.MergeError: failed to merge into a single cube.
  Coordinates in cube.aux_coords (non-scalar) differ: wibble.

Ideally merge would be able to stack the wibble coordinates together to create a 2D auxcoord spanning the new cube.

This came from an example discussed internally on Met Office Yammer, where cubes loaded from a pp-file each have a 2D surface_pressure coordinate that spans latitude and longitude. Attempting to merge the cubes (creating a time dimension) fail because the surface pressure changes with time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions