|
1 | | -import os |
2 | 1 | from datetime import timedelta |
3 | 2 |
|
| 3 | +import pytest |
4 | 4 | import uxarray as ux |
5 | 5 |
|
6 | 6 | from parcels import ( |
|
9 | 9 | ParticleSet, |
10 | 10 | UXPiecewiseConstantFace, |
11 | 11 | UXPiecewiseLinearNode, |
| 12 | + download_example_dataset, |
12 | 13 | ) |
13 | 14 |
|
14 | | -# Get path of this script |
15 | | -V4_TEST_DATA = f"{os.path.dirname(__file__)}/test_data" |
16 | 15 |
|
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" |
21 | 20 | 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", |
25 | 24 | ] |
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]) |
29 | 31 | fieldset._check_complete() |
30 | 32 | # Check that the fieldset has the expected properties |
31 | | - assert fieldset.datasets[0] == ds |
| 33 | + assert fieldset.datasets[0] == ds_fesom_channel |
32 | 34 |
|
33 | 35 |
|
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]) |
44 | 38 | # Check that the fieldset has the expected properties |
45 | | - assert fieldset.datasets[0] == ds |
| 39 | + assert fieldset.datasets[0] == ds_fesom_channel |
46 | 40 | pset = ParticleSet(fieldset, pclass=Particle) |
47 | 41 | assert pset.fieldset == fieldset |
48 | 42 |
|
49 | 43 |
|
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]) |
60 | 46 | # Set the interpolation method for each field |
61 | 47 | fieldset.U.interp_method = UXPiecewiseConstantFace |
62 | 48 | fieldset.V.interp_method = UXPiecewiseConstantFace |
63 | 49 | fieldset.W.interp_method = UXPiecewiseLinearNode |
64 | 50 |
|
65 | 51 |
|
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]) |
76 | 54 | # Set the interpolation method for each field |
77 | 55 | fieldset.U.interp_method = UXPiecewiseConstantFace |
78 | 56 | fieldset.V.interp_method = UXPiecewiseConstantFace |
|
0 commit comments