meteodatalab.grib_decoder

Decoder for grib data.

Functions

get_code_flag(value, indices)

Get the code flag value at the given indices.

load(source, request)

Request data from a data source.

load_single_param(source, request)

Request data from a data source for a single parameter.

save(field, file_handle[, bits_per_value])

Write field to file in GRIB format.

set_code_flag(indices)

Create code flag by setting bits at the given indices.

Classes

ChainMap(*maps)

GribField(*args, **kwargs)

GribReader(source[, ref_param])

UnitOfTime(value[, names, module, qualname, ...])

Exceptions

class meteodatalab.grib_decoder.ChainMap(*maps)[source]
class meteodatalab.grib_decoder.GribField(*args, **kwargs)[source]
exception meteodatalab.grib_decoder.MissingData[source]
class meteodatalab.grib_decoder.UnitOfTime(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
meteodatalab.grib_decoder.get_code_flag(value: int, indices: Sequence[int]) list[bool][source]

Get the code flag value at the given indices.

Parameters:
  • value (int) – The code flag as an integer in the [0, 255] range.

  • indices (Sequence[int]) – Indices at which to get the flag values. Left to right, 1-based.

Returns:

The code flag values at the given indices.

Return type:

list[bool]

meteodatalab.grib_decoder.load(source: DataSource, request: str | tuple | dict | Request) dict[str, DataArray][source]

Request data from a data source.

Parameters:
  • source (data_source.DataSource) – Source to request the data from.

  • request (str | tuple[str, str] | dict[str, Any] | meteodatalab.mars.Request) – Request for data from the source in the mars language.

Raises:

RuntimeError – when all of the requested data is not returned from the data source.

Returns:

A mapping of shortName to data arrays of the requested fields.

Return type:

dict[str, xarray.DataArray]

meteodatalab.grib_decoder.load_single_param(source: DataSource, request: str | tuple | dict | Request) DataArray[source]

Request data from a data source for a single parameter.

Parameters:
  • source (data_source.DataSource) – Source to request the data from.

  • request (str | tuple[str, str] | dict[str, Any] | meteodatalab.mars.Request) – Request for data from the source in the mars language.

Raises:
  • ValueError – if more than one param is present in the request.

  • RuntimeError – when all of the requested data is not returned from the data source.

Returns:

A data array of the requested field.

Return type:

xarray.DataArray

meteodatalab.grib_decoder.save(field: DataArray, file_handle: BufferedWriter | BytesIO, bits_per_value: int = 16)[source]

Write field to file in GRIB format.

Parameters:
  • field (xarray.DataArray) – Field to write into the output file.

  • file_handle (io.BufferedWriter) – File handle for the output file.

  • bits_per_value (int, optional) – Bits per value encoded in the output file. (Default: 16)

Raises:

ValueError – If the field does not have a message attribute.

meteodatalab.grib_decoder.set_code_flag(indices: Sequence[int]) int[source]

Create code flag by setting bits at the given indices.

Parameters:

indices (Sequence[int]) – Indices at which to set the flag values. Left to right, 1-based.

Returns:

Code flag with bits set at the given indices.

Return type:

int