Skip to content

Commit 4491677

Browse files
committed
Rename GridAdapter to XGrid
This class now attaches Parcels specific functionality and methods to the original xgcm Grid
1 parent 042b7e5 commit 4491677

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

parcels/field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
VectorType,
1919
assert_valid_mesh,
2020
)
21-
from parcels.gridadapter import GridAdapter
21+
from parcels.gridadapter import XGrid
2222
from parcels.tools.converters import (
2323
UnitConverter,
2424
unitconverters_map,
@@ -177,7 +177,7 @@ def __init__(
177177
# For compatibility with parts of the codebase that rely on v3 definition of Grid.
178178
# Should be worked to be removed in v4
179179
if isinstance(grid, Grid):
180-
self.gridadapter = GridAdapter(grid)
180+
self.gridadapter = XGrid(grid)
181181
else:
182182
self.gridadapter = None
183183

parcels/gridadapter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ def get_time(axis: xgcm.Axis) -> npt.NDArray:
2929
return axis._ds[axis.coords["center"]].values
3030

3131

32-
class GridAdapter:
32+
class XGrid:
33+
"""
34+
Class to represent a structured grid in Parcels. Wraps a xgcm-like Grid object (we use a trimmed down version of the xgcm.Grid class that is vendored with Parcels).
35+
36+
This class provides methods and properties required for indexing and interpolating on the grid.
37+
"""
38+
3339
def __init__(self, grid: xgcm.Grid, mesh="flat"):
3440
self.grid = grid
3541
self.mesh = mesh

tests/v4/test_gridadapter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from parcels import xgcm
88
from parcels._datasets.structured.generic import T, X, Y, Z, datasets
99
from parcels.grid import Grid as OldGrid
10-
from parcels.gridadapter import GridAdapter
10+
from parcels.gridadapter import XGrid
1111
from parcels.tools.converters import TimeConverter
1212

1313
GridTestCase = namedtuple("GridTestCase", ["Grid", "attr", "expected"])
@@ -39,7 +39,7 @@ def assert_equal(actual, expected):
3939

4040
@pytest.mark.parametrize("ds, attr, expected", test_cases)
4141
def test_grid_adapter_properties_ground_truth(ds, attr, expected):
42-
adapter = GridAdapter(xgcm.Grid(ds, periodic=False))
42+
adapter = XGrid(xgcm.Grid(ds, periodic=False))
4343
actual = getattr(adapter, attr)
4444
assert_equal(actual, expected)
4545

@@ -61,7 +61,7 @@ def test_grid_adapter_properties_ground_truth(ds, attr, expected):
6161
)
6262
@pytest.mark.parametrize("ds", datasets.values())
6363
def test_grid_adapter_against_old(ds, attr):
64-
adapter = GridAdapter(xgcm.Grid(ds, periodic=False))
64+
adapter = XGrid(xgcm.Grid(ds, periodic=False))
6565

6666
grid = OldGrid.create_grid(
6767
lon=ds.lon.values,

0 commit comments

Comments
 (0)