Forcing
ForcingBase (DataBlockINIBasedModel)
pydantic-model
¶
validate(v)
classmethod
¶
Try to iniatialize subclass based on the function
field.
This field is compared to each function
field of the derived models of ForcingBase
.
The derived model with an equal function type will be initialized.
Exceptions:
Type | Description |
---|---|
ValueError |
When the given type is not a known structure type. |
Source code in hydrolib/core/io/bc/models.py
@classmethod
def validate(cls, v):
"""Try to iniatialize subclass based on the `function` field.
This field is compared to each `function` field of the derived models of `ForcingBase`.
The derived model with an equal function type will be initialized.
Raises:
ValueError: When the given type is not a known structure type.
"""
# should be replaced by discriminated unions once merged
# https://github.com/samuelcolvin/pydantic/pull/2336
if isinstance(v, dict):
for c in cls.__subclasses__():
if (
c.__fields__.get("function").default.lower()
== v.get("function", "").lower()
):
v = c(**v)
break
else:
raise ValueError(
f"Function of {cls.__name__} with name={v.get('name', '')} and function={v.get('function', '')} is not recognized."
)
return v
TimeInterpolation (str, Enum)
¶
An enumeration.
VerticalInterpolation (str, Enum)
¶
An enumeration.
VerticalPositionType (str, Enum)
¶
An enumeration.