Skip to content

Commit af86676

Browse files
authored
updated HAB schema (#65)
* updated HAB schema * precommit
1 parent 4e4cc78 commit af86676

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

docs/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ m = ptm.OpenDriftModel(drift_model="HarmfulAlgalBloom", lon = -89.8, lat = 29.08
6565
ocean_model="TXLA",
6666
start_time="2009-11-19T12:00",
6767
ocean_model_local=False,
68-
species_type="Pseudo_nitzschia",
68+
species_type="Pseudo nitzschia",
6969
plots={'spaghetti': {}})
7070
```
7171

docs/whats_new.md

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

3-
## Unreleased
3+
## v2.0.2 (Decemeber 5, 2025)
4+
5+
* Changed "name" of `HarmfulAlgalBloom` `species_type` enum to be an abbreviation "PN" and the value for the initial species to be "Pseudo nitzschia" instead of "Pseudo_nitzschia".
6+
* Added to the `HarmfulAlgalBloom` schema to have a "oneOf" output containing the preset values associated with a `species_type` in the description.
7+
8+
## v2.0.0 (December 4, 2025)
49

510
* Added a new model scenario: `HarmfalAlgalBloom`.
611
* Fix a bug for running backward in time.

particle_tracking_manager/models/opendrift/config_opendrift.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
SPECIES_HAB_DEFAULTS,
3131
SPECIES_HAB_MANAGER_DEFAULTS,
3232
HABParameters,
33+
_species_descriptions,
3334
)
3435

3536

@@ -770,12 +771,22 @@ class HarmfulAlgalBloomModelConfig(HABParameters, OceanDriftModelConfig):
770771
"""Harmful algal bloom model configuration for OpenDrift."""
771772

772773
drift_model: DriftModelEnum = DriftModelEnum.HarmfulAlgalBloom
773-
774+
# import pdb; pdb.set_trace()
774775
species_type: HABSpeciesTypeEnum = Field(
775-
default=HABSpeciesTypeEnum("Pseudo_nitzschia"),
776+
default=HABSpeciesTypeEnum.PN,
776777
description="HarmfulAlgalBloom species category for this simulation. This option maps to individual properties which can instead be set manually if desired.",
777778
title="HAB Species Type",
778-
json_schema_extra={"ptm_level": 1},
779+
json_schema_extra={
780+
"ptm_level": 1,
781+
"oneOf": [
782+
{
783+
"const": species.name,
784+
"title": species.value,
785+
"description": _species_descriptions[species.value],
786+
}
787+
for species in HABSpeciesTypeEnum
788+
],
789+
},
779790
)
780791

781792
# # new field: full parameter bundle for the HAB species
@@ -824,7 +835,7 @@ def apply_species_defaults(cls, data: Any) -> Any:
824835
return data
825836

826837
# Ensure species_type has some value in raw input
827-
data.setdefault("species_type", HABSpeciesTypeEnum("Pseudo_nitzschia"))
838+
data.setdefault("species_type", HABSpeciesTypeEnum.PN)
828839
species = data["species_type"]
829840

830841
# -------- HAB param defaults (flattened) --------

particle_tracking_manager/models/opendrift/enums/species_types.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class HABSpeciesTypeEnum(str, Enum):
99
"""Enum for species types used in HarmfulAlgalBloom model in OpenDrift."""
1010

11-
Pseudo_nitzschia = "Pseudo_nitzschia"
11+
PN = "Pseudo nitzschia"
1212
custom = "custom" # for fully user-specified params
1313

1414

@@ -20,6 +20,7 @@ class HABParameters(BaseModel):
2020
title="Cell death below this temperature",
2121
ge=-5.0,
2222
le=40.0,
23+
default=3.0,
2324
json_schema_extra={
2425
"units": "degrees",
2526
"od_mapping": "hab:temperature_death_min",
@@ -32,6 +33,7 @@ class HABParameters(BaseModel):
3233
title="Cell death above this temperature",
3334
ge=-5.0,
3435
le=40.0,
36+
default=22.0,
3537
json_schema_extra={
3638
"units": "degrees",
3739
"od_mapping": "hab:temperature_death_max",
@@ -44,6 +46,7 @@ class HABParameters(BaseModel):
4446
title="High mortality rate",
4547
ge=0.0,
4648
le=10.0,
49+
default=1.0,
4750
json_schema_extra={
4851
"units": "days^-1",
4952
"od_mapping": "hab:mortality_rate_high",
@@ -56,6 +59,7 @@ class HABParameters(BaseModel):
5659
title="Cell death below this salinity",
5760
ge=0.0,
5861
le=50.0,
62+
default=25.0,
5963
json_schema_extra={
6064
"units": "psu",
6165
"od_mapping": "hab:salinity_death_min",
@@ -68,6 +72,7 @@ class HABParameters(BaseModel):
6872
title="Cell death above this salinity",
6973
ge=0.0,
7074
le=50.0,
75+
default=36.0,
7176
json_schema_extra={
7277
"units": "psu",
7378
"od_mapping": "hab:salinity_death_max",
@@ -78,7 +83,7 @@ class HABParameters(BaseModel):
7883

7984
# Species default for HarmfulAlgalBloom model
8085
SPECIES_HAB_DEFAULTS: dict[HABSpeciesTypeEnum, HABParameters] = {
81-
HABSpeciesTypeEnum.Pseudo_nitzschia: HABParameters(
86+
HABSpeciesTypeEnum.PN: HABParameters(
8287
temperature_death_min=3.0,
8388
temperature_death_max=22.0,
8489
mortality_rate_high=1.0,
@@ -91,10 +96,24 @@ class HABParameters(BaseModel):
9196

9297
# Other config defaults per species (z, do3D, etc.)
9398
SPECIES_HAB_MANAGER_DEFAULTS: dict[HABSpeciesTypeEnum, dict[str, object]] = {
94-
HABSpeciesTypeEnum.Pseudo_nitzschia: {
99+
HABSpeciesTypeEnum.PN: {
95100
"z": -1.0,
96101
"do3D": False,
97102
},
98103
# HABSpeciesTypeEnum.Alexandrium: {"do3D": True, ...},
99104
# HABSpeciesTypeEnum.Dinophysis: {...},
100105
}
106+
107+
# this is for the schema
108+
_species_descriptions = {
109+
species.value: "Defaults: "
110+
+ ", ".join(
111+
[
112+
f"{key}={value}"
113+
for key, value in SPECIES_HAB_DEFAULTS[species].model_dump().items()
114+
]
115+
)
116+
for species in HABSpeciesTypeEnum
117+
if species != "custom"
118+
}
119+
_species_descriptions["custom"] = "Custom species with user-defined parameters."

tests/test_config_opendrift.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,25 +286,25 @@ def test_HarmfulAlgalBloom_species_type():
286286
"""Make sure species_type parameter works as expected."""
287287
m = HarmfulAlgalBloomModelConfig(
288288
drift_model="HarmfulAlgalBloom",
289-
species_type="Pseudo_nitzschia",
289+
species_type="Pseudo nitzschia",
290290
steps=1,
291291
)
292-
assert m.species_type == "Pseudo_nitzschia"
292+
assert m.species_type == "Pseudo nitzschia"
293293
assert (
294294
m.temperature_death_min
295-
== SPECIES_HAB_DEFAULTS["Pseudo_nitzschia"].temperature_death_min
295+
== SPECIES_HAB_DEFAULTS["Pseudo nitzschia"].temperature_death_min
296296
)
297297
assert (
298298
m.temperature_death_max
299-
== SPECIES_HAB_DEFAULTS["Pseudo_nitzschia"].temperature_death_max
299+
== SPECIES_HAB_DEFAULTS["Pseudo nitzschia"].temperature_death_max
300300
)
301301
assert (
302302
m.salinity_death_min
303-
== SPECIES_HAB_DEFAULTS["Pseudo_nitzschia"].salinity_death_min
303+
== SPECIES_HAB_DEFAULTS["Pseudo nitzschia"].salinity_death_min
304304
)
305305
assert (
306306
m.salinity_death_max
307-
== SPECIES_HAB_DEFAULTS["Pseudo_nitzschia"].salinity_death_max
307+
== SPECIES_HAB_DEFAULTS["Pseudo nitzschia"].salinity_death_max
308308
)
309309

310310

tests/test_opendrift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def test_HarmfulAlgalBloom_seeding():
291291

292292
m = OpenDriftModel(
293293
drift_model="HarmfulAlgalBloom",
294-
species_type="Pseudo_nitzschia",
294+
species_type="Pseudo nitzschia",
295295
temperature_death_min=1,
296296
lon=-151,
297297
lat=60,

0 commit comments

Comments
 (0)