Transform from 3dimension to 4dimension

61 views
Skip to first unread message

python/iris

unread,
Mar 3, 2016, 11:22:55 PM3/3/16
to Iris

HI all,

I have 3dimesion precipitation cubes

like this,
>>> cubes = iris.load('*.nc') 
>>> print cubes
cubes[0] =     time : 360, latitude: 145, longitude:192
cubes[1] =     time : 360, latitude: 145, longitude:192
cubes[2]) =     time : 360, latitude: 145, longitude:192
cubes[3] =     time : 360, latitude: 145, longitude:192
cubes[4]=     time : 360, latitude: 145, longitude:192

5 cubes no scalar coordinate. therefore, merge function is not working. 
i attempted to slove the problem, like this

>>> ncube = iris.util.new_axis(cubes[0], 'time')
>>> print cubes[0]
cubes[0] =                        --:1  time:360 , latitude:145, longitude:192
dimension coordinates:      
time                                    -        x                -                      -
latitude                               -        -                 x                     -
longitude                            -        -                 -                     x
  conventions: CF-1.5
>>> ncube.add_dim_coord(iris.coords.DimCoords([1], 'height'),0)
>>> print ncube

cubes[0] =                        height:1  time:360 , latitude:145, longitude:192
dimension coordinates:      
height                                 x        -                -                      -
time                                    -        x                -                      -
latitude                               -        -                 x                     -
longitude                            -        -                 -                     x

is this right?
Ultimately, I want to multi mean ensemble..
Please advise me what to do

Richard Hattersley

unread,
Mar 4, 2016, 3:54:11 AM3/4/16
to Iris
As you say, the merge and merge_cube methods work with scalar coordinates. But a scalar coordinate isn't associated with a dimension. It looks like what you want to do is something like:

for i, cube in enumerate(cubes):
    cube
.add_aux_coord(iris.coords.DimCoord(i, 'height'))

merged_cube
= cubes.merge_cube()

Did you really mean to use "height" to label all the cubes? Should that have been "realization" instead?
Message has been deleted
Message has been deleted

python/iris

unread,
Mar 6, 2016, 8:12:10 PM3/6/16
to Iris
Hi Richard.

Thank you for your answers.

yes, I want to cubes has 'realization' coordinate..

and i tried,
fileform =  pr_day_MIROC5_rcp85_r1i1p1_2007_2049_ensemble_001.nc

----------------------------------------------------------------------------------
import iris
import numpy as np
def realization_metadata(cube, field, fname):
       if not cube.coords('realization'):
              realization_number = fname[-6:-3]
              import iris.coords
              realization_coord = iris.coords.AuxCoord(np.int32(realization_number), 'realization')
              cube.add_aux_coord(realization_coord)
filenmae = iris.sample_data_path('/2007-2049/*')
cubes  = iris.load(filename(callback=realization_metadata)
cubes = iris.cube.CubeList([cube[:,:,:] for cube in cubes])
newcube = cubes.merge_cube()
print newcube
-------------------------------------------------------------------------------------------
but two error

newcube = cubes.merge_cube()
iris.exception.MergeError: failed to merge into a single cube.
cube.shape differs: (12.360.145.192) !=(360,,145,192)               # i think, it is not problems.
cube data fill_value differs:9.969209968386869e+36 !=1e+20

and

cube data dtype differs: float 64 != float 32

i think, I use the "iris.fileformat.netcdf.NetCDFDataProxy"   but i'm not sure.
how do i slove this problem..
Reply all
Reply to author
Forward
0 new messages