Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/virtualship/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions src/virtualship/expedition/do_expedition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
17 changes: 13 additions & 4 deletions src/virtualship/static/schedule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/virtualship/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 9 additions & 7 deletions tests/expedition/expedition_dir/schedule.yaml
Original file line number Diff line number Diff line change
@@ -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