Skip to content

Commit ab0489e

Browse files
committed
add test for calc_wp_stationkeeping_time
1 parent 7cf9e63 commit ab0489e

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

src/virtualship/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from parcels import FieldSet
2020
from virtualship.errors import CopernicusCatalogueError
21-
from virtualship.instruments.types import InstrumentType
2221

2322
if TYPE_CHECKING:
2423
from virtualship.expedition.simulate_schedule import (
@@ -626,7 +625,9 @@ def _calc_wp_stationkeeping_time(
626625
expedition: Expedition,
627626
instrument_config_map: dict = INSTRUMENT_CONFIG_MAP,
628627
) -> timedelta:
629-
"""For a given waypoint, calculate how much time is required to carry out all instrument deployments."""
628+
"""For a given waypoint (and the instruments present at this waypoint), calculate how much time is required to carry out all instrument deployments."""
629+
from virtualship.instruments.types import InstrumentType # avoid circular imports
630+
630631
# TODO: this can be removed if/when CTD and CTD_BGC are merged to a single instrument
631632
both_ctd_and_bgc = (
632633
InstrumentType.CTD in wp_instrument_types

tests/test_utils.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
import virtualship.utils
99
from parcels import FieldSet
10+
from virtualship.instruments.types import InstrumentType
1011
from virtualship.models.expedition import Expedition
1112
from virtualship.utils import (
13+
_calc_wp_stationkeeping_time,
1214
_find_nc_file_with_variable,
1315
_get_bathy_data,
1416
_select_product_id,
@@ -241,3 +243,79 @@ def test_data_dir_and_filename_compliance():
241243
# TODO: test for calc_sail_time
242244

243245
# TODO: test for calc_stationkeeping_time
246+
247+
248+
def test_calc_wp_stationkeeping_time(expedition, monkeypatch):
249+
"""Test _calc_wp_stationkeeping_time for correct stationkeeping time calculation."""
250+
251+
class DummyInstrumentsConfig:
252+
def __init__(self, ctd, ctd_bgc, argo, xbt):
253+
self.ctd = ctd
254+
self.ctd_bgc = ctd_bgc
255+
self.argo = argo
256+
self.xbt = xbt
257+
258+
class CTDConfig:
259+
stationkeeping_time = datetime.timedelta(minutes=50)
260+
261+
class CTD_BGCConfig:
262+
stationkeeping_time = datetime.timedelta(minutes=50)
263+
264+
class ArgoFloatConfig:
265+
stationkeeping_time = datetime.timedelta(minutes=20)
266+
267+
class XBTConfig: # has no stationkeeping time
268+
deceleration_coefficient = 0.1
269+
270+
monkeypatch.setattr(
271+
"virtualship.utils.INSTRUMENT_CONFIG_MAP",
272+
{
273+
InstrumentType.CTD: "CTDConfig",
274+
InstrumentType.CTD_BGC: "CTD_BGCConfig",
275+
InstrumentType.ARGO_FLOAT: "ArgoFloatConfig",
276+
InstrumentType.XBT: "XBTConfig",
277+
},
278+
)
279+
280+
# Create a dummy expedition with instruments_config containing the dummy configs
281+
instruments_config = DummyInstrumentsConfig(
282+
ctd=CTDConfig(),
283+
ctd_bgc=CTD_BGCConfig(),
284+
argo=ArgoFloatConfig(),
285+
xbt=XBTConfig(),
286+
)
287+
expedition.instruments_config = (
288+
instruments_config # overwrite instruments_config with test dummy
289+
)
290+
291+
# instruments at a given waypoint
292+
wp_instrument_types_all = [
293+
InstrumentType.CTD,
294+
InstrumentType.CTD_BGC,
295+
InstrumentType.ARGO_FLOAT,
296+
InstrumentType.XBT,
297+
]
298+
299+
breakpoint()
300+
301+
# all dummy instruments
302+
stationkeeping_time_all = _calc_wp_stationkeeping_time(
303+
wp_instrument_types_all, expedition
304+
)
305+
assert (
306+
stationkeeping_time_all
307+
== CTDConfig.stationkeeping_time
308+
+ (
309+
CTD_BGCConfig.stationkeeping_time * 0.0
310+
) # CTD(_BGC) counted once when both present
311+
+ ArgoFloatConfig.stationkeeping_time
312+
)
313+
314+
# xbt only (no stationkeeping time)
315+
wp_instrument_types_xbt = [InstrumentType.XBT]
316+
stationkeeping_time_xbt = _calc_wp_stationkeeping_time(
317+
wp_instrument_types_xbt, expedition
318+
)
319+
assert stationkeeping_time_xbt == datetime.timedelta(0), (
320+
"XBT should have zero stationkeeping time"
321+
)

0 commit comments

Comments
 (0)