Grid metadata for Arakawa A- and C-grid forcing layouts.
The Grid object describes the centre (tracer) coordinates of a
forcing dataset together with its stagger type, and — for C-grids — the
staggered U/V-face coordinates. It is the single owner of coordinates: it is
held on pastax.Dataset and every pastax.Field references it,
reading the coordinates appropriate to its stagger role via
Grid.coords_for().
Each Field therefore carries no coordinates of its own; interpolation
reads them from the shared Grid. This keeps the Field.interp path
(bilinear on equally-spaced coords) valid for both A- and C-grid fields, since
shifting an equally-spaced grid by half a cell preserves equal spacing.
Curvilinear (2-D) coordinate arrays are accepted structurally for forward compatibility but not yet supported by interpolation.
Grid¶
- class pastax.grid.Grid(t_coords, lat_coords, lon_coords, grid_type='rectilinear', stagger_type='A', lon_period=None, lon_closed=True, u_lat_coords=None, u_lon_coords=None, v_lat_coords=None, v_lon_coords=None)
Bases:
ModuleGrid metadata: centre coordinates plus stagger and topology type.
- Parameters
t_coords(Float[jaxlib._jax.Array,'time'])lat_coords(Float[jaxlib._jax.Array,'...'])lon_coords(Float[jaxlib._jax.Array,'...'])grid_type(Literal['rectilinear','curvilinear'])stagger_type(Literal['A','C'])lon_period(float|None)lon_closed(bool)u_lat_coords(Float[jaxlib._jax.Array,'...']|None)u_lon_coords(Float[jaxlib._jax.Array,'...']|None)v_lat_coords(Float[jaxlib._jax.Array,'...']|None)v_lon_coords(Float[jaxlib._jax.Array,'...']|None)
- t_coords
1-D time coordinates in seconds, equally spaced.
- Type
jaxtyping.Float[jaxlib._jax.Array, ‘time’]
- lat_coords
Latitude of cell centres. 1-D for rectilinear grids, 2-D
(lat, lon)for curvilinear grids.- Type
jaxtyping.Float[jaxlib._jax.Array, ‘…’]
- lon_coords
Longitude of cell centres. 1-D for rectilinear grids, 2-D
(lat, lon)for curvilinear grids.- Type
jaxtyping.Float[jaxlib._jax.Array, ‘…’]
- grid_type
"rectilinear"(default) or"curvilinear". Curvilinear grids are accepted structurally but not yet supported byField.interp.- Type
Literal[‘rectilinear’, ‘curvilinear’]
- stagger_type
"A"(default — all variables at cell centres) or"C"(NEMO-convention Arakawa C-grid: U on east faces, V on north faces).- Type
Literal[‘A’, ‘C’]
- lon_period
If set (e.g.
360.0), longitude is treated as periodic with that period. The grid then either spans exactly one period (a global grid — seelon_closed) or is a seam-crossing regional subset.- Type
float | None
- lon_closed
Whether a periodic (
lon_periodset) grid spans exactly one full period.True(default) is a closed global grid: the cell past the last centre is identified with the first and interpolation wraps ((i+1) % n).Falseis an open seam-crossing regional slab (e.g.170°…-170°): longitude is still circular for query folding, but the grid does not wrap — it behaves like a bounded grid withnlon - 1interior faces and extrapolates past its two ends. Derived at load fromnlon * dlonvslon_period; irrelevant whenlon_periodisNone.- Type
bool
- u_lat_coords, u_lon_coords
U-face coordinates (NEMO C-grid). Populated by the C-grid loaders (derived from the centre grid via
u_face_coords()or supplied explicitly);Noneon A-grids.
- v_lat_coords, v_lon_coords
V-face coordinates (NEMO C-grid). Populated by the C-grid loaders (derived via
v_face_coords()or supplied explicitly);Noneon A-grids.
- t_coords: Float[jaxlib._jax.Array, 'time']
- lat_coords: Float[jaxlib._jax.Array, '...']
- lon_coords: Float[jaxlib._jax.Array, '...']
- grid_type: Literal['rectilinear', 'curvilinear'] = 'rectilinear'
- stagger_type: Literal['A', 'C'] = 'A'
- lon_period: float | None = None
- lon_closed: bool = True
- u_lat_coords: Float[jaxlib._jax.Array, '...'] | None = None
- u_lon_coords: Float[jaxlib._jax.Array, '...'] | None = None
- v_lat_coords: Float[jaxlib._jax.Array, '...'] | None = None
- v_lon_coords: Float[jaxlib._jax.Array, '...'] | None = None
- u_face_coords()
Return
(lat_u, lon_u)— coordinates of U-face centres (NEMO C-grid).For a bounded centre grid of size
nlonin longitude, U lives on thenlon - 1interior east faces between adjacent cells:When
lon_periodis set and the grid is closed (lon_closed), the grid is a global periodic grid, so every centre cell has an east face — including the seam face between the last centre and the first-plus-a-period. There are thennlonU faces, each a half-cell east of its centre:This
nlon-face axis spans exactly one period, so U interpolation wraps across the seam with the same first-order periodic scheme used for centre fields (seeperiod_for()).An open seam-crossing regional grid (
lon_periodset butlon_closedfalse) has no wrap and therefore no seam face: like a bounded grid it hasnlon - 1interior east faces at the centre midpoints. The midpoints are correct because the centre longitudes are stored unwrapped (strictly ascending) by the loaders.Latitude is unchanged: .
- Raises
NotImplementedError– For curvilinear grids.- Return type
tuple[Float[jaxlib._jax.Array, ‘lat’], Float[jaxlib._jax.Array, ‘lon_u’]]
- v_face_coords()
Return
(lat_v, lon_v)— coordinates of V-face centres (NEMO C-grid).For a centre grid of size
nlatin latitude, V lives on thenlat - 1north faces between adjacent cells:Longitude is unchanged: .
- Raises
NotImplementedError– For curvilinear grids.- Return type
tuple[Float[jaxlib._jax.Array, ‘lat_v’], Float[jaxlib._jax.Array, ‘lon’]]
- coords_for(stagger)
Return the
(lat, lon)coordinates a field atstaggerreads."center"returns the centre (tracer) coordinates;"u_face"and"v_face"return the stored staggered coordinates (populated by the C-grid loaders). This is the single source of coordinates consulted bypastax.Field.interp().- Raises
ValueError– For"u_face"/"v_face"on a grid that carries no staggered coordinates, or for an unknownstagger.- Parameters
stagger(Literal['center','u_face','v_face'])- Return type
tuple[Float[jaxlib._jax.Array, ‘…’], Float[jaxlib._jax.Array, ‘…’]]
- period_for(stagger)
Return the longitude period a field at
staggershould use.Every stagger role inherits
lon_period: centre longitudes span one period by construction, V-face longitudes equal the centre longitudes, and periodic U faces are built seam-inclusive (nlonfaces spanning one period; seeu_face_coords()). Whenlon_periodisNoneall roles getNone(bounded grid, no wrapping). Latitude is never periodic, so this concerns only the longitude axis.- Parameters
stagger(Literal['center','u_face','v_face'])- Return type
float | None
- closed_for(stagger)
Return whether the longitude axis a field at
staggerreads is closed.Every stagger role inherits the centre grid’s
lon_closed: a U/V face of an open (seam-crossing) centre grid is itself an open interior axis, and the faces of a closed global grid are closed. Only meaningful together with a non-Noneperiod_for(); on a bounded grid the value is ignored.- Parameters
stagger(Literal['center','u_face','v_face'])- Return type
bool