Skip to content

Commit d3a26ae

Browse files
committed
Update test to use fesom download
Also move the data to a pytest fixture :)
1 parent 3906a91 commit d3a26ae

File tree

2 files changed

+24
-46
lines changed

2 files changed

+24
-46
lines changed

parcels/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(
143143
self,
144144
name: str,
145145
data: xr.DataArray | ux.UxDataArray,
146-
grid: ux.UxGrid | None = None, # To do : Once parcels.Grid class is added, allow for it to be passed here
146+
grid: ux.Grid | None = None, # To do : Once parcels.Grid class is added, allow for it to be passed here
147147
mesh_type: Mesh = "flat",
148148
interp_method: Callable | None = None,
149149
allow_time_extrapolation: bool | None = None,

tests/v4/test_uxarray_fieldset.py

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import os
21
from datetime import timedelta
32

3+
import pytest
44
import uxarray as ux
55

66
from parcels import (
@@ -9,70 +9,48 @@
99
ParticleSet,
1010
UXPiecewiseConstantFace,
1111
UXPiecewiseLinearNode,
12+
download_example_dataset,
1213
)
1314

14-
# Get path of this script
15-
V4_TEST_DATA = f"{os.path.dirname(__file__)}/test_data"
1615

17-
18-
def test_fesom_fieldset():
19-
# Load a FESOM dataset
20-
grid_path = f"{V4_TEST_DATA}/fesom_channel.nc"
16+
@pytest.fixture
17+
def ds_fesom_channel() -> ux.UxDataset:
18+
fesom_path = download_example_dataset("FESOM_periodic_channel")
19+
grid_path = f"{fesom_path}/fesom_channel.nc"
2120
data_path = [
22-
f"{V4_TEST_DATA}/u.fesom_channel.nc",
23-
f"{V4_TEST_DATA}/v.fesom_channel.nc",
24-
f"{V4_TEST_DATA}/w.fesom_channel.nc",
21+
f"{fesom_path}/u.fesom_channel.nc",
22+
f"{fesom_path}/v.fesom_channel.nc",
23+
f"{fesom_path}/w.fesom_channel.nc",
2524
]
26-
ds = ux.open_mfdataset(grid_path, data_path)
27-
ds = ds.rename_vars({"u": "U", "v": "V", "w": "W"})
28-
fieldset = FieldSet([ds])
25+
ds = ux.open_mfdataset(grid_path, data_path).rename_vars({"u": "U", "v": "V", "w": "W"})
26+
return ds.copy(deep=True)
27+
28+
29+
def test_fesom_fieldset(ds_fesom_channel):
30+
fieldset = FieldSet([ds_fesom_channel])
2931
fieldset._check_complete()
3032
# Check that the fieldset has the expected properties
31-
assert fieldset.datasets[0] == ds
33+
assert fieldset.datasets[0] == ds_fesom_channel
3234

3335

34-
def test_fesom_in_particleset():
35-
grid_path = f"{V4_TEST_DATA}/fesom_channel.nc"
36-
data_path = [
37-
f"{V4_TEST_DATA}/u.fesom_channel.nc",
38-
f"{V4_TEST_DATA}/v.fesom_channel.nc",
39-
f"{V4_TEST_DATA}/w.fesom_channel.nc",
40-
]
41-
ds = ux.open_mfdataset(grid_path, data_path)
42-
ds = ds.rename_vars({"u": "U", "v": "V", "w": "W"})
43-
fieldset = FieldSet([ds])
36+
def test_fesom_in_particleset(ds_fesom_channel):
37+
fieldset = FieldSet([ds_fesom_channel])
4438
# Check that the fieldset has the expected properties
45-
assert fieldset.datasets[0] == ds
39+
assert fieldset.datasets[0] == ds_fesom_channel
4640
pset = ParticleSet(fieldset, pclass=Particle)
4741
assert pset.fieldset == fieldset
4842

4943

50-
def test_set_interp_methods():
51-
grid_path = f"{V4_TEST_DATA}/fesom_channel.nc"
52-
data_path = [
53-
f"{V4_TEST_DATA}/u.fesom_channel.nc",
54-
f"{V4_TEST_DATA}/v.fesom_channel.nc",
55-
f"{V4_TEST_DATA}/w.fesom_channel.nc",
56-
]
57-
ds = ux.open_mfdataset(grid_path, data_path)
58-
ds = ds.rename_vars({"u": "U", "v": "V", "w": "W"})
59-
fieldset = FieldSet([ds])
44+
def test_set_interp_methods(ds_fesom_channel):
45+
fieldset = FieldSet([ds_fesom_channel])
6046
# Set the interpolation method for each field
6147
fieldset.U.interp_method = UXPiecewiseConstantFace
6248
fieldset.V.interp_method = UXPiecewiseConstantFace
6349
fieldset.W.interp_method = UXPiecewiseLinearNode
6450

6551

66-
def test_fesom_channel():
67-
grid_path = f"{V4_TEST_DATA}/fesom_channel.nc"
68-
data_path = [
69-
f"{V4_TEST_DATA}/u.fesom_channel.nc",
70-
f"{V4_TEST_DATA}/v.fesom_channel.nc",
71-
f"{V4_TEST_DATA}/w.fesom_channel.nc",
72-
]
73-
ds = ux.open_mfdataset(grid_path, data_path)
74-
ds = ds.rename_vars({"u": "U", "v": "V", "w": "W"})
75-
fieldset = FieldSet([ds])
52+
def test_fesom_channel(ds_fesom_channel):
53+
fieldset = FieldSet([ds_fesom_channel])
7654
# Set the interpolation method for each field
7755
fieldset.U.interp_method = UXPiecewiseConstantFace
7856
fieldset.V.interp_method = UXPiecewiseConstantFace

0 commit comments

Comments
 (0)