Renaming an anonymous dimension

727 views
Skip to first unread message

ScottHosking

unread,
Mar 16, 2015, 8:03:18 AM3/16/15
to scitoo...@googlegroups.com
Hi, I have loaded a cubelist but I am having issues merging the data into a single cube (see below).

Is there a way to force hist[2] to use 'time' as the first coordinate?

MergeError: failed to merge into a single cube.
 
Coordinates in cube.dim_coords differ: time.
 
Coordinate-to-dimension mapping differs for cube.dim_coords.
 
Coordinates in cube.aux_coords (non-scalar) differ: season_year, clim_season, time.
 
Coordinate-to-dimension mapping differs for cube.aux_coords (non-scalar).

In [219]: hist
Out[219]:
[<iris 'Cube' of northward_wind / (m s-1) (time: 4; latitude: 160; longitude: 320)>,
<iris 'Cube' of northward_wind / (m s-1) (time: 4; latitude: 160; longitude: 320)>,
<iris 'Cube' of northward_wind / (m s-1) (-- : 4; latitude: 160; longitude: 320)>,
<iris 'Cube' of northward_wind / (m s-1) (time: 4; latitude: 160; longitude: 320)>,
<iris 'Cube' of northward_wind / (m s-1) (time: 4; latitude: 160; longitude: 320)>]

Here is the output for `print hist[2]` and a cube without this issue (hist[1]).  I am not sure why 'time' has become an Auxiliary coordinate within hist[2]

In [220]: print hist[2]
northward_wind
/ (m s-1)            (-- : 4; latitude: 160; longitude: 320)
     
Dimension coordinates:
          latitude                      
-            x               -
          longitude                    
-            -               x
     
Auxiliary coordinates:
          clim_season                   x            
-               -
          season_year                   x            
-               -
          time                          x            
-               -
     
Scalar coordinates:
         
RunID: r2i1p1
          air_pressure
: 85000.0 Pa
     
Cell methods:
          mean
: time (30 minutes)
          mean
: clim_season, season_year
          mean
: clim_season

In [221]: print hist[1]
northward_wind
/ (m s-1)            (time: 4; latitude: 160; longitude: 320)
     
Dimension coordinates:
          time                           x            
-               -
          latitude                      
-            x               -
          longitude                      
-            -               x
     
Auxiliary coordinates:
          clim_season                    x            
-               -
          season_year                    x            
-               -
     
Scalar coordinates:
         
RunID: r4i1p2
          air_pressure
: 85000.0 Pa
     
Cell methods:
          mean
: time (30 minutes)
          mean
: clim_season, season_year
          mean
: clim_season



Richard Hattersley

unread,
Mar 16, 2015, 9:20:17 AM3/16/15
to scitoo...@googlegroups.com
Sounds like you might be interested in a recent pull-request: https://github.com/SciTools/iris/pull/1567 ?

Richard

ScottHosking

unread,
Mar 16, 2015, 11:22:18 AM3/16/15
to scitoo...@googlegroups.com
Thanks Richard, that's looks to be exactly what I'm looking for.

Is there a way I could make this change using a released version of Iris?  (1.7.3+)

Richard Hattersley

unread,
Mar 16, 2015, 1:24:11 PM3/16/15
to scitoo...@googlegroups.com
Fixing your misbehaving "time" coordinate(*) should just need:

old_time = hist[2].coord('time')
new_time = iris.coords.DimCoord.from_coord(old_time)
hist
[2].remove_coord(old_time)
hist[2].add_dim_coord(new_time, 0)

*) The call to DimCoord.from_coord() will raise an error if the values are not suitable - i.e. numeric and monotonic.

Richard

ScottHosking

unread,
Mar 16, 2015, 1:55:07 PM3/16/15
to scitoo...@googlegroups.com
Thank you Richard,

Although, as you say, this raised the error "The points array must be strictly monotonic."
Reply all
Reply to author
Forward
0 new messages