Skip to content

Structures

TODO Implement the following structures - Bridge - Generalstructure - Long culvert - Gate - Dambreak

Add comments for these structures. Maybe link them to descriptions of Fields?

CulvertSubType (str, Enum)

An enumeration.

FlowDirection (str, Enum)

An enumeration.

Structure (INIBasedModel) pydantic-model

validate(v) classmethod

Try to iniatialize subclass based on function field.

Source code in hydrolib/core/io/structure/models.py
@classmethod
def validate(cls, v):
    """Try to iniatialize subclass based on function field."""
    # 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("structure_type").default
                == v.get("type", "").lower()
            ):
                v = c(**v)
                break
        else:
            logger.warning(f"Couldn't derive specific type of {cls.__name__}")
    return super().validate(v)
Back to top