earthkit.data.readers.xarray.flavour

Classes

CoordinateAttributes

A dictionary that allows access to its keys as attributes.

CoordinateGuesser

Class to guess the type of coordinates in a dataset.

DefaultCoordinateGuesser

Default implementation of CoordinateGuesser.

FlavourCoordinateGuesser

Implementation of CoordinateGuesser that uses a flavour for guessing.

Module Contents

class earthkit.data.readers.xarray.flavour.CoordinateAttributes(*args, **kwargs)

Bases: earthkit.data.utils.dotdict.DotDict

A dictionary that allows access to its keys as attributes.

>>> d = DotDict({"a": 1, "b": {"c": 2}})
>>> d.a
1
>>> d.b.c
2
>>> d.b = 3
>>> d.b
3

The class is recursive, so nested dictionaries are also DotDicts.

The DotDict class has the same constructor as the dict class.

>>> d = DotDict(a=1, b=2)
classmethod from_file(path)

Create a DotDict from a file.

Parameters:

path (str) – The path to the file.

Returns:

The created DotDict.

Return type:

DotDict

classmethod from_json_file(path)

Create a DotDict from a JSON file.

Parameters:

path (str) – The path to the JSON file.

Returns:

The created DotDict.

Return type:

DotDict

classmethod from_toml_file(path)

Create a DotDict from a TOML file.

Parameters:

path (str) – The path to the TOML file.

Returns:

The created DotDict.

Return type:

DotDict

classmethod from_yaml_file(path)

Create a DotDict from a YAML file.

Parameters:

path (str) – The path to the YAML file.

Returns:

The created DotDict.

Return type:

DotDict

class earthkit.data.readers.xarray.flavour.CoordinateGuesser(ds)

Bases: abc.ABC

Class to guess the type of coordinates in a dataset.

ds
classmethod from_flavour(ds, flavour)

Creates a CoordinateGuesser from a flavour.

Parameters:
  • ds (xr.Dataset) – The dataset to guess coordinates from.

  • flavour (Optional[Dict[str, Any]]) – The flavour to use for guessing.

Returns:

The created CoordinateGuesser.

Return type:

CoordinateGuesser

grid(coordinates, variable)

Determines the grid type for the given coordinates and variable.

Parameters:
  • coordinates (Any) – The coordinates to determine the grid from.

  • variable (Any) – The variable to determine the grid from.

Returns:

The determined grid type.

Return type:

Any

guess(c, coord)

Guesses the type of a coordinate.

Parameters:
  • c (xr.DataArray) – The coordinate to guess.

  • coord (Hashable) – The name of the coordinate.

Returns:

The guessed coordinate type.

Return type:

Coordinate

class earthkit.data.readers.xarray.flavour.DefaultCoordinateGuesser(ds)

Bases: CoordinateGuesser

Default implementation of CoordinateGuesser.

ds
classmethod from_flavour(ds, flavour)

Creates a CoordinateGuesser from a flavour.

Parameters:
  • ds (xr.Dataset) – The dataset to guess coordinates from.

  • flavour (Optional[Dict[str, Any]]) – The flavour to use for guessing.

Returns:

The created CoordinateGuesser.

Return type:

CoordinateGuesser

grid(coordinates, variable)

Determines the grid type for the given coordinates and variable.

Parameters:
  • coordinates (Any) – The coordinates to determine the grid from.

  • variable (Any) – The variable to determine the grid from.

Returns:

The determined grid type.

Return type:

Any

guess(c, coord)

Guesses the type of a coordinate.

Parameters:
  • c (xr.DataArray) – The coordinate to guess.

  • coord (Hashable) – The name of the coordinate.

Returns:

The guessed coordinate type.

Return type:

Coordinate

class earthkit.data.readers.xarray.flavour.FlavourCoordinateGuesser(ds, flavour)

Bases: CoordinateGuesser

Implementation of CoordinateGuesser that uses a flavour for guessing.

ds
flavour
classmethod from_flavour(ds, flavour)

Creates a CoordinateGuesser from a flavour.

Parameters:
  • ds (xr.Dataset) – The dataset to guess coordinates from.

  • flavour (Optional[Dict[str, Any]]) – The flavour to use for guessing.

Returns:

The created CoordinateGuesser.

Return type:

CoordinateGuesser

grid(coordinates, variable)

Determines the grid type for the given coordinates and variable.

Parameters:
  • coordinates (Any) – The coordinates to determine the grid from.

  • variable (Any) – The variable to determine the grid from.

Returns:

The determined grid type.

Return type:

Any

guess(c, coord)

Guesses the type of a coordinate.

Parameters:
  • c (xr.DataArray) – The coordinate to guess.

  • coord (Hashable) – The name of the coordinate.

Returns:

The guessed coordinate type.

Return type:

Coordinate