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 docs/user-guide/tutorials/Drifter_data_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"from virtualship import Location, Spacetime\n",
"from virtualship.models import Location, Spacetime\n",
"from virtualship.instruments.drifter import Drifter, simulate_drifters\n",
"from virtualship.expedition.input_data import InputData\n",
"from pathlib import Path\n",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ select = [
"ICN", # import conventions
"RUF", # ruff
"ISC001", # single-line-implicit-string-concatenation
"TID", # flake8-tidy-imports
]
ignore = [
# line too long (82 > 79 characters)
Expand Down
5 changes: 0 additions & 5 deletions src/virtualship/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

from importlib.metadata import version as _version

from .location import Location
from .spacetime import Spacetime

try:
__version__ = _version("virtualship")
except Exception:
# Local copy or not installed with setuptools
__version__ = "unknown"

__all__ = [
"Location",
"Spacetime",
"__version__",
]
8 changes: 2 additions & 6 deletions src/virtualship/cli/_creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
import pydantic
import yaml

CREDENTIALS_FILE = "credentials.yaml"

from virtualship.errors import CredentialFileError

class CredentialFileError(Exception):
"""Exception raised for errors in the input file format."""

pass
CREDENTIALS_FILE = "credentials.yaml"


class Credentials(pydantic.BaseModel):
Expand Down
11 changes: 3 additions & 8 deletions src/virtualship/cli/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pydantic import BaseModel

from virtualship.errors import IncompleteDownloadError
from virtualship.utils import (
_dump_yaml,
_generic_load_yaml,
Expand All @@ -16,7 +17,7 @@
)

if TYPE_CHECKING:
from virtualship.expedition.space_time_region import SpaceTimeRegion
from virtualship.models import SpaceTimeRegion

import click
import copernicusmarine
Expand All @@ -38,7 +39,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.ship_config import InstrumentType
from virtualship.models 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 Expand Up @@ -329,12 +330,6 @@ def hash_to_filename(hash: str) -> str:
return f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{hash}"


class IncompleteDownloadError(Exception):
"""Exception raised for incomplete downloads."""

pass


class DownloadMetadata(BaseModel):
"""Metadata for a data download."""

Expand Down
28 changes: 28 additions & 0 deletions src/virtualship/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class CredentialFileError(Exception):
"""Exception raised for errors in the input file format."""

pass


class IncompleteDownloadError(Exception):
"""Exception raised for incomplete downloads."""

pass


class CheckpointError(RuntimeError):
"""An error in the checkpoint."""

pass


class ScheduleError(RuntimeError):
"""An error in the schedule."""

pass


class ConfigError(RuntimeError):
"""An error in the config."""

pass
23 changes: 0 additions & 23 deletions src/virtualship/expedition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,8 @@

from .do_expedition import do_expedition
from .input_data import InputData
from .schedule import Schedule, Waypoint
from .ship_config import (
ADCPConfig,
ArgoFloatConfig,
CTD_BGCConfig,
CTDConfig,
DrifterConfig,
ShipConfig,
ShipUnderwaterSTConfig,
)
from .space_time_region import SpaceTimeRegion

__all__ = [
"ADCPConfig",
"ArgoFloatConfig",
"CTDConfig",
"CTD_BGCConfig",
"DrifterConfig",
"InputData",
"InstrumentType",
"Schedule",
"ShipConfig",
"ShipUnderwaterSTConfig",
"SpaceTimeRegion",
"Waypoint",
"do_expedition",
"instruments",
]
10 changes: 2 additions & 8 deletions 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 .schedule import Schedule
from .ship_config import InstrumentType
from virtualship.errors import CheckpointError
from virtualship.models import InstrumentType, Schedule


class _YamlDumper(yaml.SafeDumper):
Expand Down Expand Up @@ -71,9 +71,3 @@ def verify(self, schedule: Schedule) -> None:
raise CheckpointError(
"Past waypoints in schedule have been changed! Restore past schedule and only change future waypoints."
)


class CheckpointError(RuntimeError):
"""An error in the checkpoint."""

pass
3 changes: 1 addition & 2 deletions src/virtualship/expedition/do_expedition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pyproj

from virtualship.cli._fetch import get_existing_download, get_space_time_region_hash
from virtualship.models import Schedule, ShipConfig
from virtualship.utils import (
CHECKPOINT,
_get_schedule,
Expand All @@ -16,8 +17,6 @@
from .checkpoint import Checkpoint
from .expedition_cost import expedition_cost
from .input_data import InputData
from .schedule import Schedule
from .ship_config import ShipConfig
from .simulate_measurements import simulate_measurements
from .simulate_schedule import ScheduleProblem, simulate_schedule

Expand Down
17 changes: 9 additions & 8 deletions src/virtualship/expedition/simulate_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from pathlib import Path
from typing import TYPE_CHECKING

from ..instruments.adcp import simulate_adcp
from ..instruments.argo_float import simulate_argo_floats
from ..instruments.ctd import simulate_ctd
from ..instruments.ctd_bgc import simulate_ctd_bgc
from ..instruments.drifter import simulate_drifters
from ..instruments.ship_underwater_st import simulate_ship_underwater_st
from ..instruments.xbt import simulate_xbt
from .ship_config import ShipConfig
from virtualship.instruments.adcp import simulate_adcp
from virtualship.instruments.argo_float import simulate_argo_floats
from virtualship.instruments.ctd import simulate_ctd
from virtualship.instruments.ctd_bgc import simulate_ctd_bgc
from virtualship.instruments.drifter import simulate_drifters
from virtualship.instruments.ship_underwater_st import simulate_ship_underwater_st
from virtualship.instruments.xbt import simulate_xbt
from virtualship.models import ShipConfig

from .simulate_schedule import MeasurementsToSimulate

if TYPE_CHECKING:
Expand Down
22 changes: 13 additions & 9 deletions src/virtualship/expedition/simulate_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

import pyproj

from ..instruments.argo_float import ArgoFloat
from ..instruments.ctd import CTD
from ..instruments.ctd_bgc import CTD_BGC
from ..instruments.drifter import Drifter
from ..instruments.xbt import XBT
from ..location import Location
from ..spacetime import Spacetime
from .schedule import Schedule, Waypoint
from .ship_config import InstrumentType, ShipConfig
from virtualship.instruments.argo_float import ArgoFloat
from virtualship.instruments.ctd import CTD
from virtualship.instruments.ctd_bgc import CTD_BGC
from virtualship.instruments.drifter import Drifter
from virtualship.instruments.xbt import XBT
from virtualship.models import (
InstrumentType,
Location,
Schedule,
ShipConfig,
Spacetime,
Waypoint,
)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/adcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from parcels import FieldSet, ParticleSet, ScipyParticle, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime

# we specifically use ScipyParticle because we have many small calls to execute
# there is some overhead with JITParticle and this ends up being significantly faster
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/argo_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Variable,
)

from ..spacetime import Spacetime
from virtualship.models import Spacetime


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/ctd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from parcels import FieldSet, JITParticle, ParticleSet, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/ctd_bgc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from parcels import FieldSet, JITParticle, ParticleSet, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/drifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from parcels import AdvectionRK4, FieldSet, JITParticle, ParticleSet, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/ship_underwater_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from parcels import FieldSet, ParticleSet, ScipyParticle, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime

# we specifically use ScipyParticle because we have many small calls to execute
# there is some overhead with JITParticle and this ends up being significantly faster
Expand Down
2 changes: 1 addition & 1 deletion src/virtualship/instruments/xbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from parcels import FieldSet, JITParticle, ParticleSet, Variable

from ..spacetime import Spacetime
from virtualship.models import Spacetime


@dataclass
Expand Down
42 changes: 42 additions & 0 deletions src/virtualship/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Pydantic models and data classes used to configure virtualship (i.e., in the configuration files or settings)."""

from .location import Location
from .schedule import Schedule, Waypoint
from .ship_config import (
ADCPConfig,
ArgoFloatConfig,
CTD_BGCConfig,
CTDConfig,
DrifterConfig,
InstrumentType,
ShipConfig,
ShipUnderwaterSTConfig,
XBTConfig,
)
from .space_time_region import (
SpaceTimeRegion,
SpatialRange,
TimeRange,
)
from .spacetime import (
Spacetime,
)

__all__ = [ # noqa: RUF022
"Location",
"Schedule",
"Waypoint",
"InstrumentType",
"ArgoFloatConfig",
"ADCPConfig",
"CTDConfig",
"CTD_BGCConfig",
"ShipUnderwaterSTConfig",
"DrifterConfig",
"XBTConfig",
"ShipConfig",
"SpatialRange",
"TimeRange",
"SpaceTimeRegion",
"Spacetime",
]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
import pydantic
import pyproj
import yaml
from parcels import FieldSet

from ..location import Location
from virtualship.errors import ScheduleError

from .location import Location
from .ship_config import InstrumentType
from .space_time_region import SpaceTimeRegion

if TYPE_CHECKING:
from .input_data import InputData
from parcels import FieldSet

from virtualship.expedition.input_data import InputData

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


Expand Down Expand Up @@ -212,12 +216,6 @@ def verify(
time = wp_next.time


class ScheduleError(RuntimeError):
"""An error in the schedule."""

pass


def _is_on_land_zero_uv(fieldset: FieldSet, waypoint: Waypoint) -> bool:
"""
Check if waypoint is on land by assuming zero velocity means land.
Expand Down
Loading
Loading