parcels icon indicating copy to clipboard operation
parcels copied to clipboard

Adding `axes` and `get_axis_dim` to BaseGrid

Open VeckoTheGecko opened this issue 8 months ago • 1 comments

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
  • 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

VeckoTheGecko avatar Jun 30 '25 09:06 VeckoTheGecko

It also looks like as part of compatibility with v3 we have Field.lon and Field.lat and Field.depth - these can also go as part of this PR - there are no more references to these attributes.

VeckoTheGecko avatar Jun 30 '25 12:06 VeckoTheGecko