Skip to content

String representations of SGRID layouts#2553

Merged
VeckoTheGecko merged 12 commits intoParcels-code:mainfrom
VeckoTheGecko:sgrid
Mar 25, 2026
Merged

String representations of SGRID layouts#2553
VeckoTheGecko merged 12 commits intoParcels-code:mainfrom
VeckoTheGecko:sgrid

Conversation

@VeckoTheGecko
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko commented Mar 24, 2026

I was doing some exploring of Xarray internals (i.e., using indices), and I quickly whipped this up so that we can visualise SGRID metadata that's attached to any dataset to help with my debugging.

Example:

In [1]: from parcels._core.utils import sgrid
   ...: from parcels._datasets.structured.generic import datasets_sgrid
   ...: ds = datasets_sgrid['ds_2d_padded_low']
   ...: metadata = sgrid.parse_grid_attrs(ds.grid.attrs)
   ...: print(metadata)
<ipython-input-1-860a92e3be2e>:1: UserWarning: This is an alpha version of Parcels v4. The API is not stable and may change without deprecation warnings.
  from parcels._core.utils import sgrid
Grid2DMetadata
  X-axis:  face='face_dimension1'  node='node_dimension1'  padding=low
  Y-axis:  face='face_dimension2'  node='node_dimension2'  padding=low
  Z-axis:  face='vertical_dimensions_dim2'  node='vertical_dimensions_dim1'  padding=low
  Coordinates: lon, lat

  Staggered grid layout (symbolic 3x3 nodes):

    ↑ YZ
    |                       |
    n --u-- n --u-- n       w
    |       |       |       |
    v   ·   v   ·   v       ·
    |       |       |       |
    n --u-- n --u-- n       w
    |       |       |       |
    v   ·   v   ·   v       ·
    |       |       |       |
    n --u-- n --u-- n --X w

  n = node  (node_dimension1, node_dimension2)
  u = x-face  (face_dimension1)
  v = y-face  (face_dimension2)
  w = z-node  (vertical_dimensions_dim1)
  · = cell centre

  Axis padding:

  face_dimension1:node_dimension1 (padding:low)
    ─────●─────●─────●─────●─────●
      1  1  2  2  3  3  4  4  5  5

  face_dimension2:node_dimension2 (padding:low)
    ─────●─────●─────●─────●─────●
      1  1  2  2  3  3  4  4  5  5

  vertical_dimensions_dim2:vertical_dimensions_dim1 (padding:low)
    ─────●─────●─────●─────●─────●
      1  1  2  2  3  3  4  4  5  5

Future work:

  • Explore how to more easily surface this to users (e.g., via an xarray accessor - print(ds.sgrid.metadata))
  • Integrate this into our documentation (i.e., using executed cells)

Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tool! Two small comments below

@VeckoTheGecko VeckoTheGecko merged commit 03fc33e into Parcels-code:main Mar 25, 2026
13 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Mar 25, 2026
@VeckoTheGecko VeckoTheGecko deleted the sgrid branch March 25, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants