Skip to content

Commit 82c52ff

Browse files
authored
make parameter consistent (#91)
Made sure the `vertical_mixing_at_surface` is consistent with `vertical_mixing` and `vertical_advection_at_surface` is consistent with `do3D`.
1 parent a428fd8 commit 82c52ff

3 files changed

Lines changed: 189 additions & 5 deletions

File tree

docs/whats_new.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# What's New
22

3-
## Unreleased
3+
## 3.0.0 (March 12, 2026)
44

55
* Fixed bug so that horizontal diffusivity is now properly applied to model output.
66
* Added `wind_drift` parameter which when False makes sure that `wind_drift_factor=0` so that wind drift is not on.
77
* If `do3D==False`, vertical_mixing is now also turned to False. Otherwise it is easy to run 2D with vertical mixing on.
8+
* Made sure the `vertical_mixing_at_surface` is consistent with `vertical_mixing` and `vertical_advection_at_surface` is consistent with `do3D`.
89

910
## 2.5.0 (March 9, 2026)
1011

particle_tracking_manager/models/opendrift/config_opendrift.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class OceanDriftModelConfig(OpenDriftConfig):
476476
)
477477

478478
vertical_mixing: bool = Field(
479-
default=False,
479+
default=True,
480480
description="Activate vertical mixing scheme. Vertical mixing includes movement due to buoyancy and turbulent mixing.",
481481
title="Vertical Mixing",
482482
json_schema_extra={
@@ -486,7 +486,7 @@ class OceanDriftModelConfig(OpenDriftConfig):
486486
)
487487

488488
vertical_mixing_at_surface: bool = Field(
489-
default=False,
489+
default=True,
490490
description="If vertical mixing is activated, surface elements (z=0) can only be mixed (downwards) if this setting it True.",
491491
title="Vertical Mixing At Surface",
492492
json_schema_extra={
@@ -521,6 +521,46 @@ def check_config_do3D(self) -> Self:
521521
logger.debug("Setting vertical_mixing to False because do3D is False.")
522522
return self
523523

524+
@model_validator(mode="after")
525+
def check_vertical_advection_at_surface_True(self) -> Self:
526+
"""If do3D is True, vertical_advection_at_surface is also True."""
527+
if self.do3D:
528+
self.vertical_advection_at_surface = True
529+
logger.debug(
530+
"Setting vertical_advection_at_surface to True because do3D is True."
531+
)
532+
return self
533+
534+
@model_validator(mode="after")
535+
def check_vertical_advection_at_surface_False(self) -> Self:
536+
"""If do3D is False, vertical_advection_at_surface is also False."""
537+
if not self.do3D:
538+
self.vertical_advection_at_surface = False
539+
logger.debug(
540+
"Setting vertical_advection_at_surface to False because do3D is False."
541+
)
542+
return self
543+
544+
@model_validator(mode="after")
545+
def check_vertical_mixing_at_surface_True(self) -> Self:
546+
"""If vertical_mixing is True, vertical_mixing_at_surface must also be True."""
547+
if self.vertical_mixing:
548+
self.vertical_mixing_at_surface = True
549+
logger.debug(
550+
"Setting vertical_mixing_at_surface to True because vertical_mixing is True."
551+
)
552+
return self
553+
554+
@model_validator(mode="after")
555+
def check_vertical_mixing_at_surface_False(self) -> Self:
556+
"""If vertical_mixing is False, vertical_mixing_at_surface must also be False."""
557+
if not self.vertical_mixing:
558+
self.vertical_mixing_at_surface = False
559+
logger.debug(
560+
"Setting vertical_mixing_at_surface to False because vertical_mixing is False."
561+
)
562+
return self
563+
524564

525565
class OpenOilModelConfig(OceanDriftModelConfig):
526566
"""OpenOil model configuration for OpenDrift."""
@@ -685,11 +725,11 @@ class OpenOilModelConfig(OceanDriftModelConfig):
685725
OceanDriftModelConfig.model_fields["wind_drift_factor"], Field(default=0.03)
686726
)
687727
vertical_mixing: bool = FieldInfo.merge_field_infos(
688-
OceanDriftModelConfig.model_fields["vertical_mixing"], Field(default=False)
728+
OceanDriftModelConfig.model_fields["vertical_mixing"], Field(default=True)
689729
)
690730
vertical_mixing_at_surface: bool = FieldInfo.merge_field_infos(
691731
OceanDriftModelConfig.model_fields["vertical_mixing_at_surface"],
692-
Field(default=False),
732+
Field(default=True),
693733
)
694734
vertical_advection_at_surface: bool = FieldInfo.merge_field_infos(
695735
OceanDriftModelConfig.model_fields["vertical_advection_at_surface"],

tests/test_config_opendrift.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,149 @@ def test_do3D_vertical_mixing_False():
187187
assert m.vertical_mixing == False
188188

189189

190+
def test_vertical_advection_surface():
191+
"""If do3D is False, vertical_advection_at_surface should be set to False
192+
193+
and if True, vertical_advection_at_surface should be set to True."""
194+
195+
# OceanDrift
196+
m = OceanDriftModelConfig(
197+
steps=1,
198+
do3D=False,
199+
start_time="2022-01-01",
200+
vertical_advection_at_surface=True,
201+
)
202+
assert m.vertical_advection_at_surface == False
203+
204+
m = OceanDriftModelConfig(
205+
steps=1,
206+
do3D=True,
207+
start_time="2022-01-01",
208+
vertical_advection_at_surface=False,
209+
)
210+
assert m.vertical_advection_at_surface == True
211+
212+
# OpenOil
213+
m = OpenOilModelConfig(
214+
steps=1,
215+
do3D=False,
216+
start_time="2022-01-01",
217+
vertical_advection_at_surface=True,
218+
)
219+
assert m.vertical_advection_at_surface == False
220+
221+
m = OpenOilModelConfig(
222+
steps=1,
223+
do3D=True,
224+
start_time="2022-01-01",
225+
vertical_advection_at_surface=False,
226+
)
227+
assert m.vertical_advection_at_surface == True
228+
229+
# Phytoplankton
230+
m = PhytoplanktonModelConfig(
231+
steps=1,
232+
do3D=False,
233+
start_time="2022-01-01",
234+
vertical_advection_at_surface=True,
235+
)
236+
assert m.vertical_advection_at_surface == False
237+
238+
m = PhytoplanktonModelConfig(
239+
steps=1,
240+
do3D=True,
241+
start_time="2022-01-01",
242+
vertical_advection_at_surface=False,
243+
)
244+
assert m.vertical_advection_at_surface == True
245+
246+
m = LarvalFishModelConfig(
247+
steps=1,
248+
do3D=True,
249+
start_time="2022-01-01",
250+
vertical_advection_at_surface=False,
251+
)
252+
assert m.vertical_advection_at_surface == True
253+
254+
255+
def test_vertical_mixing_surface():
256+
"""If vertical_mixing is True, vertical_mixing_at_surface should be True
257+
258+
and if False, vertical_mixing_at_surface should be False."""
259+
260+
# OceanDrift
261+
m = OceanDriftModelConfig(
262+
steps=1,
263+
vertical_mixing=True,
264+
start_time="2022-01-01",
265+
vertical_mixing_at_surface=False,
266+
do3D=True,
267+
)
268+
assert m.vertical_mixing_at_surface == True
269+
270+
m = OceanDriftModelConfig(
271+
steps=1,
272+
vertical_mixing=False,
273+
start_time="2022-01-01",
274+
vertical_mixing_at_surface=True,
275+
)
276+
assert m.vertical_mixing_at_surface == False
277+
278+
# OpenOil
279+
m = OpenOilModelConfig(
280+
steps=1,
281+
vertical_mixing=True,
282+
start_time="2022-01-01",
283+
vertical_mixing_at_surface=False,
284+
do3D=True,
285+
)
286+
assert m.vertical_mixing_at_surface == True
287+
288+
m = OpenOilModelConfig(
289+
steps=1,
290+
vertical_mixing=False,
291+
start_time="2022-01-01",
292+
vertical_mixing_at_surface=True,
293+
)
294+
assert m.vertical_mixing_at_surface == False
295+
296+
# Phytoplankton
297+
m = PhytoplanktonModelConfig(
298+
steps=1,
299+
vertical_mixing=True,
300+
start_time="2022-01-01",
301+
vertical_mixing_at_surface=False,
302+
do3D=True,
303+
)
304+
assert m.vertical_mixing_at_surface == True
305+
306+
m = PhytoplanktonModelConfig(
307+
steps=1,
308+
vertical_mixing=False,
309+
start_time="2022-01-01",
310+
vertical_mixing_at_surface=True,
311+
)
312+
assert m.vertical_mixing_at_surface == False
313+
314+
# LarvalFish
315+
m = LarvalFishModelConfig(
316+
steps=1,
317+
vertical_mixing=True,
318+
start_time="2022-01-01",
319+
vertical_mixing_at_surface=False,
320+
do3D=True,
321+
)
322+
assert m.vertical_mixing_at_surface == True
323+
324+
m = LarvalFishModelConfig(
325+
steps=1,
326+
vertical_mixing=False,
327+
start_time="2022-01-01",
328+
vertical_mixing_at_surface=True,
329+
)
330+
assert m.vertical_mixing_at_surface == False
331+
332+
190333
def test_OceanDrift_parameters():
191334
"""Make sure OceanDrift-specific parameters are present."""
192335
m = OceanDriftModelConfig(drift_model="OceanDrift", steps=1)

0 commit comments

Comments
 (0)