Skip to content

Commit 3329698

Browse files
ammeddpre-commit-ci[bot]erikvansebille
authored
Adds XBTs to schedule and expedition (#117)
* add XBTs to schedule and expedition * ruff * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Small bugfixes to xbt * Removing duplicate entries in tutorials page --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Erik van Sebille <[email protected]>
1 parent 8b76228 commit 3329698

File tree

10 files changed

+875
-1
lines changed

10 files changed

+875
-1
lines changed

docs/tutorials/ADCP_data_tutorial.ipynb

Lines changed: 308 additions & 0 deletions
Large diffs are not rendered by default.

docs/tutorials/CTD_data_tutorial.ipynb

Lines changed: 505 additions & 0 deletions
Large diffs are not rendered by default.

src/virtualship/expedition/do_expedition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def _load_input_data(
168168
load_argo_float=ship_config.argo_float_config is not None,
169169
load_ctd=ship_config.ctd_config is not None,
170170
load_drifter=ship_config.drifter_config is not None,
171+
load_xbt=ship_config.xbt_config is not None,
171172
load_ship_underwater_st=ship_config.ship_underwater_st_config is not None,
172173
)
173174

src/virtualship/expedition/input_data.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class InputData:
1616
argo_float_fieldset: FieldSet | None
1717
ctd_fieldset: FieldSet | None
1818
drifter_fieldset: FieldSet | None
19+
xbt_fieldset: FieldSet | None
1920
ship_underwater_st_fieldset: FieldSet | None
2021

2122
@classmethod
@@ -26,6 +27,7 @@ def load(
2627
load_argo_float: bool,
2728
load_ctd: bool,
2829
load_drifter: bool,
30+
load_xbt: bool,
2931
load_ship_underwater_st: bool,
3032
) -> InputData:
3133
"""
@@ -49,7 +51,7 @@ def load(
4951
argo_float_fieldset = cls._load_argo_float_fieldset(directory)
5052
else:
5153
argo_float_fieldset = None
52-
if load_adcp or load_ctd or load_ship_underwater_st:
54+
if load_adcp or load_ctd or load_ship_underwater_st or load_xbt:
5355
default_fieldset = cls._load_default_fieldset(directory)
5456
if load_adcp:
5557
adcp_fieldset = default_fieldset
@@ -63,12 +65,17 @@ def load(
6365
ship_underwater_st_fieldset = default_fieldset
6466
else:
6567
ship_underwater_st_fieldset = None
68+
if load_xbt:
69+
xbt_fieldset = default_fieldset
70+
else:
71+
xbt_fieldset = None
6672

6773
return InputData(
6874
adcp_fieldset=adcp_fieldset,
6975
argo_float_fieldset=argo_float_fieldset,
7076
ctd_fieldset=ctd_fieldset,
7177
drifter_fieldset=drifter_fieldset,
78+
xbt_fieldset=xbt_fieldset,
7279
ship_underwater_st_fieldset=ship_underwater_st_fieldset,
7380
)
7481

src/virtualship/expedition/instrument_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ class InstrumentType(Enum):
99
CTD = "CTD"
1010
DRIFTER = "DRIFTER"
1111
ARGO_FLOAT = "ARGO_FLOAT"
12+
XBT = "XBT"

src/virtualship/expedition/ship_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def _serialize_lifetime(self, value: timedelta, _info):
8989
return value.total_seconds() / 60.0
9090

9191

92+
class XBTConfig(pydantic.BaseModel):
93+
"""Configuration for xbt instrument."""
94+
95+
min_depth_meter: float = pydantic.Field(le=0.0)
96+
max_depth_meter: float = pydantic.Field(le=0.0)
97+
fall_speed_meter_per_second: float = pydantic.Field(gt=0.0)
98+
deceleration_coefficient: float = pydantic.Field(gt=0.0)
99+
100+
92101
class ShipConfig(pydantic.BaseModel):
93102
"""Configuration of the virtual ship."""
94103

@@ -132,6 +141,13 @@ class ShipConfig(pydantic.BaseModel):
132141
If None, no drifters can be deployed.
133142
"""
134143

144+
xbt_config: XBTConfig | None = None
145+
"""
146+
XBT configuration.
147+
148+
If None, no XBTs can be cast.
149+
"""
150+
135151
model_config = pydantic.ConfigDict(extra="forbid")
136152

137153
def to_yaml(self, file_path: str | Path) -> None:

src/virtualship/expedition/simulate_measurements.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..instruments.ctd import simulate_ctd
99
from ..instruments.drifter import simulate_drifters
1010
from ..instruments.ship_underwater_st import simulate_ship_underwater_st
11+
from ..instruments.xbt import simulate_xbt
1112
from .input_data import InputData
1213
from .ship_config import ShipConfig
1314
from .simulate_schedule import MeasurementsToSimulate
@@ -102,3 +103,16 @@ def simulate_measurements(
102103
outputdt=timedelta(minutes=5),
103104
endtime=None,
104105
)
106+
107+
if len(measurements.xbts) > 0:
108+
print("Simulating XBTs")
109+
if ship_config.xbt_config is None:
110+
raise RuntimeError("No configuration for XBTs provided.")
111+
if input_data.xbt_fieldset is None:
112+
raise RuntimeError("No fieldset for XBTs provided.")
113+
simulate_xbt(
114+
out_path=expedition_dir.joinpath("results", "xbts.zarr"),
115+
fieldset=input_data.xbt_fieldset,
116+
xbts=measurements.xbts,
117+
outputdt=timedelta(seconds=1),
118+
)

src/virtualship/expedition/simulate_schedule.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..instruments.argo_float import ArgoFloat
1111
from ..instruments.ctd import CTD
1212
from ..instruments.drifter import Drifter
13+
from ..instruments.xbt import XBT
1314
from ..location import Location
1415
from ..spacetime import Spacetime
1516
from .instrument_type import InstrumentType
@@ -43,6 +44,7 @@ class MeasurementsToSimulate:
4344
argo_floats: list[ArgoFloat] = field(default_factory=list, init=False)
4445
drifters: list[Drifter] = field(default_factory=list, init=False)
4546
ctds: list[CTD] = field(default_factory=list, init=False)
47+
xbts: list[XBT] = field(default_factory=list, init=False)
4648

4749

4850
def simulate_schedule(
@@ -257,6 +259,16 @@ def _make_measurements(self, waypoint: Waypoint) -> timedelta:
257259
lifetime=self._ship_config.drifter_config.lifetime,
258260
)
259261
)
262+
elif instrument is InstrumentType.XBT:
263+
self._measurements_to_simulate.xbts.append(
264+
XBT(
265+
spacetime=Spacetime(self._location, self._time),
266+
min_depth=self._ship_config.xbt_config.min_depth_meter,
267+
max_depth=self._ship_config.xbt_config.max_depth_meter,
268+
fall_speed=self._ship_config.xbt_config.fall_speed_meter_per_second,
269+
deceleration_coefficient=self._ship_config.xbt_config.deceleration_coefficient,
270+
)
271+
)
260272
else:
261273
raise NotImplementedError("Instrument type not supported.")
262274

src/virtualship/static/schedule.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ waypoints:
2525
latitude: 0.02
2626
longitude: 0.02
2727
time: 2023-01-01 02:00:00
28+
- instrument: XBT
29+
location:
30+
latitude: 0.03
31+
longitude: 0.03
32+
time: 2023-01-01 03:00:00

src/virtualship/static/ship_config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ ctd_config:
1717
drifter_config:
1818
depth_meter: 0.0
1919
lifetime_minutes: 40320.0
20+
xbt_config:
21+
max_depth_meter: -285.0
22+
min_depth_meter: -2.0
23+
fall_speed_meter_per_second: 6.7
24+
deceleration_coefficient: 0.00225
2025
ship_underwater_st_config:
2126
period_minutes: 5.0

0 commit comments

Comments
 (0)