Skip to content

Commit f9a0844

Browse files
Merge branch 'parcels-v4' of https://github.com/Parcels-code/virtualship into parcels-v4
2 parents 9ebeda3 + 27b8f62 commit f9a0844

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/virtualship/instruments/drifter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import numpy as np
88
from parcels import FieldSet, Particle, ParticleFile, ParticleSet, Variable
9-
from parcels.kernels import AdvectionRK4
109
from parcels._core.statuscodes import StatusCode
10+
from parcels.kernels import AdvectionRK4
1111

1212
from virtualship.models import Spacetime
1313

@@ -91,7 +91,9 @@ def simulate_drifters(
9191
)
9292

9393
# get earliest between fieldset end time and provide end time
94-
fieldset_endtime = fieldset.time_interval.right - np.timedelta64(1, "s") # TODO remove hack stopping 1 second too early when v4 is fixed
94+
fieldset_endtime = fieldset.time_interval.right - np.timedelta64(
95+
1, "s"
96+
) # TODO remove hack stopping 1 second too early when v4 is fixed
9597
if endtime is None:
9698
actual_endtime = fieldset_endtime
9799
elif endtime > fieldset_endtime:
@@ -110,9 +112,7 @@ def simulate_drifters(
110112
)
111113

112114
# if there are more particles left than the number of drifters with an indefinite endtime, warn the user
113-
if len(drifter_particleset) > len(
114-
[d for d in drifters if d.lifetime is None]
115-
):
115+
if len(drifter_particleset) > len([d for d in drifters if d.lifetime is None]):
116116
print(
117117
"WARN: Some drifters had a life time beyond the end time of the fieldset or the requested end time."
118118
)

tests/instruments/test_drifter.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
import xarray as xr
7-
from parcels import FieldSet, Field, VectorField, XGrid
7+
from parcels import Field, FieldSet, VectorField, XGrid
88

99
from virtualship.instruments.drifter import Drifter, simulate_drifters
1010
from virtualship.models import Location, Spacetime
@@ -23,15 +23,35 @@ def test_simulate_drifters(tmpdir) -> None:
2323

2424
time = [base_time, base_time + np.timedelta64(3, "D")]
2525
ds = xr.Dataset(
26-
{"U": (["time", "YG", "XG"], u), "V": (["time", "YG", "XG"], v), "T": (["time", "YG", "XG"], t)},
26+
{
27+
"U": (["time", "YG", "XG"], u),
28+
"V": (["time", "YG", "XG"], v),
29+
"T": (["time", "YG", "XG"], t),
30+
},
2731
coords={
2832
"time": (["time"], time, {"axis": "T"}),
2933
"YC": (["YC"], np.arange(dims[1]) + 0.5, {"axis": "Y"}),
30-
"YG": (["YG"], np.arange(dims[1]), {"axis": "Y", "c_grid_axis_shift": -0.5}),
34+
"YG": (
35+
["YG"],
36+
np.arange(dims[1]),
37+
{"axis": "Y", "c_grid_axis_shift": -0.5},
38+
),
3139
"XC": (["XC"], np.arange(dims[2]) + 0.5, {"axis": "X"}),
32-
"XG": (["XG"], np.arange(dims[2]), {"axis": "X", "c_grid_axis_shift": -0.5}),
33-
"lat": (["YG"], np.linspace(-10, 10, dims[1]), {"axis": "Y", "c_grid_axis_shift": 0.5}),
34-
"lon": (["XG"], np.linspace(-10, 10, dims[2]), {"axis": "X", "c_grid_axis_shift": -0.5}),
40+
"XG": (
41+
["XG"],
42+
np.arange(dims[2]),
43+
{"axis": "X", "c_grid_axis_shift": -0.5},
44+
),
45+
"lat": (
46+
["YG"],
47+
np.linspace(-10, 10, dims[1]),
48+
{"axis": "Y", "c_grid_axis_shift": 0.5},
49+
),
50+
"lon": (
51+
["XG"],
52+
np.linspace(-10, 10, dims[2]),
53+
{"axis": "X", "c_grid_axis_shift": -0.5},
54+
),
3555
},
3656
)
3757

@@ -42,7 +62,6 @@ def test_simulate_drifters(tmpdir) -> None:
4262
UV = VectorField("UV", U, V)
4363
fieldset = FieldSet([U, V, T, UV])
4464

45-
4665
# drifters to deploy
4766
drifters = [
4867
Drifter(
@@ -76,7 +95,9 @@ def test_simulate_drifters(tmpdir) -> None:
7695
)
7796

7897
# test if output is as expected
79-
results = xr.open_zarr(out_path, decode_cf=False) # TODO fix decode_cf when parcels v4 is fixed
98+
results = xr.open_zarr(
99+
out_path, decode_cf=False
100+
) # TODO fix decode_cf when parcels v4 is fixed
80101

81102
assert len(results.trajectory) == len(drifters)
82103

0 commit comments

Comments
 (0)