Skip to content

Commit

Permalink
load in fieldsets preemtively and better error mesgs
Browse files Browse the repository at this point in the history
  • Loading branch information
surgura committed Aug 26, 2024
1 parent 4799bfc commit 29b5b0f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/expedition/expedition_dir/ship_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ship_speed_meter_per_second: 5.14
adcp_config:
num_bins: 40
max_depth_meter: -1000.0
Expand All @@ -16,6 +17,5 @@ ctd_config:
drifter_config:
depth_meter: 0.0
lifetime_minutes: 40320.0
ship_speed_meter_per_second: 5.14
ship_underwater_st_config:
period_minutes: 5.0
6 changes: 6 additions & 0 deletions virtual_ship/expedition/input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def _load_drifter_fieldset(cls, directory: str | Path) -> FieldSet:
for g in fieldset.gridset.grids:
g.depth = -g.depth

# read in data already
fieldset.computeTimeChunk(0, 1)

return fieldset

@classmethod
Expand Down Expand Up @@ -167,4 +170,7 @@ def _load_argo_float_fieldset(cls, directory: str | Path) -> FieldSet:
if max(g.depth) > 0:
g.depth = -g.depth

# read in data already
fieldset.computeTimeChunk(0, 1)

return fieldset
30 changes: 30 additions & 0 deletions virtual_ship/expedition/verify_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ def verify_schedule(
else:
time = wp_next.time

# verify instruments in schedule have configuration
for wp in schedule.waypoints:
if wp.instrument is not None:
for instrument in (
wp.instrument if isinstance(wp.instrument, list) else [wp.instrument]
):
if (
instrument == InstrumentType.ARGO_FLOAT
and ship_config.argo_float_config is None
):
raise PlanningError(
"Planning has waypoint with Argo float instrument, but configuration does not configure Argo floats."
)
elif (
instrument == InstrumentType.CTD
and ship_config.argo_float_config is None
):
raise PlanningError(
"Planning has waypoint with CTD instrument, but configuration does not configure CTDs."
)
elif (
instrument == InstrumentType.DRIFTER
and ship_config.argo_float_config is None
):
raise PlanningError(
"Planning has waypoint with drifter instrument, but configuration does not configure drifters."
)
else:
raise RuntimeError("Instrument not supported.")


class PlanningError(RuntimeError):
"""An error in the schedule."""
Expand Down

0 comments on commit 29b5b0f

Please sign in to comment.