Skip to content

Commit ec7b76c

Browse files
Attempt to port test_expedition to v4
1 parent a008053 commit ec7b76c

File tree

5 files changed

+37
-77
lines changed

5 files changed

+37
-77
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ filterwarnings = [
7272
"ignore:divide by zero encountered *:RuntimeWarning",
7373
"ignore:invalid value encountered *:RuntimeWarning",
7474
"ignore:This is an alpha version of Parcels v4*:UserWarning",
75+
"ignore:numpy.ndarray size changed*:RuntimeWarning",
7576
]
7677
log_cli_level = "INFO"
7778
testpaths = [

src/virtualship/expedition/input_data.py

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66
from pathlib import Path
77

8+
import xarray as xr
89
from parcels import Field, FieldSet
910

1011

@@ -95,40 +96,15 @@ def _load_ship_fieldset(cls, directory: Path) -> FieldSet:
9596
"V": directory.joinpath("ship_uv.nc"),
9697
"S": directory.joinpath("ship_s.nc"),
9798
"T": directory.joinpath("ship_t.nc"),
99+
"bathymetry": directory.joinpath("bathymetry.nc"),
98100
}
99-
variables = {"U": "uo", "V": "vo", "S": "so", "T": "thetao"}
100-
dimensions = {
101-
"lon": "longitude",
102-
"lat": "latitude",
103-
"time": "time",
104-
"depth": "depth",
105-
}
106-
107-
# create the fieldset and set interpolation methods
108-
fieldset = FieldSet.from_netcdf(
109-
filenames, variables, dimensions, allow_time_extrapolation=True
101+
ds = xr.open_mfdataset(
102+
[filenames["U"], filenames["T"], filenames["S"], filenames["bathymetry"]]
110103
)
111-
fieldset.T.interp_method = "linear_invdist_land_tracer"
112-
fieldset.S.interp_method = "linear_invdist_land_tracer"
113-
114-
# make depth negative
115-
for g in fieldset.gridset.grids:
116-
g.negate_depth()
117-
118-
# add bathymetry data
119-
bathymetry_file = directory.joinpath("bathymetry.nc")
120-
bathymetry_variables = ("bathymetry", "deptho")
121-
bathymetry_dimensions = {"lon": "longitude", "lat": "latitude"}
122-
bathymetry_field = Field.from_netcdf(
123-
bathymetry_file, bathymetry_variables, bathymetry_dimensions
124-
)
125-
# make depth negative
126-
bathymetry_field.data = -bathymetry_field.data
127-
fieldset.add_field(bathymetry_field)
128-
129-
# read in data already
130-
fieldset.computeTimeChunk(0, 1)
131-
104+
ds = ds.rename_vars({"deptho": "bathymetry"})
105+
ds["bathymetry"] = -ds["bathymetry"]
106+
ds["depth"] = -ds["depth"]
107+
fieldset = FieldSet.from_copernicusmarine(ds)
132108
return fieldset
133109

134110
@classmethod
@@ -203,26 +179,8 @@ def _load_drifter_fieldset(cls, directory: Path) -> FieldSet:
203179
"V": directory.joinpath("drifter_uv.nc"),
204180
"T": directory.joinpath("drifter_t.nc"),
205181
}
206-
variables = {"U": "uo", "V": "vo", "T": "thetao"}
207-
dimensions = {
208-
"lon": "longitude",
209-
"lat": "latitude",
210-
"time": "time",
211-
"depth": "depth",
212-
}
213-
214-
fieldset = FieldSet.from_netcdf(
215-
filenames, variables, dimensions, allow_time_extrapolation=False
216-
)
217-
fieldset.T.interp_method = "linear_invdist_land_tracer"
218-
219-
# make depth negative
220-
for g in fieldset.gridset.grids:
221-
g.negate_depth()
222-
223-
# read in data already
224-
fieldset.computeTimeChunk(0, 1)
225-
182+
ds = xr.open_mfdataset([filenames["U"], filenames["T"]])
183+
fieldset = FieldSet.from_copernicusmarine(ds)
226184
return fieldset
227185

228186
@classmethod

src/virtualship/instruments/ctd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def simulate_ctd(
100100
max(
101101
ctd.max_depth,
102102
fieldset.bathymetry.eval(
103-
z=0,
104-
y=ctd.spacetime.location.lat,
105-
x=ctd.spacetime.location.lon,
103+
z=np.array(0, dtype=np.float32),
104+
y=np.array(ctd.spacetime.location.lat, dtype=np.float32),
105+
x=np.array(ctd.spacetime.location.lon, dtype=np.float32),
106106
time=fieldset.time_interval.left,
107107
),
108108
)

src/virtualship/models/expedition.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from enum import Enum
66
from typing import TYPE_CHECKING
77

8+
import numpy as np
89
import pydantic
910
import pyproj
1011
import yaml
@@ -448,9 +449,9 @@ def _is_on_land_zero_uv(fieldset: FieldSet, waypoint: Waypoint) -> bool:
448449
:returns: If the waypoint is on land.
449450
"""
450451
return fieldset.UV.eval(
451-
0,
452-
fieldset.gridset.grids[0].depth[0],
453-
waypoint.location.lat,
454-
waypoint.location.lon,
452+
fieldset.time_interval.left,
453+
fieldset.gridset[0].depth[0],
454+
np.array([waypoint.location.lat]),
455+
np.array([waypoint.location.lon]),
455456
applyConversion=False,
456457
) == (0.0, 0.0)

tests/expedition/expedition_dir/expedition.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ schedule:
88
time: 2023-01-01 00:00:00
99
- instrument:
1010
- DRIFTER
11-
- ARGO_FLOAT
11+
# - ARGO_FLOAT # TODO port ARGO_FLOAT to v4
1212
location:
1313
latitude: 0.01
1414
longitude: 0.01
@@ -18,29 +18,29 @@ schedule:
1818
longitude: 0.01
1919
time: 2023-01-02 03:00:00
2020
instruments_config:
21-
adcp_config:
22-
num_bins: 40
23-
max_depth_meter: -1000.0
24-
period_minutes: 5.0
25-
argo_float_config:
26-
cycle_days: 10.0
27-
drift_days: 9.0
28-
drift_depth_meter: -1000.0
29-
max_depth_meter: -2000.0
30-
min_depth_meter: 0.0
31-
vertical_speed_meter_per_second: -0.1
21+
# adcp_config:
22+
# num_bins: 40
23+
# max_depth_meter: -1000.0
24+
# period_minutes: 5.0
25+
# argo_float_config:
26+
# cycle_days: 10.0
27+
# drift_days: 9.0
28+
# drift_depth_meter: -1000.0
29+
# max_depth_meter: -2000.0
30+
# min_depth_meter: 0.0
31+
# vertical_speed_meter_per_second: -0.1
3232
ctd_config:
3333
max_depth_meter: -2000.0
3434
min_depth_meter: -11.0
3535
stationkeeping_time_minutes: 20.0
36-
ctd_bgc_config:
37-
max_depth_meter: -2000.0
38-
min_depth_meter: -11.0
39-
stationkeeping_time_minutes: 20.0
36+
# ctd_bgc_config:
37+
# max_depth_meter: -2000.0
38+
# min_depth_meter: -11.0
39+
# stationkeeping_time_minutes: 20.0
4040
drifter_config:
4141
depth_meter: 0.0
4242
lifetime_minutes: 40320.0
43-
ship_underwater_st_config:
44-
period_minutes: 5.0
43+
# ship_underwater_st_config:
44+
# period_minutes: 5.0
4545
ship_config:
4646
ship_speed_knots: 10.0

0 commit comments

Comments
 (0)