grib templates

templates.builtin

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

Bases: IndexTemplateProvider

Builtin templates provider.

Initialize the index template provider.

Parameters:
  • manager (TemplateManager) – The manager for the template provider.

  • index (str | list) – The path to the index.yaml file, or its contents directly as a list.

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.

Initialize the template provider.

Parameters:
  • manager (TemplateManager) – The manager for the template provider.

  • **fallback (dict[str, str]) – A mapping of output to input variable names to use as templates from the input, used as fallback when the output variable is not present in the input state (e.g., for diagnostic variables).

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.

Initialize the TemplateManager.

Parameters:
  • owner (Output) – The owner of the TemplateManager.

  • templates (Optional[Union[List[str], str]], optional) – A list of template providers or a single provider, by default None.

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.

Initialize the index template provider.

Parameters:
  • manager (TemplateManager) – The manager for the template provider.

  • index (str | list) – The path to the index.yaml file, or its contents directly as a list.

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]