Skip to content

Commit 46b3fea

Browse files
committed
Move Waypoint to schedule.py
1 parent 6914b72 commit 46b3fea

File tree

6 files changed

+21
-35
lines changed

6 files changed

+21
-35
lines changed

src/virtualship/expedition/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .do_expedition import do_expedition
44
from .input_data import InputData
5-
from .schedule import Schedule
5+
from .schedule import Schedule, Waypoint
66
from .ship_config import (
77
ADCPConfig,
88
ArgoFloatConfig,
@@ -12,7 +12,6 @@
1212
ShipUnderwaterSTConfig,
1313
)
1414
from .space_time_region import SpaceTimeRegion
15-
from .waypoint import Waypoint
1615

1716
__all__ = [
1817
"ADCPConfig",

src/virtualship/expedition/schedule.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,37 @@
33
from __future__ import annotations
44

55
import itertools
6-
from datetime import timedelta
6+
from datetime import datetime, timedelta
77
from pathlib import Path
88

99
import pydantic
1010
import pyproj
1111
import yaml
1212
from parcels import FieldSet
1313

14+
from ..location import Location
1415
from .input_data import InputData
1516
from .ship_config import InstrumentType
1617
from .space_time_region import SpaceTimeRegion
17-
from .waypoint import Waypoint
1818

1919
projection: pyproj.Geod = pyproj.Geod(ellps="WGS84")
2020

2121

22+
class Waypoint(pydantic.BaseModel):
23+
"""A Waypoint to sail to with an optional time and an optional instrument."""
24+
25+
location: Location
26+
time: datetime | None = None
27+
instrument: InstrumentType | list[InstrumentType] | None = None
28+
29+
@pydantic.field_serializer("instrument")
30+
def serialize_instrument(self, instrument):
31+
"""Ensure InstrumentType is serialized as a string (or list of strings)."""
32+
if isinstance(instrument, list):
33+
return [inst.value for inst in instrument]
34+
return instrument.value if instrument else None
35+
36+
2237
class Schedule(pydantic.BaseModel):
2338
"""Schedule of the virtual ship."""
2439

src/virtualship/expedition/simulate_schedule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
from ..instruments.xbt import XBT
1414
from ..location import Location
1515
from ..spacetime import Spacetime
16-
from .schedule import Schedule
16+
from .schedule import Schedule, Waypoint
1717
from .ship_config import InstrumentType, ShipConfig
18-
from .waypoint import Waypoint
1918

2019

2120
@dataclass

src/virtualship/expedition/waypoint.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/virtualship/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,13 @@ def mfp_to_yaml(coordinates_file_path: str, yaml_output_path: str): # noqa: D41
139139
140140
"""
141141
# Importing Schedule and related models from expedition module
142-
from virtualship.expedition.schedule import Schedule
142+
from virtualship.expedition.schedule import Location, Schedule, Waypoint
143143
from virtualship.expedition.ship_config import InstrumentType
144144
from virtualship.expedition.space_time_region import (
145145
SpaceTimeRegion,
146146
SpatialRange,
147147
TimeRange,
148148
)
149-
from virtualship.expedition.waypoint import Location, Waypoint
150149

151150
# Read data from file
152151
coordinates_data = load_coordinates(coordinates_file_path)

tests/expedition/test_schedule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import pytest
66

77
from virtualship import Location
8-
from virtualship.expedition import Waypoint
98
from virtualship.expedition.do_expedition import _load_input_data
10-
from virtualship.expedition.schedule import Schedule, ScheduleError
9+
from virtualship.expedition.schedule import Schedule, ScheduleError, Waypoint
1110
from virtualship.utils import _get_ship_config
1211

1312
projection = pyproj.Geod(ellps="WGS84")

0 commit comments

Comments
 (0)