ants.fileformats.pp package#

This module includes utility functions for working with PP files for ancillary generation.

Loading PP data#

The following additional functionality is provided on load by ANTS:

  1. Pseudo-level order from the PP file is preserved.

ants.fileformats.pp.cube2pp(cube, field_coords=None)[source]#

Generates pp fields from a cube.

This is a wrapper around iris.fileformats.pp.as_fields(). In addition to that function, this ensures the horizontal coordinates are defined in the directions anticipated by the UM, identifies logical data, and applies fixes required for zonal mean data.

Parameters:
  • cube (iris.cube.Cube) – Cube to convert into pp fields.

  • field_coords (list of 2 iris.coords.Coord instances or list of 2 str coordinate names, optional.) – The coordinates to use to reduce the cube into 2D slices. Passed directly to iris.fileformats.pp.as_fields(). If not provided, this is automatically determined from the cube dimension coordinates if possible.

Returns:

The fields generated from the cube. Note that due to processing requirements, this is a list, rather than the generator returned by iris.fileformats.pp.as_fields().

Return type:

list of iris.fileformats.pp.PPField

Raises:
  • RuntimeError – If the cube has more than time based coordinate.

  • ValueError – If the cube has a time coordinate with a year of zero.

  • ValueError – If the cube has contradictory valid_range and valid_min/valid_max attributes.

ants.fileformats.pp.field_filter(fields, stash)[source]#

Return only those fields with the given stash code.

Parameters:
Returns:

List of fields with requested stash code.

Return type:

iris.fileformats.pp.PPField

Notes

The model identifier is ignored in the comparison when it has a value of 0. This is due to the commonly missing model identifier in existing fields.

ants.fileformats.pp.field_filter_strict(*args, **kwargs)[source]#

Return the sole field matching the given stash code.

Arguments are passed straight to field_filter().

Returns:

Single field with requested stash code.

Return type:

iris.fileformats.pp.PPField

Raises:

RuntimeError – if more than one field has the given stash code.

See also

field_filter()

ants.fileformats.pp.load_cubes(*args, **kwargs)[source]#

Loads cubes from a list of pp filenames.

This function acts as a wrapper to iris.fileformats.pp.load_cubes().

ants.fileformats.pp.load_cubes_little_endian(*args, **kwargs)[source]#

Loads cubes from a list of pp filenames.

This function acts as a wrapper to iris.fileformats.pp.load_cubes().

ants.fileformats.pp.load_ppfields(*args, **kwargs)[source]#

Read PPFields from on or more files.

Parameters:

filenames (str or Iterable of str) – One or more filenames to load.

Returns:

The pp fields from all files read.

Return type:

Iterator

Notes

This function differs from iris.fileformats.pp.load() by supporting multiple file names on input.

ants.fileformats.pp.pp2cubes(fields)[source]#

Convert ppfields to cube(s).

Parameters:

fields (iris.fileformats.pp.PPField) – A single pp field or an iterator of pp fields to convert to one or more cubes.

Returns:

The cubes derived from the pp fields.

Return type:

iris.cube.CubeList

Notes

At time of writing there was no iris implementation of this function. This implementation will be retired when the iris implementation is complete.