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
15 changes: 15 additions & 0 deletions virtual_ship/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ class Location:
latitude: float
longitude: float

def __post_init__(self) -> None:
"""
Verify this location has valid latitude and longitude.

:raises ValueError: If latitude and/or longitude are not valid.
"""
if self.lat < -90:
raise ValueError("Latitude cannot be smaller than -90.")
if self.lat > 90:
raise ValueError("Latitude cannot be larger than 90.")
if self.lon < -180:
raise ValueError("Longitude cannot be smaller than -180.")
if self.lon > 360:
raise ValueError("Longitude cannot be larger than 360.")

@property
def lat(self) -> float:
"""
Expand Down
15 changes: 0 additions & 15 deletions virtual_ship/virtual_ship_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from parcels import FieldSet

from .location import Location
from .waypoint import Waypoint


Expand Down Expand Up @@ -84,11 +83,6 @@ def verify(self) -> None:
if len(self.waypoints) < 2:
raise ValueError("Waypoints require at least a start and an end.")

if not all(
[self._is_valid_location(waypoint.location) for waypoint in self.waypoints]
):
raise ValueError("Invalid location for waypoint.")

if self.argo_float_config.max_depth > 0:
raise ValueError("Argo float max depth must be negative or zero.")

Expand All @@ -106,12 +100,3 @@ def verify(self) -> None:

if self.adcp_config is not None and self.adcp_config.max_depth > 0:
raise ValueError("ADCP max depth must be negative.")

@staticmethod
def _is_valid_location(location: Location) -> bool:
return (
location.lat >= -90
and location.lat <= 90
and location.lon >= -180
and location.lon <= 360
)