Skip to content

Adding axes and get_axis_dim to BaseGrid #2056

@VeckoTheGecko

Description

@VeckoTheGecko

In essene, ravelling and unravelling needs to know two things:

  • Which axes are part of the grid
  • How to get the dimensionality of an axis (i.e., how many observations/cell edges are there along a dimension)

Once that is known (and now that #2048 unifies the API for ravel/unravel across grids) the algorithm for ravelling and unravelling grids is the same regardless of grid.

I propose we make the following changes to BaseGrid:

  • add a grid.axes cached property that needs to be defined on the subclasses that returns a tuple[GridAxis] (where GridAxis is a string) listing the axes names for the grid. Implementation lies on the subclasses.
  • add a get_axis_dim(axis: GridAxes) -> int function that gives the dimensionality along a dimension (returning None for values not in grid.axes). Implementation lies on the subclasses. An lru_cache can be added to this method.
  • move the ravel/unravel logic from the subclasses to the Base class
  • remove xdim/ydim/zdim/tdim from the XGrid class (and from Field), as they can be replaced with grid.get_axis_dim("X") etc.
    • these attributes were at first only for backwards compatibility with v3

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions