Merging/concatenating two cubes, one of which has a scalar coordinate

572 views
Skip to first unread message

Simon Peatman

unread,
Nov 14, 2016, 7:53:43 AM11/14/16
to Iris

I have two Cubes which I wish to merge/concatenate, which are as follows:
>>> print c1
toa_outgoing_longwave_flux
/ (W m-2) (time: 9840; longitude: 40)
     
Dimension coordinates:
          time                            x                
-
          longitude                      
-                x
     
Scalar coordinates:
          latitude
: -21.3889 degrees, bound=(-21.6667, -21.1111) degrees
>>> print c2
toa_outgoing_longwave_flux
/ (W m-2) (time: 9840; latitude: 111; longitude: 40)
     
Dimension coordinates:
          time                            x              
-               -
          latitude                        
-               x               -
          longitude                      
-               -               x

As you can see, their shapes are incompatible but only because Iris treats a coordinate of length 1 as a scalar coordinate, not a dimension coordinate.  It would be perfectly meaningful to concatenate these along the latitude dimension to make a new Cube of shape (9840, 112, 40) but Iris refuses (see below).  I know that merging is used for scalar coordinates and concatenating for dimension coordinates, but what about when you have one of each?

>>> iris.cube.CubeList([c1, c2]).merge_cube()
MergeError: failed to merge into a single cube.
  cube
.shape differs: (9840, 40) != (9840, 111, 40)
>>> iris.cube.CubeList([c1, c2]).concatenate_cube()
ConcatenateError: failed to concatenate into a single cube.
 
Dimension coordinates differ: longitude, time != latitude, longitude, time
 
Scalar coordinates differ: latitude != < None >
 
Data dimensions differ: 2 != 3

Is there a way in which the latitude scalar coordinate in c1 can be "promoted" to a dimension coordinate in order for the concatenation to happen, or is there another solution to this?

Andrew Dawson

unread,
Nov 14, 2016, 8:11:20 AM11/14/16
to Iris
Use iris.util.new_axis to promote the scalar coordinate to a singleton dimension coordinate, then I guess use transpose to put the axes in the same order (don't know if that is required, but makes sense), and then use concatenate.

Simon Peatman

unread,
Nov 14, 2016, 8:28:08 AM11/14/16
to Iris
Excellent, thanks very much.

Simon
Reply all
Reply to author
Forward
0 new messages