mule.lbc

This module provides a class for interacting with LBC files.

class mule.lbc.LBC_IntegerConstants(values)[source]

Bases: IntegerConstants

The integer constants component of a UM LBC File.

HEADER_MAPPING = [('num_times', 3), ('num_cols', 6), ('num_rows', 7), ('num_p_levels', 8), ('num_wet_levels', 9), ('num_field_types', 15), ('height_algorithm', 17), ('integer_mdi', 21), ('first_constant_rho', 24)]

A list containing a series of tuple-pairs; the raw value of an index in the header, and a named-attribute to associate with it (see the help for the _HeaderMetaclass for further details).

CREATE_DIMS = (46,)

A tuple defining the default dimensions of the header to be produced by the empty() method, when the caller provides incomplete shape information. Where an element of the tuple is “None”, the arguments to the empty method must specify a size for the corresponding dimension.

class mule.lbc.LBC_RealConstants(values)[source]

Bases: RealConstants

The real constants component of a UM LBC File.

HEADER_MAPPING = [('col_spacing', 1), ('row_spacing', 2), ('start_lat', 3), ('start_lon', 4), ('north_pole_lat', 5), ('north_pole_lon', 6), ('atmos_year', 8), ('atmos_day', 9), ('atmos_hour', 10), ('atmos_minute', 11), ('atmos_second', 12), ('top_theta_height', 16), ('mean_diabatic_flux', 18), ('mass', 19), ('energy', 20), ('energy_drift', 21), ('real_mdi', 29)]

A list containing a series of tuple-pairs; the raw value of an index in the header, and a named-attribute to associate with it (see the help for the _HeaderMetaclass for further details).

CREATE_DIMS = (38,)

A tuple defining the default dimensions of the header to be produced by the empty() method, when the caller provides incomplete shape information. Where an element of the tuple is “None”, the arguments to the empty method must specify a size for the corresponding dimension.

class mule.lbc.LBC_LevelDependentConstants(values)[source]

Bases: LevelDependentConstants

The level dependent constants component of a UM LBC File.

HEADER_MAPPING = [('eta_at_theta', (slice(None, None, None), 1)), ('eta_at_rho', (slice(None, None, None), 2)), ('rhcrit', (slice(None, None, None), 3)), ('soil_thickness', (slice(None, None, None), 4))]

A list containing a series of tuple-pairs; the raw value of an index in the header, and a named-attribute to associate with it (see the help for the _HeaderMetaclass for further details).

CREATE_DIMS = (None, 4)

A tuple defining the default dimensions of the header to be produced by the empty() method, when the caller provides incomplete shape information. Where an element of the tuple is “None”, the arguments to the empty method must specify a size for the corresponding dimension.

class mule.lbc.LBC_RowDependentConstants(values)[source]

Bases: RowDependentConstants

The row dependent constants component of a UM LBC File.

HEADER_MAPPING = [('phi_p', (slice(None, None, None), 1)), ('phi_v', (slice(None, None, None), 2))]

A list containing a series of tuple-pairs; the raw value of an index in the header, and a named-attribute to associate with it (see the help for the _HeaderMetaclass for further details).

CREATE_DIMS = (None, 2)

A tuple defining the default dimensions of the header to be produced by the empty() method, when the caller provides incomplete shape information. Where an element of the tuple is “None”, the arguments to the empty method must specify a size for the corresponding dimension.

class mule.lbc.LBC_ColumnDependentConstants(values)[source]

Bases: ColumnDependentConstants

The column dependent constants component of a UM LBC File.

HEADER_MAPPING = [('lambda_p', (slice(None, None, None), 1)), ('lambda_u', (slice(None, None, None), 2))]

A list containing a series of tuple-pairs; the raw value of an index in the header, and a named-attribute to associate with it (see the help for the _HeaderMetaclass for further details).

CREATE_DIMS = (None, 2)

A tuple defining the default dimensions of the header to be produced by the empty() method, when the caller provides incomplete shape information. Where an element of the tuple is “None”, the arguments to the empty method must specify a size for the corresponding dimension.

class mule.lbc._ReadLBCProviderUnpacked(source, sourcefile, offset)[source]

Bases: RawReadProvider

A mule.RawReadProvider which reads an unpacked field.

class mule.lbc._ReadLBCProviderCray32Packed(source, sourcefile, offset)[source]

Bases: _ReadLBCProviderUnpacked

A mule.RawReadProvider which reads a Cray32-bit packed field.

class mule.lbc._WriteLBCOperatorUnpacked[source]

Bases: object

Formats the data array from a field into bytes suitable to be written into the output file, as unpacked LBC data.

class mule.lbc._WriteLBCOperatorCray32Packed[source]

Bases: _WriteLBCOperatorUnpacked

Formats the data array from a field into bytes suitable to be written into the output file, as Cray32-bit packed LBC data.

class mule.lbc.LBCToMaskedArrayOperator[source]

Bases: DataOperator

A special mule.DataOperator provided with the LBC class - this will transform the 1-dimensional LBC array into a masked 3-d array where the points in the center of the domain are missing.

Note

In order to write this back out as an LBC it will need to additionally pass through the converse MaskedArrayToLBCOperator.

__init__()[source]

Initialise the operator object.

new_field(field)[source]

Create a copy of the source field object.

Args:
  • field:

    The mule.Field object to attach the operator to when it is called.

transform(source_field, result_field)[source]

Retrieve the data from the original mule.Field object, and construct a masked 3-d data array to return.

Args:
  • source_field:

    The mule.Field object which contains the means to extract the original data.

Note

This method should not be called directly; it will be called by the “get_data” method of the mule.Field object this operator has been attached to.

class mule.lbc.MaskedArrayToLBCOperator[source]

Bases: DataOperator

A special mule.DataOperator provided with the LBC class - this will transform the masked 3-d array produced by wrapping an LBC field in the LBCToMaskedArrayOperator class back into a 1-d LBC array.

__init__()[source]

Initialise the operator object.

new_field(field)[source]

Create a copy of the source field object.

Args:
  • field:

    The mule.Field object to attach the operator to when it is called.

    This object is assumed to be the result of applying the LBCToMaskedArrayOperator to an LBC field. It will return a field object which reverts the transformation provided by that operator.

transform(source_field, result_field)[source]

Retrieve the masked 3-d array from the mule.Field object and revert it to a sequential 1-d LBC array.

Args:
  • source_field:

    The mule.Field object which returns the masked 3-d array.

Note

This method should not be called directly; it will be called by the “get_data” method of the mule.Field object this operator has been attached to.

class mule.lbc.LBCFile[source]

Bases: UMFile

Represents a single UM LBC File.

COMPONENTS = (('integer_constants', <class 'mule.lbc.LBC_IntegerConstants'>), ('real_constants', <class 'mule.lbc.LBC_RealConstants'>), ('level_dependent_constants', <class 'mule.lbc.LBC_LevelDependentConstants'>), ('row_dependent_constants', <class 'mule.lbc.LBC_RowDependentConstants'>), ('column_dependent_constants', <class 'mule.lbc.LBC_ColumnDependentConstants'>), ('additional_parameters', <class 'mule.UnsupportedHeaderItem2D'>), ('extra_constants', <class 'mule.UnsupportedHeaderItem1D'>), ('temp_historyfile', <class 'mule.UnsupportedHeaderItem1D'>), ('compressed_field_index1', <class 'mule.UnsupportedHeaderItem1D'>), ('compressed_field_index2', <class 'mule.UnsupportedHeaderItem1D'>), ('compressed_field_index3', <class 'mule.UnsupportedHeaderItem1D'>))

A series of tuples containing the name of a header component, and the class which should be used to represent it. The name will become the final attribute name to store the component, but it must also correspond to a name in the HEADER_MAPPING of the fixed length header.

READ_PROVIDERS = {'000': <class 'mule.lbc._ReadLBCProviderUnpacked'>, '002': <class 'mule.lbc._ReadLBCProviderCray32Packed'>}

A dictionary which maps a string containing the trailing 3 digits (n3 - n1) of a field’s lbpack (packing code) onto a suitable data-provider object to read the field. Any packing code not in this list will default to using a _NullReadProvider object (which can only be used to copy the raw byte-data of the field - not to unpack it or access the data).

WRITE_OPERATORS = {'000': <class 'mule.lbc._WriteLBCOperatorUnpacked'>, '002': <class 'mule.lbc._WriteLBCOperatorCray32Packed'>}

A dictionary which maps a string containing the trailing 3 digits (n3 - n1) of a field’s lbpack (packing code) onto a suitable DataOperator object to write the field. Any packing code found in a field from this object’s field list but not found here will cause an exception when trying to write to a file.

validate(filename=None, warn=False, GridArakawaA=False)

Main validation method, ensures that certain quantities are the expected sizes and different header quantities are self-consistent.

Kwargs:
  • filename:

    If provided, this filename will be included in any validation error messages raised by this method.

  • warn:

    If True, issue a warning rather than a failure in the event that the object fails to validate.

  • GridArakawaA:

    If True, switch validation to use grid staggering allowed in GRIB files - namely Arakawa A grids

_write_to_file(output_file)[source]

Write out to an open output file.