|
7 | 7 | from pathlib import Path |
8 | 8 |
|
9 | 9 | # Third-party imports |
10 | | -from pydantic import Field, field_validator, model_validator |
| 10 | +from pydantic import Field, model_validator |
11 | 11 | from pydantic.fields import FieldInfo |
12 | 12 | from typing_extensions import Self |
13 | 13 |
|
|
18 | 18 | DiffusivityModelEnum, |
19 | 19 | DriftModelEnum, |
20 | 20 | DropletSizeDistributionEnum, |
21 | | - ModifyOilTypeJsonSchema, |
22 | 21 | ObjectTypeEnum, |
23 | 22 | OilTypeEnum, |
24 | 23 | PlotTypeEnum, |
@@ -158,13 +157,6 @@ class OpenDriftConfig(TheManagerConfig): |
158 | 157 | "extra": "forbid", |
159 | 158 | } |
160 | 159 |
|
161 | | - @classmethod |
162 | | - def model_json_schema(cls, **kwargs) -> dict: |
163 | | - """Override the method to customize the JSON schema to include customization of oil_type.""" |
164 | | - return super().model_json_schema( |
165 | | - schema_generator=ModifyOilTypeJsonSchema, **kwargs |
166 | | - ) |
167 | | - |
168 | 160 | @model_validator(mode="after") |
169 | 161 | def check_interpolator_filename(self) -> Self: |
170 | 162 | """Check if interpolator_filename is set correctly.""" |
@@ -489,10 +481,14 @@ class OpenOilModelConfig(OceanDriftModelConfig): |
489 | 481 | drift_model: DriftModelEnum = DriftModelEnum.OpenOil # .value |
490 | 482 |
|
491 | 483 | oil_type: OilTypeEnum = Field( |
492 | | - default=OilTypeEnum["AD04012"], # .value, |
| 484 | + default=OilTypeEnum.AD04012, # .value, |
493 | 485 | description="Oil type to be used for the simulation, from the NOAA ADIOS database.", |
494 | 486 | title="Oil Type", |
495 | | - json_schema_extra={"od_mapping": "seed:oil_type", "ptm_level": 1}, |
| 487 | + json_schema_extra={ |
| 488 | + "od_mapping": "seed:oil_type", |
| 489 | + "ptm_level": 1, |
| 490 | + "oneOf": [{"const": oil.value, "title": oil.title} for oil in OilTypeEnum], |
| 491 | + }, |
496 | 492 | ) |
497 | 493 |
|
498 | 494 | m3_per_hour: float = Field( |
@@ -645,20 +641,6 @@ class OpenOilModelConfig(OceanDriftModelConfig): |
645 | 641 | OceanDriftModelConfig.model_fields["vertical_mixing"], Field(default=True) |
646 | 642 | ) |
647 | 643 |
|
648 | | - @field_validator("oil_type", mode="before") |
649 | | - def map_id_to_oil_type_tuple(cls, v): |
650 | | - """Map input oil type to enum name (which is the oil type id).""" |
651 | | - if ( |
652 | | - v in OilTypeEnum.__members__ |
653 | | - ): # Check if it matches an Enum name (which is the oil type id) |
654 | | - return OilTypeEnum[v] # then return id |
655 | | - else: |
656 | | - return v # return the original value |
657 | | - # for enum_member in OilTypeEnum: # Check if it matches an Enum value (which is the oil type name/title) |
658 | | - # if enum_member.value == v: |
659 | | - # return enum_member # then return id |
660 | | - raise ValueError(f"Invalid value or name '{v}' for OilTypeEnum") |
661 | | - |
662 | 644 |
|
663 | 645 | class LarvalFishModelConfig(OceanDriftModelConfig): |
664 | 646 | """Larval fish model configuration for OpenDrift.""" |
@@ -715,8 +697,8 @@ class LarvalFishModelConfig(OceanDriftModelConfig): |
715 | 697 | }, |
716 | 698 | ) |
717 | 699 |
|
718 | | - length: float = Field( |
719 | | - default=0, |
| 700 | + length: float | None = Field( |
| 701 | + default=None, |
720 | 702 | description="Seeding value of length. This is not currently used.", |
721 | 703 | title="Length", |
722 | 704 | gt=0, |
|
0 commit comments