Skip to content

Commit

Permalink
add units to config
Browse files Browse the repository at this point in the history
  • Loading branch information
surgura committed Aug 25, 2024
1 parent ed25a0b commit bd78130
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
18 changes: 9 additions & 9 deletions tests/expedition/expedition_dir/ship_config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
adcp_config:
num_bins: 40
max_depth: -1000.0
max_depth_meter: -1000.0
period_minutes: 5.0
argo_float_config:
cycle_days: 10.0
drift_days: 9.0
drift_depth: -1000.0
max_depth: -2000.0
min_depth: 0.0
vertical_speed: -0.1
drift_depth_meter: -1000.0
max_depth_meter: -2000.0
min_depth_meter: 0.0
vertical_speed_meter_per_second: -0.1
ctd_config:
max_depth: -2000.0
min_depth: -11.0
max_depth_meter: -2000.0
min_depth_meter: -11.0
stationkeeping_time_minutes: 20.0
drifter_config:
depth: 0.0
depth_meter: 0.0
lifetime_minutes: 40320.0
ship_speed: 5.14
ship_speed_meter_per_second: 5.14
ship_underwater_st_config:
period_minutes: 5.0
2 changes: 1 addition & 1 deletion tests/expedition/test_simulate_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_simulate_schedule_feasible() -> None:

projection = pyproj.Geod(ellps="WGS84")
ship_config = ShipConfig.from_yaml("expedition_dir/ship_config.yaml")
ship_config.ship_speed = 5.14
ship_config.ship_speed_meter_per_second = 5.14
schedule = Schedule(
waypoints=[
Waypoint(Location(0, 0), base_time),
Expand Down
18 changes: 9 additions & 9 deletions virtual_ship/expedition/ship_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
class ArgoFloatConfig(BaseModel):
"""Configuration for argos floats."""

min_depth: float = Field(le=0.0)
max_depth: float = Field(le=0.0)
drift_depth: float = Field(le=0.0)
vertical_speed: float = Field(lt=0.0)
min_depth_meter: float = Field(le=0.0)
max_depth_meter: float = Field(le=0.0)
drift_depth_meter: float = Field(le=0.0)
vertical_speed_meter_per_second: float = Field(lt=0.0)
cycle_days: float = Field(gt=0.0)
drift_days: float = Field(gt=0.0)


class ADCPConfig(BaseModel):
"""Configuration for ADCP instrument."""

max_depth: float = Field(le=0.0)
max_depth_meter: float = Field(le=0.0)
num_bins: int = Field(gt=0.0)
period: timedelta = Field(
serialization_alias="period_minutes",
Expand All @@ -46,8 +46,8 @@ class CTDConfig(BaseModel):
validation_alias="stationkeeping_time_minutes",
gt=timedelta(),
)
min_depth: float = Field(le=0.0)
max_depth: float = Field(le=0.0)
min_depth_meter: float = Field(le=0.0)
max_depth_meter: float = Field(le=0.0)

model_config = ConfigDict(populate_by_name=True)

Expand Down Expand Up @@ -75,7 +75,7 @@ def _serialize_period(self, value: timedelta, _info):
class DrifterConfig(BaseModel):
"""Configuration for drifters."""

depth: float = Field(le=0.0)
depth_meter: float = Field(le=0.0)
lifetime: timedelta = Field(
serialization_alias="lifetime_minutes",
validation_alias="lifetime_minutes",
Expand All @@ -92,7 +92,7 @@ def _serialize_lifetime(self, value: timedelta, _info):
class ShipConfig(BaseModel):
"""Configuration of the virtual ship."""

ship_speed: float = Field(gt=0.0)
ship_speed_meter_per_second: float = Field(gt=0.0)
"""
Velocity of the ship in meters per second.
"""
Expand Down
2 changes: 1 addition & 1 deletion virtual_ship/expedition/simulate_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def simulate_measurements(
simulate_adcp(
fieldset=input_data.adcp_fieldset,
out_path=expedition_dir.joinpath("results", "adcp.zarr"),
max_depth=ship_config.adcp_config.max_depth,
max_depth=ship_config.adcp_config.max_depth_meter,
min_depth=-5,
num_bins=ship_config.adcp_config.num_bins,
sample_points=measurements.adcps,
Expand Down
23 changes: 13 additions & 10 deletions virtual_ship/expedition/simulate_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def _progress_time_traveling_towards(self, location: Location) -> None:
azimuth1 = geodinv[0]
distance_to_next_waypoint = geodinv[2]
time_to_reach = timedelta(
seconds=distance_to_next_waypoint / self._ship_config.ship_speed
seconds=distance_to_next_waypoint
/ self._ship_config.ship_speed_meter_per_second
)
end_time = self._time + time_to_reach

Expand All @@ -134,7 +135,8 @@ def _progress_time_traveling_towards(self, location: Location) -> None:
while self._next_adcp_time <= end_time:
time_to_sail = self._next_adcp_time - time
distance_to_move = (
self._ship_config.ship_speed * time_to_sail.total_seconds()
self._ship_config.ship_speed_meter_per_second
* time_to_sail.total_seconds()
)
geodfwd: tuple[float, float, float] = self._projection.fwd(
lons=location.lon,
Expand All @@ -160,7 +162,8 @@ def _progress_time_traveling_towards(self, location: Location) -> None:
while self._next_ship_underwater_st_time <= end_time:
time_to_sail = self._next_ship_underwater_st_time - time
distance_to_move = (
self._ship_config.ship_speed * time_to_sail.total_seconds()
self._ship_config.ship_speed_meter_per_second
* time_to_sail.total_seconds()
)
geodfwd: tuple[float, float, float] = self._projection.fwd(
lons=location.lon,
Expand Down Expand Up @@ -229,10 +232,10 @@ def _make_measurements(self, waypoint: Waypoint) -> timedelta:
self._measurements_to_simulate.argo_floats.append(
ArgoFloat(
spacetime=Spacetime(self._location, self._time),
min_depth=self._ship_config.argo_float_config.min_depth,
max_depth=self._ship_config.argo_float_config.max_depth,
drift_depth=self._ship_config.argo_float_config.drift_depth,
vertical_speed=self._ship_config.argo_float_config.vertical_speed,
min_depth=self._ship_config.argo_float_config.min_depth_meter,
max_depth=self._ship_config.argo_float_config.max_depth_meter,
drift_depth=self._ship_config.argo_float_config.drift_depth_meter,
vertical_speed=self._ship_config.argo_float_config.vertical_speed_meter_per_second,
cycle_days=self._ship_config.argo_float_config.cycle_days,
drift_days=self._ship_config.argo_float_config.drift_days,
)
Expand All @@ -241,16 +244,16 @@ def _make_measurements(self, waypoint: Waypoint) -> timedelta:
self._measurements_to_simulate.ctds.append(
CTD(
spacetime=Spacetime(self._location, self._time),
min_depth=self._ship_config.ctd_config.min_depth,
max_depth=self._ship_config.ctd_config.max_depth,
min_depth=self._ship_config.ctd_config.min_depth_meter,
max_depth=self._ship_config.ctd_config.max_depth_meter,
)
)
time_costs.append(timedelta(minutes=20))
elif instrument is InstrumentType.DRIFTER:
self._measurements_to_simulate.drifters.append(
Drifter(
spacetime=Spacetime(self._location, self._time),
depth=self._ship_config.drifter_config.depth,
depth=self._ship_config.drifter_config.depth_meter,
lifetime=self._ship_config.drifter_config.lifetime,
)
)
Expand Down
4 changes: 3 additions & 1 deletion virtual_ship/expedition/verify_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def verify_schedule(
)
distance = geodinv[2]

time_to_reach = timedelta(seconds=distance / ship_config.ship_speed)
time_to_reach = timedelta(
seconds=distance / ship_config.ship_speed_meter_per_second
)
arrival_time = time + time_to_reach

if wp_next.time is None:
Expand Down

0 comments on commit bd78130

Please sign in to comment.