diff --git a/virtual_ship/location.py b/virtual_ship/location.py index edeb4efc..793e5312 100644 --- a/virtual_ship/location.py +++ b/virtual_ship/location.py @@ -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: """ diff --git a/virtual_ship/virtual_ship_config.py b/virtual_ship/virtual_ship_config.py index 7dba815e..42e8c5d8 100644 --- a/virtual_ship/virtual_ship_config.py +++ b/virtual_ship/virtual_ship_config.py @@ -5,7 +5,6 @@ from parcels import FieldSet -from .location import Location from .waypoint import Waypoint @@ -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.") @@ -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 - )