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
2 changes: 1 addition & 1 deletion src/virtualship/cli/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _fetch(path: str | Path, username: str | None, password: str | None) -> None
be provided on prompt, via command line arguments, or via a YAML config file. Run
`virtualship fetch` on an expedition for more info.
"""
from virtualship.expedition.instrument_type import InstrumentType
from virtualship.expedition.ship_config import InstrumentType

if sum([username is None, password is None]) == 1:
raise ValueError("Both username and password must be provided when using CLI.")
Expand Down
4 changes: 1 addition & 3 deletions src/virtualship/expedition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from .do_expedition import do_expedition
from .input_data import InputData
from .instrument_type import InstrumentType
from .schedule import Schedule
from .schedule import Schedule, Waypoint
from .ship_config import (
ADCPConfig,
ArgoFloatConfig,
Expand All @@ -13,7 +12,6 @@
ShipUnderwaterSTConfig,
)
from .space_time_region import SpaceTimeRegion
from .waypoint import Waypoint

__all__ = [
"ADCPConfig",
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/expedition/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import pydantic
import yaml

from .instrument_type import InstrumentType
from .schedule import Schedule
from .ship_config import InstrumentType


class _YamlDumper(yaml.SafeDumper):
Expand Down
12 changes: 0 additions & 12 deletions src/virtualship/expedition/instrument_type.py

This file was deleted.

21 changes: 18 additions & 3 deletions src/virtualship/expedition/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,37 @@
from __future__ import annotations

import itertools
from datetime import timedelta
from datetime import datetime, timedelta
from pathlib import Path

import pydantic
import pyproj
import yaml
from parcels import FieldSet

from ..location import Location
from .input_data import InputData
from .instrument_type import InstrumentType
from .ship_config import InstrumentType
from .space_time_region import SpaceTimeRegion
from .waypoint import Waypoint

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


class Waypoint(pydantic.BaseModel):
"""A Waypoint to sail to with an optional time and an optional instrument."""

location: Location
time: datetime | None = None
instrument: InstrumentType | list[InstrumentType] | None = None

@pydantic.field_serializer("instrument")
def serialize_instrument(self, instrument):
"""Ensure InstrumentType is serialized as a string (or list of strings)."""
if isinstance(instrument, list):
return [inst.value for inst in instrument]
return instrument.value if instrument else None


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

Expand Down
15 changes: 13 additions & 2 deletions src/virtualship/expedition/ship_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
from __future__ import annotations

from datetime import timedelta
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING

import pydantic
import yaml

from virtualship.utils import _validate_numeric_mins_to_timedelta

from .instrument_type import InstrumentType
from .schedule import Schedule
if TYPE_CHECKING:
from .schedule import Schedule


class InstrumentType(Enum):
"""Types of instruments."""

CTD = "CTD"
DRIFTER = "DRIFTER"
ARGO_FLOAT = "ARGO_FLOAT"
XBT = "XBT"


class ArgoFloatConfig(pydantic.BaseModel):
Expand Down
6 changes: 2 additions & 4 deletions src/virtualship/expedition/simulate_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
from ..instruments.xbt import XBT
from ..location import Location
from ..spacetime import Spacetime
from .instrument_type import InstrumentType
from .schedule import Schedule
from .ship_config import ShipConfig
from .waypoint import Waypoint
from .schedule import Schedule, Waypoint
from .ship_config import InstrumentType, ShipConfig


@dataclass
Expand Down
23 changes: 0 additions & 23 deletions src/virtualship/expedition/waypoint.py

This file was deleted.

5 changes: 2 additions & 3 deletions src/virtualship/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,13 @@ def mfp_to_yaml(coordinates_file_path: str, yaml_output_path: str): # noqa: D41

"""
# Importing Schedule and related models from expedition module
from virtualship.expedition.instrument_type import InstrumentType
from virtualship.expedition.schedule import Schedule
from virtualship.expedition.schedule import Location, Schedule, Waypoint
from virtualship.expedition.ship_config import InstrumentType
from virtualship.expedition.space_time_region import (
SpaceTimeRegion,
SpatialRange,
TimeRange,
)
from virtualship.expedition.waypoint import Location, Waypoint

# Read data from file
coordinates_data = load_coordinates(coordinates_file_path)
Expand Down
3 changes: 1 addition & 2 deletions tests/expedition/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import pytest

from virtualship import Location
from virtualship.expedition import Waypoint
from virtualship.expedition.do_expedition import _load_input_data
from virtualship.expedition.schedule import Schedule, ScheduleError
from virtualship.expedition.schedule import Schedule, ScheduleError, Waypoint
from virtualship.utils import _get_ship_config

projection = pyproj.Geod(ellps="WGS84")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mfp_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pandas as pd
import pytest

from virtualship.expedition.instrument_type import InstrumentType
from virtualship.expedition.schedule import Schedule
from virtualship.expedition.ship_config import InstrumentType
from virtualship.utils import mfp_to_yaml


Expand Down