Unable to create instance of HybridHeightFactory. The file(s) ... don't contain field(s) for 'orography'.

311 views
Skip to first unread message

Luke Abraham

unread,
Oct 27, 2015, 7:59:48 AM10/27/15
to Iris
I would like to create/have access to the altitude derived coordinate for a cube which is on hybrid theta levels. Whenever I load a cube containing this data I get the following message:

/usr/lib/python2.7/site-packages/iris/fileformats/rules.py:835: UserWarning: Unable to create instance of HybridHeightFactory. The file(s) [
....
] don't contain field(s) for 'orography'.

The cube itself looks like this:

mass_fraction_of_ozone_in_air / (kg kg-1) (time: 12; model_level_number: 60; latitude: 73; longitude: 96)
     Dimension coordinates:
          time                                 x                       -             -              -
          model_level_number                   -                       x             -              -
          latitude                             -                       -             x              -
          longitude                            -                       -             -              x
     Auxiliary coordinates:
          forecast_period                      x                       -             -              -
          level_height                         -                       x             -              -
          sigma                                -                       x             -              -
     Scalar coordinates:
          forecast_reference_time: 1951-01-01 00:00:00
     Attributes:
          STASH: m01s34i001
          source: Data from Met Office Unified Model
          um_version: 7.3
     Cell methods:
          mean: time (1 hour)

I have used a call-back to define the name/units of the cube.

I have the qrparm.orog file in UM ancillary file format (used by the model), which contains the orography. I can load this, and iris sees it like this:

unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i034
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i005
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i006
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i035
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i036
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i037
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i017
          source: Data from Met Office Unified Model
          um_version: 7.3
unknown / (unknown)                 (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i018
          source: Data from Met Office Unified Model
          um_version: 7.3
surface_altitude / (m)              (latitude: 145; longitude: 192)
     Dimension coordinates:
          latitude                           x               -
          longitude                          -               x
     Attributes:
          STASH: m01s00i033
          source: Data from Met Office Unified Model
          um_version: 7.3

The cube labelled as surface_altitude is the model orography field. The other fields are things like

OROGRAPHY (/STRAT LOWER BC)           (m01s00i033)
STANDARD DEVIATION OF OROGRAPHY       (m01s00i034)
OROGRAPHIC GRADIENT  X COMPONENT      (m01s00i005)
OROGRAPHIC GRADIENT  Y COMPONENT      (m01s00i006)
OROGRAPHIC GRADIENT XX COMPONENT      (m01s00i035)
OROGRAPHIC GRADIENT XY COMPONENT      (m01s00i036)
OROGRAPHIC GRADIENT YY COMPONENT      (m01s00i037)
SILHOUETTE OROGRAPHIC ROUGHNESS       (m01s00i017)
HALF OF  (PEAK TO TROUGH HT OF OROG)  (m01s00i018)

although it seems that only the surface_altitude/orography has been named within iris.

I would like to either
  • 1) Load the cube such that the orography is recognised and that the altitude coordinate is generated
or 
  • 2) use HybridHeightFactory after the fact and insert the altitude coordinate

Is this possible to do given the files/cubes that I have? 

The reason I want this is to be able to accurately calculate the volume of each gridcell (calculating the area of each gridcell is straight-forward from the latitude/longitudes). 

In the future I will want to do the equivalent with hybrid pressure coordinate to derive the true pressure at each level, and I assume/am hoping that a similar method can be used with the surface pressure.

Many thanks,
Luke



Luke Abraham

unread,
Oct 29, 2015, 6:24:19 AM10/29/15
to Iris
The solution here seems to be to make the orography/surface_altitude field an auxiliary coordinate to the cube, then use iris.aux_factory.HybridHeightFactory and add_aux_factory to create the altitude derrived coordinate:

In [2]: orog
Out[2]: <iris 'Cube' of surface_altitude / (m) (latitude: 73; longitude: 96)>

In [3]: auxcoord=iris.coords.AuxCoord(orog.data,standard_name=str(orog.standard_name),long_name="orography",var_name="orog",units=orog.units)

In [4]: vmro3.add_aux_coord(auxcoord,(2,3,))

In [5]: factory=iris.aux_factory.HybridHeightFactory(sigma=vmro3.coord("sigma"),orography=vmro3.coord("surface_altitude"))

In [6]: vmro3.add_aux_factory(factory)

In [8]: print vmro3
mass_fraction_of_ozone_in_air / (kg kg-1) (time: 12; model_level_number: 60; latitude: 73; longitude: 96)
     Dimension coordinates:
          time                                 x                       -             -              -
          model_level_number                   -                       x             -              -
          latitude                             -                       -             x              -
          longitude                            -                       -             -              x
     Auxiliary coordinates:
          forecast_period                      x                       -             -              -
          level_height                         -                       x             -              -
          sigma                                -                       x             -              -
          surface_altitude                     -                       -             x              x
     Derived coordinates:
          altitude                             -                       x             x              x

Luke Abraham

unread,
Oct 29, 2015, 7:06:25 AM10/29/15
to Iris
However, now I'm getting the following error when trying to save this new cube (with the additional coordinates) to cf-netCDF. The error is with the altitude and not the surface_altitude coordinate:

KeyError                                  Traceback (most recent call last)
<ipython-input-10-d4d606719173> in <module>()
----> 1 iris.fileformats.netcdf.save(vmro3,'/group_workspaces/jasmin2/ukca/nlabraham/CCMI/misc/vmro3_03.nc',netcdf_format='NETCDF4_CLASSIC')

/usr/lib/python2.7/site-packages/iris/fileformats/netcdf.pyc in save(cube, filename, netcdf_format, local_keys, unlimited_dimensions, zlib, complevel, shuffle, fletcher32, contiguous, chunksizes, endian, least_significant_digit)
   1754             sman.write(cube, local_keys, unlimited_dimensions, zlib, complevel,
   1755                        shuffle, fletcher32, contiguous, chunksizes, endian,
-> 1756                        least_significant_digit)
   1757 
   1758         conventions = CF_CONVENTIONS_VERSION

/usr/lib/python2.7/site-packages/iris/fileformats/netcdf.pyc in write(self, cube, local_keys, unlimited_dimensions, zlib, complevel, shuffle, fletcher32, contiguous, chunksizes, endian, least_significant_digit)
    770         # Add the formula terms to the appropriate cf variables for each
    771         # aux factory in the cube.
--> 772         self._add_aux_factories(cube, cf_var_cube, dimension_names)
    773 
    774         # Add data variable-only attribute names to local_keys.

/usr/lib/python2.7/site-packages/iris/fileformats/netcdf.pyc in _add_aux_factories(self, cube, cf_var_cube, dimension_names)
    952                 primaries.append(primary_coord)
    953 
--> 954                 cf_name = self._name_coord_map.name(primary_coord)
    955                 cf_var = self._dataset.variables[cf_name]
    956 

/usr/lib/python2.7/site-packages/iris/fileformats/netcdf.pyc in name(self, coord)
    194         if result is None:
    195             msg = 'Coordinate is not mapped, {!r}'.format(coord)
--> 196             raise KeyError(msg)
    197         return result
    198 

KeyError: 'Coordinate is not mapped, None'


Is anyone able to explain what this error message means, and what to do to fix it?

Many thanks,
Luke
Message has been deleted

Luke Abraham

unread,
Oct 29, 2015, 7:55:23 AM10/29/15
to Iris
I should clarify that the altitude here then only gives the b * orog term. Passing in model_level_height as the delta then gives the altitude above sea-level.

Luke Abraham

unread,
Oct 29, 2015, 8:18:27 AM10/29/15
to Iris
I should clarify that the altitude here then only gives the b * orog term. Passing in model_level_height as the delta then gives the altitude above sea-level.

Now when trying to save the netCDF file is created (so no error message as above), however, the altitude is not included. Instead, the following is added to the level_height coordinate:

level_height:formula_terms = "a: level_height b: sigma orog: orog" ;


Reply all
Reply to author
Forward
0 new messages