0

I'm using the python iris module to read in some netCDF data and output specific fields in grib format for further downstream processing. However I generate the following error

 .../pythonlib/iris/1.9.1/lib/python2.7/site-packages/Iris-1.9.1-py2.7-linux-x86_64.egg/iris/fileformats/grib/_save_rules.pyc in gribbability_check(cube)    
   1062     cs1 = cube.coord(dimensions=[1]).coord_system   
   1063     if cs0 is None or cs1 is None:     
-> 1064         raise iris.exceptions.TranslationError("CoordSystem not present") 
   1065     if cs0 != cs1:  
   1066         raise iris.exceptions.TranslationError("Inconsistent CoordSystems")

 TranslationError: CoordSystem not present

So after having read the following :

Iris Google group thread https://groups.google.com/forum/#!searchin/scitools-iris/grib2/scitools-iris/D2InfYESaUM/yVT7ayXSFV0J

StackOverflow thread Converting NetCDF to GRIB2

iris source code at https://github.com/SciTools/iris/blob/master/lib/iris/fileformats/grib/grib_save_rules.py#L80

I attempted the following

In [26]: radius=iris.fileformats.pp.EARTH_RADIUS

In [27]: u.coord(dimensions=[0]).coord_system=iris.coord_systems.GeogCS(radius)

In [28]: u.coord(dimensions=[1]).coord_system=iris.coord_systems.GeogCS(radius)

In [29]: u.coord(dimensions=[0]).coord_system
Out[29]: GeogCS(6371229.0)

In [30]: u.coord(dimensions=[1]).coord_system
Out[30]: GeogCS(6371229.0)  

In [31]: iris.save(u,'prod.grib2')
  ---------------------------------------------------------------------------
 TranslationError                          Traceback (most recent call last)
 <ipython-input-15-a38abe1720ac> in <module>()
 ----> 1 iris.save(u,'prod.grib2')

i.e. I still generate the same error, a failure in the iris subroutine gribbability_check

Hoping someone can help. I'm using iris 1.9.0 with python 2.7.6. The operation also fails with iris 1.8.0

Cheers

Community
  • 1
  • 1

1 Answers1

1

Thanks to Andrew Dawson on the iris google group for the answer. Dimensions [0] and [1] in grib_save_rules.py strictly refer to spatial dimensions, even if your cube may use time for the zeroth dimension. To quote:

There is a huge amount of code in between your cube and saving as grib2. Since grib knows nothing about dimensionalities above 2 (it only stores 1 grid per message) we split your cube up into one slice per grid and pass that onward, hence in the function you are referring to dimension 0 is latitude and 1 is longitude regardless of how many other dimensions your cube had.

If I repeat the process but prescribe the coord_system to my spatial dimensions and give the vertical co-ordinate an attribute as well using

cube.coord('vertical_level').standard_name = 'air_pressure'

The grib can be saved.