grib templates

templates.builtin

class anemoi.inference.grib.templates.builtin.BuiltinTemplates(manager: TemplateManager, index_path: str | None = None)

Bases: IndexTemplateProvider

Builtin templates provider.

load_template(grib: str, lookup: dict[str, Any]) Field | None

Load the template for the given GRIB and lookup.

Parameters:
  • grib (str) – The GRIB string.

  • lookup (Dict[str, Any]) – The lookup dictionary.

Returns:

The loaded template field if found, otherwise None.

Return type:

Optional[ekd.Field]

templates.file

templates.input

class anemoi.inference.grib.templates.input.InputTemplates(manager: TemplateManager, **fallback: dict[str, str])

Bases: TemplateProvider

Use input fields as the output GRIB template.

template(variable: str, lookup: dict[str, Any], *, state: dict[str, Any], **kwargs) Field | None

Get the template for the given variable and lookup.

Parameters:
  • variable (str) – The variable to get the template for.

  • lookup (Dict[str, Any]) – The lookup dictionary.

  • kwargs – Extra arguments for specific template providers.

Returns:

The template field.

Return type:

ekd.Field | None

templates.manager

class anemoi.inference.grib.templates.manager.TemplateManager(owner: Output, templates: list[str] | str | None = None)

Bases: object

A class to manage GRIB template providers.

log_summary() None

Log a summary of the loaded templates. Repeated calls will only log newly loaded templates since the last call.

template(name: str, state: dict[str, Any], typed_variables: dict[str, Any]) Field | None

Get the template for a given name and state.

Parameters:
  • name (str) – The name of the template.

  • state (State) – The state object containing template information.

  • typed_variables (dict[str, Any]) – The dictionary of typed variables.

Returns:

The template field if found, otherwise None.

Return type:

Optional[ekd.Field]

load_template(name: str, state: dict[str, Any], typed_variables: dict[str, Any]) Field | None

Load the template for a given name and state.

Parameters:
  • name (str) – The name of the template.

  • state (State) – The state object containing template information.

  • typed_variables (dict[str, Any]) – The dictionary of typed variables.

Returns:

The template field if found, otherwise None.

Return type:

Optional[ekd.Field]

templates.samples

class anemoi.inference.grib.templates.samples.SamplesTemplates(manager: TemplateManager, *args, index_path: str | None = None)

Bases: IndexTemplateProvider

Class to provide GRIB templates from sample files.

load_template(grib: str, lookup: dict[str, Any]) Field | None

Load the template for the given GRIB and lookup.

Parameters:
  • grib (str) – The GRIB string.

  • lookup (Dict[str, Any]) – The lookup dictionary.

Returns:

The loaded template field if found, otherwise None.

Return type:

Optional[ekd.Field]