From 79b776a889225231710a9fbfc12544dee8790d11 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 14 Feb 2025 12:32:05 +0100 Subject: [PATCH 1/4] remove instrument configurations that are not in schedule This fixes #118 --- src/virtualship/expedition/do_expedition.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index 1846ea14..ce3014eb 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -32,6 +32,15 @@ def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) -> ship_config = _get_ship_config(expedition_dir) schedule = _get_schedule(expedition_dir) + # remove instrument configurations that are not in schedule + instruments_in_schedule = set( + [waypoint.instrument for waypoint in schedule.waypoints] + ) + for instrument in ['argo_float', 'drifter']: + if hasattr(ship_config, instrument + "_config") and instrument not in instruments_in_schedule: + print(f"{instrument} configuration provided but not in schedule.") + setattr(ship_config, instrument + "_config", None) + # load last checkpoint checkpoint = _load_checkpoint(expedition_dir) if checkpoint is None: From 7533d29a4cc1edbf1bcf721f5d74f0f51394524e Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 14 Feb 2025 12:45:23 +0100 Subject: [PATCH 2/4] Using rglob() to recursively travel through expedition_dir --- src/virtualship/cli/_fetch.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/virtualship/cli/_fetch.py b/src/virtualship/cli/_fetch.py index cfa52a61..d0e9d7d6 100644 --- a/src/virtualship/cli/_fetch.py +++ b/src/virtualship/cli/_fetch.py @@ -89,13 +89,10 @@ def get_existing_download( data_folder: Path, space_time_region_hash: str ) -> Path | None: """Check if a download has already been completed. If so, return the path for existing download.""" - for download_path in data_folder.iterdir(): + for download_path in data_folder.rglob("*"): try: hash = filename_to_hash(download_path.name) except ValueError: - click.echo( - f"Skipping {download_path.name} as it is not a valid download folder name." - ) continue if hash == space_time_region_hash: From 890c7486848af8f7c08a3fc88d812d7bd90b80c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:46:05 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/virtualship/cli/_fetch.py | 1 - src/virtualship/expedition/do_expedition.py | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/virtualship/cli/_fetch.py b/src/virtualship/cli/_fetch.py index d0e9d7d6..4eb0d2d3 100644 --- a/src/virtualship/cli/_fetch.py +++ b/src/virtualship/cli/_fetch.py @@ -5,7 +5,6 @@ from pathlib import Path from typing import TYPE_CHECKING -import click from pydantic import BaseModel from virtualship.utils import _dump_yaml, _generic_load_yaml diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index ce3014eb..d17b51b7 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -36,8 +36,11 @@ def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) -> instruments_in_schedule = set( [waypoint.instrument for waypoint in schedule.waypoints] ) - for instrument in ['argo_float', 'drifter']: - if hasattr(ship_config, instrument + "_config") and instrument not in instruments_in_schedule: + for instrument in ["argo_float", "drifter"]: + if ( + hasattr(ship_config, instrument + "_config") + and instrument not in instruments_in_schedule + ): print(f"{instrument} configuration provided but not in schedule.") setattr(ship_config, instrument + "_config", None) From 0ba66a11c0a4ba881f1895c22770187b8ae63774 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 14 Feb 2025 13:07:43 +0100 Subject: [PATCH 4/4] Fixing instrument list and work-around for lowercase-vs-capitalised instrument names --- src/virtualship/cli/_fetch.py | 1 - src/virtualship/expedition/do_expedition.py | 23 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/virtualship/cli/_fetch.py b/src/virtualship/cli/_fetch.py index d0e9d7d6..4eb0d2d3 100644 --- a/src/virtualship/cli/_fetch.py +++ b/src/virtualship/cli/_fetch.py @@ -5,7 +5,6 @@ from pathlib import Path from typing import TYPE_CHECKING -import click from pydantic import BaseModel from virtualship.utils import _dump_yaml, _generic_load_yaml diff --git a/src/virtualship/expedition/do_expedition.py b/src/virtualship/expedition/do_expedition.py index ce3014eb..de5d8a3a 100644 --- a/src/virtualship/expedition/do_expedition.py +++ b/src/virtualship/expedition/do_expedition.py @@ -33,13 +33,24 @@ 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 = set( - [waypoint.instrument for waypoint in schedule.waypoints] - ) - for instrument in ['argo_float', 'drifter']: - if hasattr(ship_config, instrument + "_config") and instrument not in instruments_in_schedule: + instruments_in_schedule = [ + waypoint.instrument.name for waypoint in schedule.waypoints + ] + + for instrument in [ + "ARGO_FLOAT", + "DRIFTER", + "XBT", + "CTD", + "ADCP", + "SHIP_UNDERWATER_ST", + ]: # TODO make instrument names consistent capitals or lowercase throughout codebase + if ( + hasattr(ship_config, instrument.lower() + "_config") + and instrument not in instruments_in_schedule + ): print(f"{instrument} configuration provided but not in schedule.") - setattr(ship_config, instrument + "_config", None) + setattr(ship_config, instrument.lower() + "_config", None) # load last checkpoint checkpoint = _load_checkpoint(expedition_dir)