Logo Iris 1.12

Previous topic

iris.fileformats.ff

Next topic

iris.fileformats.grib.grib_phenom_translation

This Page

iris.fileformats.grib

Conversion of cubes to/from GRIB.

See also: ECMWF GRIB API.

Deprecated since version 1.10: This module is now deprecated. For GRIB file support in iris, please use the separate package iris_grib instead.

In this module:

iris.fileformats.grib.load_cubes(filenames, callback=None, auto_regularise=True)

Returns a generator of cubes from the given list of filenames.

Args:

  • filenames (string/list):

    One or more GRIB filenames to load from.

Kwargs:

  • callback (callable function):

    Function which can be passed on to iris.io.run_callback().

  • auto_regularise (True | False):

    If True, any cube defined on a reduced grid will be interpolated to an equivalent regular grid. If False, any cube defined on a reduced grid will be loaded on the raw reduced grid with no shape information. If iris.FUTURE.strict_grib_load is True then this keyword has no effect, raw grids are always used. If the older GRIB loader is in use then the default behaviour is to interpolate cubes on a reduced grid to an equivalent regular grid.

    Deprecated since version 1.8.: Please use strict_grib_load and regrid instead.

↑ top ↑

iris.fileformats.grib.save_grib2(cube, target, append=False, **kwargs)

Save a cube or iterable of cubes to a GRIB2 file.

Args:

Kwargs:

  • append - Whether to start a new file afresh or add the cube(s) to

    the end of the file. Only applicable when target is a filename, not a file handle. Default is False.

See also iris.io.save().

↑ top ↑

iris.fileformats.grib.load_pairs_from_fields(grib_messages)

Convert an iterable of GRIB messages into an iterable of (Cube, Grib message) tuples.

Args:

Returns:
An iterable of tuples of (iris.cube.Cube, iris.fileformats.grib.message.GribMessage).

This capability can be used to filter out fields before they are passed to the load pipeline, and amend the cubes once they are created, using GRIB metadata conditions. Where the filtering removes a significant number of fields, the speed up to load can be significant:

>>> import iris
>>> from iris.fileformats.grib import load_pairs_from_fields
>>> from iris.fileformats.grib.message import GribMessage
>>> filename = iris.sample_data_path('polar_stereo.grib2')
>>> filtered_messages = []
>>> for message in GribMessage.messages_from_filename(filename):
...     if message.sections[1]['productionStatusOfProcessedData'] == 0:
...         filtered_messages.append(message)
>>> cubes_messages = load_pairs_from_fields(filtered_messages)
>>> for cube, msg in cubes_messages:
...     prod_stat = msg.sections[1]['productionStatusOfProcessedData']
...     cube.attributes['productionStatusOfProcessedData'] = prod_stat
>>> print(cube.attributes['productionStatusOfProcessedData'])
0

This capability can also be used to alter fields before they are passed to the load pipeline. Fields with out of specification header elements can be cleaned up this way and cubes created:

>>> from iris.fileformats.grib import load_pairs_from_fields
>>> cleaned_messages = GribMessage.messages_from_filename(filename)
>>> for message in cleaned_messages:
...     if message.sections[1]['productionStatusOfProcessedData'] == 0:
...         message.sections[1]['productionStatusOfProcessedData'] = 4
>>> cubes = load_pairs_from_fields(cleaned_messages)

↑ top ↑

iris.fileformats.grib.save_pairs_from_cube(cube)

Convert one or more cubes to (2D cube, GRIB message) pairs. Returns an iterable of tuples each consisting of one 2D cube and one GRIB message ID, the result of the 2D cube being processed by the GRIB save rules.

Args:

list of cubes.

↑ top ↑

iris.fileformats.grib.save_messages(messages, target, append=False)

Save messages to a GRIB2 file. The messages will be released as part of the save.

Args:

  • messages - An iterable of grib_api message IDs.
  • target - A filename or open file handle.

Kwargs:

  • append - Whether to start a new file afresh or add the cube(s) to

    the end of the file. Only applicable when target is a filename, not a file handle. Default is False.

↑ top ↑

Contains a pygrib object plus some extra keys of our own.

Deprecated since version 1.10.

The class iris.fileformats.grib.message.GribMessage provides alternative means of working with GRIB message instances.

class iris.fileformats.grib.GribWrapper(grib_message, grib_fh=None, auto_regularise=True)

Bases: object

Contains a pygrib object plus some extra keys of our own.

Deprecated since version 1.10.

The class iris.fileformats.grib.message.GribMessage provides alternative means of working with GRIB message instances.

phenomenon_bounds(time_unit)

Return the phenomenon time bound offsets from the epoch time reference measured in the appropriate time units.

phenomenon_points(time_unit)

Return the phenomenon time point offset from the epoch time reference measured in the appropriate time units.

↑ top ↑

iris.fileformats.grib.as_messages(cube)

Deprecated since version 1.10.

Please use iris.fileformats.grib.save_pairs_from_cube() instead.

Convert one or more cubes to GRIB messages. Returns an iterable of grib_api GRIB messages.

Args:

↑ top ↑

iris.fileformats.grib.as_pairs(cube)

Deprecated since version 1.10.

Please use iris.fileformats.grib.save_pairs_from_cube() for the same functionality.

↑ top ↑

iris.fileformats.grib.grib_generator(filename, auto_regularise=True)

Returns a generator of GribWrapper fields from the given filename.

Deprecated since version 1.10.

The function: iris.fileformats.grib.message.GribMessage.messages_from_filename() provides alternative means of obtainig GRIB messages from a file.

Args:

  • filename (string):

    Name of the file to generate fields from.

Kwargs:

  • auto_regularise (True | False):

    If True, any field defined on a reduced grid will be interpolated to an equivalent regular grid. If False, any field defined on a reduced grid will be loaded on the raw reduced grid with no shape information. The default behaviour is to interpolate fields on a reduced grid to an equivalent regular grid.

↑ top ↑

iris.fileformats.grib.reset_load_rules()

Resets the GRIB load process to use only the standard conversion rules.

Deprecated since version 1.7.

↑ top ↑

iris.fileformats.grib.hindcast_workaround

Set this flag to True to enable support of negative forecast periods when loading and saving GRIB files.

Deprecated since version 1.10.