1

I’ve run into a problem with merging cubes. I have a cube list that I would like to merge into a smaller set of cubes. However, when I try and merge iris gives me the following error message:

Traceback (most recent call last):
  File "site-packages/iris/cube.py", line 377, in merge_cube
    proto_cube.register(cube, error_on_mismatch=True)
  File "site-packages/iris/_merge.py", line 1260, in register
    error_on_mismatch)
  File "site-packages/iris/_merge.py", line 420, in match
    raise iris.exceptions.MergeError(msgs)
iris.exceptions.MergeError: failed to merge into a single cube.
  cube.var_name differs: u'air_pressure_at_sea_level_0' != u'air_pressure_at_sea_level_2'

I’m using Iris version 1.13.0 with python 2.7.

I have tried removing the var_name coordinate but got an exception when I did cube.remove_coord('var_name'):

iris.exceptions.CoordinateNotFoundError: 'Expected to find exactly 1  coordinate, but found none.'

Other than this detail, I consider the two cubes to be suitable for merging and would appreciate any guidance.

Neill Bowler
  • 145
  • 1
  • 10

1 Answers1

1

var_name is an attribute on a cube (and, as it happens, on coordinates) and it is this that differs between your two cubes.

Simply homogenising your var_names should be all that is needed in this instance. For example, you might want to set them all to air_pressure_at_sea_level with:

for cube in cubes:
    cube.var_name = 'air_pressure_at_sea_level'

After that, cubes.merge_cube() should work (or potentially raise a further incompatibility).

pelson
  • 21,252
  • 4
  • 92
  • 99
  • 1
    I also note that cube coordinates also have a var_name. Therefore it may also be necessary to apply a similar process to these. For instance: `cube.coord("latitude").var_name = "latitude"` (depending on how messed up your input cube is. – Neill Bowler Jul 06 '17 at 15:37