|
7 | 7 |
|
8 | 8 | import virtualship.utils |
9 | 9 | from parcels import FieldSet |
| 10 | +from virtualship.instruments.types import InstrumentType |
10 | 11 | from virtualship.models.expedition import Expedition |
11 | 12 | from virtualship.utils import ( |
| 13 | + _calc_wp_stationkeeping_time, |
12 | 14 | _find_nc_file_with_variable, |
13 | 15 | _get_bathy_data, |
14 | 16 | _select_product_id, |
@@ -241,3 +243,79 @@ def test_data_dir_and_filename_compliance(): |
241 | 243 | # TODO: test for calc_sail_time |
242 | 244 |
|
243 | 245 | # 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