Skip to content

Commit 650cb21

Browse files
committed
updating tests and better unexpected error handling
1 parent f3bad07 commit 650cb21

6 files changed

Lines changed: 28 additions & 12 deletions

File tree

src/virtualship/cli/_run.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import copernicusmarine
1010

11+
from virtualship.errors import ProblemsError
1112
from virtualship.expedition.simulate_schedule import (
1213
MeasurementsToSimulate,
1314
ScheduleProblem,
@@ -168,12 +169,20 @@ def _run(
168169
and problems["problem_class"][0].pre_departure
169170
else f"\033[4mUp next\033[0m: {itype.name} measurements...\n"
170171
)
171-
172-
problem_simulator.execute(
173-
problems,
174-
instrument_type_validation=itype,
175-
problems_dir=problems_dir,
176-
)
172+
try:
173+
problem_simulator.execute(
174+
problems,
175+
instrument_type_validation=itype,
176+
problems_dir=problems_dir,
177+
)
178+
179+
except Exception as e:
180+
os.removedirs(problems_dir) # clean up if fails
181+
os.remove(expedition_dir.joinpath(CHECKPOINT))
182+
raise ProblemsError(
183+
f"An error occurred while simulating problems: {e}. Please report this issue, with a description and the traceback, "
184+
"to the VirtualShip issue tracker at: https://github.com/OceanParcels/virtualship/issues"
185+
) from e
177186

178187
# get measurements to simulate
179188
attr = MeasurementsToSimulate.get_attr_for_instrumenttype(itype)

src/virtualship/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CopernicusCatalogueError(Exception):
5252
pass
5353

5454

55-
class ProblemEncountered(Exception):
56-
"""Error raised when a problem is encountered during simulation."""
55+
class ProblemsError(Exception):
56+
"""Error raised when simulation of problem(s) in expedition fails."""
5757

5858
pass

src/virtualship/expedition/simulate_schedule.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def _progress_time_traveling_towards(self, location: Location) -> None:
150150
self._projection,
151151
)
152152
end_time = self._time + time_to_reach
153-
154153
# note all ADCP measurements
155154
if self._expedition.instruments_config.adcp_config is not None:
156155
location = self._location

src/virtualship/models/checkpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def verify(self, expedition: Expedition, problems_dir: Path) -> None:
111111

112112
# problem at a later waypoint: check new scheduled time exceeds sail time + delay duration + instrument deployment time (rather whole delay duration add-on, as there may be _some_ contingency time already scheduled)
113113
else:
114+
breakpoint()
114115
failed_waypoint = new_schedule.waypoints[self.failed_waypoint_i]
115116

116117
scheduled_time = failed_waypoint.time - problem_waypoint.time

src/virtualship/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def _calc_sail_time(
616616
distance_to_next_waypoint = geodinv[2]
617617
return (
618618
timedelta(seconds=distance_to_next_waypoint / ship_speed_meter_per_second),
619-
geodinv,
619+
geodinv[0],
620620
ship_speed_meter_per_second,
621621
)
622622

@@ -650,7 +650,12 @@ def _calc_wp_stationkeeping_time(
650650
# get wp total stationkeeping time
651651
cumulative_stationkeeping_time = timedelta()
652652
for iconfig in wp_instrument_configs:
653-
if both_ctd_and_bgc and iconfig.instrument_type == InstrumentType.CTD_BGC:
653+
breakpoint()
654+
if (
655+
both_ctd_and_bgc
656+
and iconfig.__class__.__name__
657+
== INSTRUMENT_CONFIG_MAP[InstrumentType.CTD_BGC]
658+
):
654659
continue # only need to add time cost once if both CTD and CTD_BGC are being taken; in reality they would be done on the same instrument
655660
if hasattr(iconfig, "stationkeeping_time"):
656661
cumulative_stationkeeping_time += iconfig.stationkeeping_time

tests/cli/test_run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def test_run(tmp_path, monkeypatch):
5353
fake_data_dir = tmp_path / "fake_data"
5454
fake_data_dir.mkdir()
5555

56-
_run(expedition_dir, from_data=fake_data_dir)
56+
_run(
57+
expedition_dir, prob_level=0, from_data=fake_data_dir
58+
) # problems turned off here
5759

5860
results_dir = expedition_dir / "results"
5961

0 commit comments

Comments
 (0)