pre_processors

extract

class anemoi.inference.pre_processors.extract.ExtractBase(context: Context, metadata: Metadata)

Bases: Processor

Base class for pre-processors that extract data from the state.

property indexer: ndarray[tuple[Any, ...], dtype[Any]] | slice
process(state: dict[str, Any]) → dict[str, Any]

Process the state to extract a subset of points based on the indexer.

class anemoi.inference.pre_processors.extract.ExtractSlice(context: Context, metadata: Metadata, *slice_args: int)

Bases: ExtractBase

Extract a subset of points from the state based on a slice.

Parameters:
  • context (Context) – The context in which the processor is running.

  • metadata (Metadata) – Metadata corresponding to the dataset this processor is handling.

  • slice_args (int) – Arguments to create a slice object. This can be a single integer or a tuple of integers representing the start, stop, and step of the slice.

forward_transform_filter

mask

class anemoi.inference.pre_processors.mask.MaskValues(context: Context, *, mask: str, param: str | list[str], **kwargs)

Bases: Processor

Replace values in a field with nans from a specified mask in the supporting arrays.

Initialize the MaskValues processor.

Parameters:
  • context (Context) – The context in which the processor operates.

  • mask (str) – The mask to apply to the fields from the supporting arrays or a path to a mask file. Can be npy, grib, or netCDF file.

  • param (str or list of str) – The parameter(s) to which the mask should be applied.

  • kwargs (Any) – Additional keyword arguments to pass to the apply_mask_to_param filter. - mask_value: The value in the mask that indicates where to apply the mask (default: None). - threshold_operator: The operator to use for thresholding the mask if using a threshold (default: None). - threshold: The threshold value for the mask if using operator (default: None).

process(state: dict[str, Any]) → dict[str, Any]

Apply the mask to the specified parameters in the state.

Parameters:

state (State) – The state containing the fields to be masked.

Returns:

The state with the specified parameters masked.

Return type:

State

no_missing_values

class anemoi.inference.pre_processors.no_missing_values.NoMissingValues(context: Context, metadata: Metadata, **kwargs: Any)

Bases: Processor

Replace NaNs with mean.

Initialize the NoMissingValues processor.

Parameters:
  • context (Context) – The context in which the processor operates.

  • metadata (Metadata) – Metadata corresponding to the dataset this processor is handling.

  • kwargs (Any) – Additional keyword arguments.

process(state: dict[str, Any]) → dict[str, Any]

Process the fields to replace NaNs with the mean value.

Parameters:

state (State) – The state to process.

Returns:

List of processed state with NaNs replaced by the mean value.

Return type:

list