44import uxarray as ux
55
66from parcels import (
7+ Field ,
78 FieldSet ,
89 Particle ,
910 ParticleSet ,
1011 UXPiecewiseConstantFace ,
1112 UXPiecewiseLinearNode ,
13+ VectorField ,
1214 download_example_dataset ,
1315)
1416
@@ -26,33 +28,66 @@ def ds_fesom_channel() -> ux.UxDataset:
2628 return ds
2729
2830
29- def test_fesom_fieldset (ds_fesom_channel ):
30- fieldset = FieldSet ([ds_fesom_channel ])
31+ @pytest .fixture
32+ def uv_fesom_channel (ds_fesom_channel ) -> VectorField :
33+ UV = VectorField (
34+ name = "UV" ,
35+ U = Field (name = "U" , data = ds_fesom_channel .U , grid = ds_fesom_channel .uxgrid ),
36+ V = Field (name = "V" , data = ds_fesom_channel .V , grid = ds_fesom_channel .uxgrid ),
37+ )
38+ return UV
39+
40+
41+ @pytest .fixture
42+ def uvw_fesom_channel (ds_fesom_channel ) -> VectorField :
43+ UVW = VectorField (
44+ name = "UVW" ,
45+ U = Field (name = "U" , data = ds_fesom_channel .U , grid = ds_fesom_channel .uxgrid ),
46+ V = Field (name = "V" , data = ds_fesom_channel .V , grid = ds_fesom_channel .uxgrid ),
47+ W = Field (name = "W" , data = ds_fesom_channel .W , grid = ds_fesom_channel .uxgrid ),
48+ )
49+ return UVW
50+
51+
52+ def test_fesom_fieldset (ds_fesom_channel , uv_fesom_channel ):
53+ fieldset = FieldSet ([uv_fesom_channel ])
3154 # Check that the fieldset has the expected properties
32- assert fieldset .datasets [0 ] == ds_fesom_channel
55+ assert (fieldset .fields ["U" ] == ds_fesom_channel .U ).all ()
56+ assert (fieldset .fields ["V" ] == ds_fesom_channel .V ).all ()
3357
3458
35- def test_fesom_in_particleset (ds_fesom_channel ):
36- fieldset = FieldSet ([ds_fesom_channel ])
59+ def test_fesom_in_particleset (ds_fesom_channel , uv_fesom_channel ):
60+ fieldset = FieldSet ([uv_fesom_channel ])
3761 # Check that the fieldset has the expected properties
38- assert fieldset .datasets [0 ] == ds_fesom_channel
62+ assert (fieldset .fields ["U" ] == ds_fesom_channel .U ).all ()
63+ assert (fieldset .fields ["V" ] == ds_fesom_channel .V ).all ()
3964 pset = ParticleSet (fieldset , pclass = Particle )
4065 assert pset .fieldset == fieldset
4166
4267
43- def test_set_interp_methods (ds_fesom_channel ):
44- fieldset = FieldSet ([ds_fesom_channel ])
68+ def test_set_interp_methods (ds_fesom_channel , uv_fesom_channel ):
69+ fieldset = FieldSet ([uv_fesom_channel ])
70+ # Check that the fieldset has the expected properties
71+ assert (fieldset .fields ["U" ] == ds_fesom_channel .U ).all ()
72+ assert (fieldset .fields ["V" ] == ds_fesom_channel .V ).all ()
73+
4574 # Set the interpolation method for each field
4675 fieldset .U .interp_method = UXPiecewiseConstantFace
4776 fieldset .V .interp_method = UXPiecewiseConstantFace
48- fieldset .W .interp_method = UXPiecewiseLinearNode
4977
5078
51- def test_fesom_channel (ds_fesom_channel ):
52- fieldset = FieldSet ([ds_fesom_channel ])
79+ def test_fesom_channel (ds_fesom_channel , uvw_fesom_channel ):
80+ fieldset = FieldSet ([uvw_fesom_channel ])
81+
82+ # Check that the fieldset has the expected properties
83+ assert (fieldset .fields ["U" ] == ds_fesom_channel .U ).all ()
84+ assert (fieldset .fields ["V" ] == ds_fesom_channel .V ).all ()
85+ assert (fieldset .fields ["W" ] == ds_fesom_channel .W ).all ()
86+
5387 # Set the interpolation method for each field
5488 fieldset .U .interp_method = UXPiecewiseConstantFace
5589 fieldset .V .interp_method = UXPiecewiseConstantFace
5690 fieldset .W .interp_method = UXPiecewiseLinearNode
91+
5792 pset = ParticleSet (fieldset , pclass = Particle )
5893 pset .execute (endtime = timedelta (days = 1 ), dt = timedelta (hours = 1 ))
0 commit comments