Skip to content

Commit 89dcfd7

Browse files
committed
Add ds_2d_right dataset to structured.generic
With tests
1 parent 7c4e9b3 commit 89dcfd7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

parcels/_datasets/structured/generic.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,47 @@ def _unrolled_cone_curvilinear_grid():
178178
"time": (["time"], TIME, {"axis": "T"}),
179179
},
180180
),
181+
"ds_2d_right": xr.Dataset(
182+
{
183+
"data_g": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
184+
"data_c": (["time", "ZC", "YC", "XC"], np.random.rand(T, Z, Y, X)),
185+
"U (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
186+
"V (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
187+
"U (C grid)": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
188+
"V (C grid)": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
189+
},
190+
coords={
191+
"XG": (
192+
["XG"],
193+
2 * np.pi / X * np.arange(0, X),
194+
{"axis": "X", "c_grid_axis_shift": 0.5},
195+
),
196+
"XC": (["XC"], 2 * np.pi / X * (np.arange(0, X) - 0.5), {"axis": "X"}),
197+
"YG": (
198+
["YG"],
199+
2 * np.pi / (Y) * np.arange(0, Y),
200+
{"axis": "Y", "c_grid_axis_shift": 0.5},
201+
),
202+
"YC": (
203+
["YC"],
204+
2 * np.pi / (Y) * (np.arange(0, Y) - 0.5),
205+
{"axis": "Y"},
206+
),
207+
"ZG": (
208+
["ZG"],
209+
np.arange(Z),
210+
{"axis": "Z", "c_grid_axis_shift": 0.5},
211+
),
212+
"ZC": (
213+
["ZC"],
214+
np.arange(Z) - 0.5,
215+
{"axis": "Z"},
216+
),
217+
"lon": (["XG"], 2 * np.pi / X * np.arange(0, X)),
218+
"lat": (["YG"], 2 * np.pi / (Y) * np.arange(0, Y)),
219+
"depth": (["ZG"], np.arange(Z)),
220+
"time": (["time"], TIME, {"axis": "T"}),
221+
},
222+
),
181223
"2d_left_unrolled_cone": _unrolled_cone_curvilinear_grid(),
182224
}

tests/v4/test_datasets.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from parcels._datasets.structured.generic import datasets
2+
from parcels.xgcm import Grid
3+
4+
5+
def test_left_indexed_dataset():
6+
"""Checks that 'ds_2d_left' is right indexed on all variables."""
7+
ds = datasets["ds_2d_left"]
8+
grid = Grid(ds)
9+
10+
for _axis_name, axis in grid.axes.items():
11+
for pos, _dim_name in axis.coords.items():
12+
assert pos in ["left", "center"]
13+
14+
15+
def test_right_indexed_dataset():
16+
"""Checks that 'ds_2d_right' is right indexed on all variables."""
17+
ds = datasets["ds_2d_right"]
18+
grid = Grid(ds)
19+
for _axis_name, axis in grid.axes.items():
20+
for pos, _dim_name in axis.coords.items():
21+
assert pos in ["center", "right"]

0 commit comments

Comments
 (0)