diff --git a/src/virtualship/cli/commands.py b/src/virtualship/cli/commands.py index 0ede4ff9..97b03048 100644 --- a/src/virtualship/cli/commands.py +++ b/src/virtualship/cli/commands.py @@ -20,7 +20,12 @@ _get_ship_config, do_expedition, ) -from virtualship.utils import SCHEDULE, SHIP_CONFIG, mfp_to_yaml +from virtualship.utils import ( + SCHEDULE, + SHIP_CONFIG, + get_instruments_in_schedule, + mfp_to_yaml, +) @click.command() @@ -135,12 +140,7 @@ def fetch(path: str | Path, username: str | None, password: str | None) -> None: time_range = schedule.space_time_region.time_range start_datetime = time_range.start_time end_datetime = time_range.end_time - instruments_in_schedule = [ - waypoint.instrument[0].name - if isinstance(waypoint.instrument, list) - else waypoint.instrument.name - for waypoint in schedule.waypoints # TODO check why instrument is a list here - ] + instruments_in_schedule = get_instruments_in_schedule(schedule) # Create download folder and set download metadata download_folder = data_folder / hash_to_filename(space_time_region_hash) diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index a6e9403d..b199bb4a 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -7,7 +7,12 @@ import pyproj from virtualship.cli._fetch import get_existing_download, get_space_time_region_hash -from virtualship.utils import CHECKPOINT, SCHEDULE, SHIP_CONFIG +from virtualship.utils import ( + CHECKPOINT, + SCHEDULE, + SHIP_CONFIG, + get_instruments_in_schedule, +) from .checkpoint import Checkpoint from .expedition_cost import expedition_cost @@ -33,11 +38,7 @@ def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) -> schedule = _get_schedule(expedition_dir) # remove instrument configurations that are not in schedule - instruments_in_schedule = [ - waypoint.instrument.name - for waypoint in schedule.waypoints - if waypoint.instrument - ] + instruments_in_schedule = get_instruments_in_schedule(schedule) for instrument in [ "ARGO_FLOAT", diff --git a/src/virtualship/static/schedule.yaml b/src/virtualship/static/schedule.yaml index 678be7e3..d15736d0 100644 --- a/src/virtualship/static/schedule.yaml +++ b/src/virtualship/static/schedule.yaml @@ -10,23 +10,32 @@ space_time_region: start_time: 2023-01-01 00:00:00 end_time: 2023-02-01 00:00:00 waypoints: - - instrument: CTD + - instrument: + - CTD location: latitude: 0 longitude: 0 time: 2023-01-01 00:00:00 - - instrument: DRIFTER + - instrument: + - DRIFTER + - CTD location: latitude: 0.01 longitude: 0.01 time: 2023-01-01 01:00:00 - - instrument: ARGO_FLOAT + - instrument: + - ARGO_FLOAT location: latitude: 0.02 longitude: 0.02 time: 2023-01-01 02:00:00 - - instrument: XBT + - instrument: + - XBT location: latitude: 0.03 longitude: 0.03 time: 2023-01-01 03:00:00 + - location: + latitude: 0.03 + longitude: 0.03 + time: 2023-01-01 03:00:00 diff --git a/src/virtualship/utils.py b/src/virtualship/utils.py index ad48b0af..bc8a3dbe 100644 --- a/src/virtualship/utils.py +++ b/src/virtualship/utils.py @@ -173,3 +173,13 @@ def _validate_numeric_mins_to_timedelta(value: int | float | timedelta) -> timed if isinstance(value, timedelta): return value return timedelta(minutes=value) + + +def get_instruments_in_schedule(schedule): + instruments_in_schedule = [] + for waypoint in schedule.waypoints: + if waypoint.instrument: + for instrument in waypoint.instrument: + if instrument: + instruments_in_schedule.append(instrument.name) + return instruments_in_schedule diff --git a/tests/expedition/expedition_dir/schedule.yaml b/tests/expedition/expedition_dir/schedule.yaml index 0db1d2af..29c14ac9 100644 --- a/tests/expedition/expedition_dir/schedule.yaml +++ b/tests/expedition/expedition_dir/schedule.yaml @@ -1,16 +1,18 @@ waypoints: - - instrument: CTD + - instrument: + - CTD location: latitude: 0 longitude: 0 time: 2023-01-01 00:00:00 - - instrument: DRIFTER + - instrument: + - DRIFTER + - ARGO_FLOAT location: latitude: 0.01 longitude: 0.01 - time: 2023-01-01 01:00:00 - - instrument: ARGO_FLOAT - location: + time: 2023-01-02 00:00:00 + - location: # empty waypoint latitude: 0.02 - longitude: 0.02 - time: 2023-01-01 02:00:00 + longitude: 0.01 + time: 2023-01-02 03:00:00