Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 308 additions & 0 deletions docs/tutorials/ADCP_data_tutorial.ipynb

Large diffs are not rendered by default.

505 changes: 505 additions & 0 deletions docs/tutorials/CTD_data_tutorial.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/virtualship/expedition/do_expedition.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _load_input_data(
load_argo_float=ship_config.argo_float_config is not None,
load_ctd=ship_config.ctd_config is not None,
load_drifter=ship_config.drifter_config is not None,
load_xbt=ship_config.xbt_config is not None,
load_ship_underwater_st=ship_config.ship_underwater_st_config is not None,
)

Expand Down
9 changes: 8 additions & 1 deletion src/virtualship/expedition/input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InputData:
argo_float_fieldset: FieldSet | None
ctd_fieldset: FieldSet | None
drifter_fieldset: FieldSet | None
xbt_fieldset: FieldSet | None
ship_underwater_st_fieldset: FieldSet | None

@classmethod
Expand All @@ -26,6 +27,7 @@ def load(
load_argo_float: bool,
load_ctd: bool,
load_drifter: bool,
load_xbt: bool,
load_ship_underwater_st: bool,
) -> InputData:
"""
Expand All @@ -49,7 +51,7 @@ def load(
argo_float_fieldset = cls._load_argo_float_fieldset(directory)
else:
argo_float_fieldset = None
if load_adcp or load_ctd or load_ship_underwater_st:
if load_adcp or load_ctd or load_ship_underwater_st or load_xbt:
default_fieldset = cls._load_default_fieldset(directory)
if load_adcp:
adcp_fieldset = default_fieldset
Expand All @@ -63,12 +65,17 @@ def load(
ship_underwater_st_fieldset = default_fieldset
else:
ship_underwater_st_fieldset = None
if load_xbt:
xbt_fieldset = default_fieldset
else:
xbt_fieldset = None

return InputData(
adcp_fieldset=adcp_fieldset,
argo_float_fieldset=argo_float_fieldset,
ctd_fieldset=ctd_fieldset,
drifter_fieldset=drifter_fieldset,
xbt_fieldset=xbt_fieldset,
ship_underwater_st_fieldset=ship_underwater_st_fieldset,
)

Expand Down
1 change: 1 addition & 0 deletions src/virtualship/expedition/instrument_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ class InstrumentType(Enum):
CTD = "CTD"
DRIFTER = "DRIFTER"
ARGO_FLOAT = "ARGO_FLOAT"
XBT = "XBT"
16 changes: 16 additions & 0 deletions src/virtualship/expedition/ship_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def _serialize_lifetime(self, value: timedelta, _info):
return value.total_seconds() / 60.0


class XBTConfig(pydantic.BaseModel):
"""Configuration for xbt instrument."""

min_depth_meter: float = pydantic.Field(le=0.0)
max_depth_meter: float = pydantic.Field(le=0.0)
fall_speed_meter_per_second: float = pydantic.Field(gt=0.0)
deceleration_coefficient: float = pydantic.Field(gt=0.0)


class ShipConfig(pydantic.BaseModel):
"""Configuration of the virtual ship."""

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

xbt_config: XBTConfig | None = None
"""
XBT configuration.

If None, no XBTs can be cast.
"""

model_config = pydantic.ConfigDict(extra="forbid")

def to_yaml(self, file_path: str | Path) -> None:
Expand Down
14 changes: 14 additions & 0 deletions src/virtualship/expedition/simulate_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..instruments.ctd import simulate_ctd
from ..instruments.drifter import simulate_drifters
from ..instruments.ship_underwater_st import simulate_ship_underwater_st
from ..instruments.xbt import simulate_xbt
from .input_data import InputData
from .ship_config import ShipConfig
from .simulate_schedule import MeasurementsToSimulate
Expand Down Expand Up @@ -102,3 +103,16 @@ def simulate_measurements(
outputdt=timedelta(minutes=5),
endtime=None,
)

if len(measurements.xbts) > 0:
print("Simulating XBTs")
if ship_config.xbt_config is None:
raise RuntimeError("No configuration for XBTs provided.")
if input_data.xbt_fieldset is None:
raise RuntimeError("No fieldset for XBTs provided.")
simulate_xbt(
out_path=expedition_dir.joinpath("results", "xbts.zarr"),
fieldset=input_data.xbt_fieldset,
xbts=measurements.xbts,
outputdt=timedelta(seconds=1),
)
12 changes: 12 additions & 0 deletions src/virtualship/expedition/simulate_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ..instruments.argo_float import ArgoFloat
from ..instruments.ctd import CTD
from ..instruments.drifter import Drifter
from ..instruments.xbt import XBT
from ..location import Location
from ..spacetime import Spacetime
from .instrument_type import InstrumentType
Expand Down Expand Up @@ -43,6 +44,7 @@ class MeasurementsToSimulate:
argo_floats: list[ArgoFloat] = field(default_factory=list, init=False)
drifters: list[Drifter] = field(default_factory=list, init=False)
ctds: list[CTD] = field(default_factory=list, init=False)
xbts: list[XBT] = field(default_factory=list, init=False)


def simulate_schedule(
Expand Down Expand Up @@ -257,6 +259,16 @@ def _make_measurements(self, waypoint: Waypoint) -> timedelta:
lifetime=self._ship_config.drifter_config.lifetime,
)
)
elif instrument is InstrumentType.XBT:
self._measurements_to_simulate.xbts.append(
XBT(
spacetime=Spacetime(self._location, self._time),
min_depth=self._ship_config.xbt_config.min_depth_meter,
max_depth=self._ship_config.xbt_config.max_depth_meter,
fall_speed=self._ship_config.xbt_config.fall_speed_meter_per_second,
deceleration_coefficient=self._ship_config.xbt_config.deceleration_coefficient,
)
)
else:
raise NotImplementedError("Instrument type not supported.")

Expand Down
5 changes: 5 additions & 0 deletions src/virtualship/static/schedule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ waypoints:
latitude: 0.02
longitude: 0.02
time: 2023-01-01 02:00:00
- instrument: XBT
location:
latitude: 0.03
longitude: 0.03
time: 2023-01-01 03:00:00
5 changes: 5 additions & 0 deletions src/virtualship/static/ship_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ ctd_config:
drifter_config:
depth_meter: 0.0
lifetime_minutes: 40320.0
xbt_config:
max_depth_meter: -285.0
min_depth_meter: -2.0
fall_speed_meter_per_second: 6.7
deceleration_coefficient: 0.00225
ship_underwater_st_config:
period_minutes: 5.0