From 8917eb42cf3f89c94dbff684c5bf19978728fd3b Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 14:44:15 +0100 Subject: [PATCH 1/7] Supporting list of instruments --- src/virtualship/expedition/do_expedition.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index a6e9403d..907b2cf6 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -33,11 +33,11 @@ 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 = [] + for waypoint in schedule.waypoints: + if waypoint.instrument: + for instrument in waypoint.instrument: + instruments_in_schedule.append(instrument.name) for instrument in [ "ARGO_FLOAT", From 2cf9c14b69531ac44241d9936eccaa97c3445d0b Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 14:46:24 +0100 Subject: [PATCH 2/7] Adding unit tests for schedule.yaml --- src/virtualship/static/schedule.yaml | 12 ++++++++---- tests/expedition/expedition_dir/schedule.yaml | 14 +++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/virtualship/static/schedule.yaml b/src/virtualship/static/schedule.yaml index 678be7e3..82b9374a 100644 --- a/src/virtualship/static/schedule.yaml +++ b/src/virtualship/static/schedule.yaml @@ -10,22 +10,26 @@ 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 diff --git a/tests/expedition/expedition_dir/schedule.yaml b/tests/expedition/expedition_dir/schedule.yaml index 0db1d2af..b601f864 100644 --- a/tests/expedition/expedition_dir/schedule.yaml +++ b/tests/expedition/expedition_dir/schedule.yaml @@ -1,16 +1,24 @@ 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: # empty waypoint + location: + latitude: 0.02 + longitude: 0.01 + time: 2023-01-01 03:00:00 From 1e4bc833e24f0d3b4e5b9a1baa7aa60a05c0cd90 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 14:56:07 +0100 Subject: [PATCH 3/7] Fix schedule bug --- tests/expedition/expedition_dir/schedule.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/expedition/expedition_dir/schedule.yaml b/tests/expedition/expedition_dir/schedule.yaml index b601f864..1f672b67 100644 --- a/tests/expedition/expedition_dir/schedule.yaml +++ b/tests/expedition/expedition_dir/schedule.yaml @@ -6,7 +6,8 @@ waypoints: longitude: 0 time: 2023-01-01 00:00:00 - instrument: - - DRIFTER, CTD + - DRIFTER + - CTD location: latitude: 0.01 longitude: 0.01 From 381e77884a3706c7702e5a22a40b4a3ce353a6a2 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 14:59:52 +0100 Subject: [PATCH 4/7] Fixing another error in the yaml --- src/virtualship/static/schedule.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/virtualship/static/schedule.yaml b/src/virtualship/static/schedule.yaml index 82b9374a..a7b85ab9 100644 --- a/src/virtualship/static/schedule.yaml +++ b/src/virtualship/static/schedule.yaml @@ -17,7 +17,8 @@ waypoints: longitude: 0 time: 2023-01-01 00:00:00 - instrument: - - DRIFTER, CTD + - DRIFTER + - CTD location: latitude: 0.01 longitude: 0.01 From 574126519ca2f4427ff9cde47e2ebaa01f9a74c4 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 15:03:12 +0100 Subject: [PATCH 5/7] Updating locations without instruments --- src/virtualship/static/schedule.yaml | 4 ++++ tests/expedition/expedition_dir/schedule.yaml | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/virtualship/static/schedule.yaml b/src/virtualship/static/schedule.yaml index a7b85ab9..d15736d0 100644 --- a/src/virtualship/static/schedule.yaml +++ b/src/virtualship/static/schedule.yaml @@ -35,3 +35,7 @@ waypoints: 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/tests/expedition/expedition_dir/schedule.yaml b/tests/expedition/expedition_dir/schedule.yaml index 1f672b67..d60007ed 100644 --- a/tests/expedition/expedition_dir/schedule.yaml +++ b/tests/expedition/expedition_dir/schedule.yaml @@ -18,8 +18,7 @@ waypoints: latitude: 0.02 longitude: 0.02 time: 2023-01-01 02:00:00 - - instrument: # empty waypoint - location: + - location: # empty waypoint latitude: 0.02 longitude: 0.01 time: 2023-01-01 03:00:00 From d8fd66283eaf1077d299f69205a10f7aa93d06a4 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 15:16:22 +0100 Subject: [PATCH 6/7] Creating get_instruments_in_schedule() function --- src/virtualship/cli/commands.py | 14 +++++++------- src/virtualship/expedition/do_expedition.py | 13 +++++++------ src/virtualship/utils.py | 10 ++++++++++ 3 files changed, 24 insertions(+), 13 deletions(-) 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 907b2cf6..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 = [] - for waypoint in schedule.waypoints: - if waypoint.instrument: - for instrument in waypoint.instrument: - instruments_in_schedule.append(instrument.name) + instruments_in_schedule = get_instruments_in_schedule(schedule) for instrument in [ "ARGO_FLOAT", 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 From 99527667b6dbdf44d266fdb4b8229ee59bb7c28f Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 21 Feb 2025 15:26:54 +0100 Subject: [PATCH 7/7] Update test schedule --- tests/expedition/expedition_dir/schedule.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/expedition/expedition_dir/schedule.yaml b/tests/expedition/expedition_dir/schedule.yaml index d60007ed..29c14ac9 100644 --- a/tests/expedition/expedition_dir/schedule.yaml +++ b/tests/expedition/expedition_dir/schedule.yaml @@ -7,18 +7,12 @@ waypoints: time: 2023-01-01 00:00:00 - instrument: - DRIFTER - - CTD + - ARGO_FLOAT location: latitude: 0.01 longitude: 0.01 - time: 2023-01-01 01:00:00 - - instrument: - - ARGO_FLOAT - location: - latitude: 0.02 - longitude: 0.02 - time: 2023-01-01 02:00:00 + time: 2023-01-02 00:00:00 - location: # empty waypoint latitude: 0.02 longitude: 0.01 - time: 2023-01-01 03:00:00 + time: 2023-01-02 03:00:00