Skip to content

Commit f9cec7b

Browse files
Supporting list of instruments in yaml (#147)
* Supporting list of instruments * Adding unit tests for schedule.yaml * Fix schedule bug * Fixing another error in the yaml * Updating locations without instruments * Creating get_instruments_in_schedule() function * Update test schedule
1 parent aea2a2d commit f9cec7b

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

src/virtualship/cli/commands.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
_get_ship_config,
2121
do_expedition,
2222
)
23-
from virtualship.utils import SCHEDULE, SHIP_CONFIG, mfp_to_yaml
23+
from virtualship.utils import (
24+
SCHEDULE,
25+
SHIP_CONFIG,
26+
get_instruments_in_schedule,
27+
mfp_to_yaml,
28+
)
2429

2530

2631
@click.command()
@@ -135,12 +140,7 @@ def fetch(path: str | Path, username: str | None, password: str | None) -> None:
135140
time_range = schedule.space_time_region.time_range
136141
start_datetime = time_range.start_time
137142
end_datetime = time_range.end_time
138-
instruments_in_schedule = [
139-
waypoint.instrument[0].name
140-
if isinstance(waypoint.instrument, list)
141-
else waypoint.instrument.name
142-
for waypoint in schedule.waypoints # TODO check why instrument is a list here
143-
]
143+
instruments_in_schedule = get_instruments_in_schedule(schedule)
144144

145145
# Create download folder and set download metadata
146146
download_folder = data_folder / hash_to_filename(space_time_region_hash)

src/virtualship/expedition/do_expedition.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import pyproj
88

99
from virtualship.cli._fetch import get_existing_download, get_space_time_region_hash
10-
from virtualship.utils import CHECKPOINT, SCHEDULE, SHIP_CONFIG
10+
from virtualship.utils import (
11+
CHECKPOINT,
12+
SCHEDULE,
13+
SHIP_CONFIG,
14+
get_instruments_in_schedule,
15+
)
1116

1217
from .checkpoint import Checkpoint
1318
from .expedition_cost import expedition_cost
@@ -33,11 +38,7 @@ def do_expedition(expedition_dir: str | Path, input_data: Path | None = None) ->
3338
schedule = _get_schedule(expedition_dir)
3439

3540
# remove instrument configurations that are not in schedule
36-
instruments_in_schedule = [
37-
waypoint.instrument.name
38-
for waypoint in schedule.waypoints
39-
if waypoint.instrument
40-
]
41+
instruments_in_schedule = get_instruments_in_schedule(schedule)
4142

4243
for instrument in [
4344
"ARGO_FLOAT",

src/virtualship/static/schedule.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@ space_time_region:
1010
start_time: 2023-01-01 00:00:00
1111
end_time: 2023-02-01 00:00:00
1212
waypoints:
13-
- instrument: CTD
13+
- instrument:
14+
- CTD
1415
location:
1516
latitude: 0
1617
longitude: 0
1718
time: 2023-01-01 00:00:00
18-
- instrument: DRIFTER
19+
- instrument:
20+
- DRIFTER
21+
- CTD
1922
location:
2023
latitude: 0.01
2124
longitude: 0.01
2225
time: 2023-01-01 01:00:00
23-
- instrument: ARGO_FLOAT
26+
- instrument:
27+
- ARGO_FLOAT
2428
location:
2529
latitude: 0.02
2630
longitude: 0.02
2731
time: 2023-01-01 02:00:00
28-
- instrument: XBT
32+
- instrument:
33+
- XBT
2934
location:
3035
latitude: 0.03
3136
longitude: 0.03
3237
time: 2023-01-01 03:00:00
38+
- location:
39+
latitude: 0.03
40+
longitude: 0.03
41+
time: 2023-01-01 03:00:00

src/virtualship/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,13 @@ def _validate_numeric_mins_to_timedelta(value: int | float | timedelta) -> timed
173173
if isinstance(value, timedelta):
174174
return value
175175
return timedelta(minutes=value)
176+
177+
178+
def get_instruments_in_schedule(schedule):
179+
instruments_in_schedule = []
180+
for waypoint in schedule.waypoints:
181+
if waypoint.instrument:
182+
for instrument in waypoint.instrument:
183+
if instrument:
184+
instruments_in_schedule.append(instrument.name)
185+
return instruments_in_schedule
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
waypoints:
2-
- instrument: CTD
2+
- instrument:
3+
- CTD
34
location:
45
latitude: 0
56
longitude: 0
67
time: 2023-01-01 00:00:00
7-
- instrument: DRIFTER
8+
- instrument:
9+
- DRIFTER
10+
- ARGO_FLOAT
811
location:
912
latitude: 0.01
1013
longitude: 0.01
11-
time: 2023-01-01 01:00:00
12-
- instrument: ARGO_FLOAT
13-
location:
14+
time: 2023-01-02 00:00:00
15+
- location: # empty waypoint
1416
latitude: 0.02
15-
longitude: 0.02
16-
time: 2023-01-01 02:00:00
17+
longitude: 0.01
18+
time: 2023-01-02 03:00:00

0 commit comments

Comments
 (0)