-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathtest_uxarray_fieldset.py
More file actions
90 lines (71 loc) · 3.43 KB
/
test_uxarray_fieldset.py
File metadata and controls
90 lines (71 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from datetime import timedelta
import pytest
import uxarray as ux
from parcels import (
Field,
FieldSet,
Particle,
ParticleSet,
UXPiecewiseConstantFace,
UXPiecewiseLinearNode,
VectorField,
download_example_dataset,
)
@pytest.fixture
def ds_fesom_channel() -> ux.UxDataset:
fesom_path = download_example_dataset("FESOM_periodic_channel")
grid_path = f"{fesom_path}/fesom_channel.nc"
data_path = [
f"{fesom_path}/u.fesom_channel.nc",
f"{fesom_path}/v.fesom_channel.nc",
f"{fesom_path}/w.fesom_channel.nc",
]
ds = ux.open_mfdataset(grid_path, data_path).rename_vars({"u": "U", "v": "V", "w": "W"})
return ds
@pytest.fixture
def uv_fesom_channel(ds_fesom_channel) -> VectorField:
UV = VectorField(
name="UV",
U=Field(name="U", data=ds_fesom_channel.U, grid=ds_fesom_channel.uxgrid, interp_method=UXPiecewiseConstantFace),
V=Field(name="V", data=ds_fesom_channel.V, grid=ds_fesom_channel.uxgrid, interp_method=UXPiecewiseConstantFace),
)
return UV
@pytest.fixture
def uvw_fesom_channel(ds_fesom_channel) -> VectorField:
UVW = VectorField(
name="UVW",
U=Field(name="U", data=ds_fesom_channel.U, grid=ds_fesom_channel.uxgrid, interp_method=UXPiecewiseConstantFace),
V=Field(name="V", data=ds_fesom_channel.V, grid=ds_fesom_channel.uxgrid, interp_method=UXPiecewiseConstantFace),
W=Field(name="W", data=ds_fesom_channel.W, grid=ds_fesom_channel.uxgrid, interp_method=UXPiecewiseLinearNode),
)
return UVW
def test_fesom_fieldset(ds_fesom_channel, uv_fesom_channel):
fieldset = FieldSet([uv_fesom_channel, uv_fesom_channel.U, uv_fesom_channel.V])
# Check that the fieldset has the expected properties
assert (fieldset.fields["U"] == ds_fesom_channel.U).all()
assert (fieldset.fields["V"] == ds_fesom_channel.V).all()
@pytest.mark.skip(reason="ParticleSet.__init__ needs major refactoring")
def test_fesom_in_particleset(ds_fesom_channel, uv_fesom_channel):
fieldset = FieldSet([uv_fesom_channel, uv_fesom_channel.U, uv_fesom_channel.V])
# Check that the fieldset has the expected properties
assert (fieldset.fields["U"] == ds_fesom_channel.U).all()
assert (fieldset.fields["V"] == ds_fesom_channel.V).all()
pset = ParticleSet(fieldset, pclass=Particle)
assert pset.fieldset == fieldset
def test_set_interp_methods(ds_fesom_channel, uv_fesom_channel):
fieldset = FieldSet([uv_fesom_channel, uv_fesom_channel.U, uv_fesom_channel.V])
# Check that the fieldset has the expected properties
assert (fieldset.fields["U"] == ds_fesom_channel.U).all()
assert (fieldset.fields["V"] == ds_fesom_channel.V).all()
# Set the interpolation method for each field
fieldset.fields["U"].interp_method = UXPiecewiseConstantFace
fieldset.fields["V"].interp_method = UXPiecewiseConstantFace
@pytest.mark.skip(reason="ParticleSet.__init__ needs major refactoring")
def test_fesom_channel(ds_fesom_channel, uvw_fesom_channel):
fieldset = FieldSet([uvw_fesom_channel, uvw_fesom_channel.U, uvw_fesom_channel.V, uvw_fesom_channel.W])
# Check that the fieldset has the expected properties
assert (fieldset.fields["U"] == ds_fesom_channel.U).all()
assert (fieldset.fields["V"] == ds_fesom_channel.V).all()
assert (fieldset.fields["W"] == ds_fesom_channel.W).all()
pset = ParticleSet(fieldset, pclass=Particle)
pset.execute(endtime=timedelta(days=1), dt=timedelta(hours=1))