Cross section files¶
The crosssection module provides the specific logic for accessing cross section files (location and definition) for a D-Flow FM model. Generic parsing and serializing functionality comes from the generic hydrolib.core.io.ini modules.
The cross section files are represented by the classes below.
Model¶
CircleCrsDef (CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=circle, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the circle input as described in UM Sec.C.16.1.1.
CrossDefGeneral (INIGeneral)
pydantic-model
¶
The crosssection definition file's [General] section with file meta data.
CrossDefModel (INIModel)
pydantic-model
¶
The overall crosssection definition model that contains the contents of one crossdef file.
This model is typically referenced under a FMModel.geometry.crossdeffile.
Attributes:
| Name | Type | Description |
|---|---|---|
general |
CrossdefGeneral |
|
definition |
List[CrossSectionDefinition] |
List of |
CrossLocGeneral (INIGeneral)
pydantic-model
¶
The crosssection location file's [General] section with file meta data.
CrossLocModel (INIModel)
pydantic-model
¶
The overall crosssection location model that contains the contents of one crossloc file.
This model is typically referenced under a FMModel.geometry.crosslocfile.
Attributes:
| Name | Type | Description |
|---|---|---|
general |
CrossLocGeneral |
|
crosssection |
List[CrossSection] |
List of |
CrossSection (INIBasedModel)
pydantic-model
¶
A [CrossSection] block for use inside a crosssection location file,
i.e., a CrossLocModel.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str |
Unique cross-section location id. |
branchid |
str |
(optional) Branch on which the cross section is located. |
CrossSectionDefinition (INIBasedModel)
pydantic-model
¶
A [Definition] block for use inside a crosssection definition file,
i.e., a CrossDefModel.
This class is intended as an abstract class: various subclasses should define they actual types of crosssection definitions.
validate(v)
classmethod
¶
Try to iniatialize subclass based on the type field.
This field is compared to each type field of the derived models of CrossSectionDefinition.
The derived model with an equal crosssection definition type will be initialized.
Exceptions:
| Type | Description |
|---|---|
ValueError |
When the given type is not a known crosssection definition type. |
Source code in hydrolib/core/io/crosssection/models.py
@classmethod
def validate(cls, v):
"""Try to iniatialize subclass based on the `type` field.
This field is compared to each `type` field of the derived models of `CrossSectionDefinition`.
The derived model with an equal crosssection definition type will be initialized.
Raises:
ValueError: When the given type is not a known crosssection definition 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("type").default.lower()
== v.get("type", "").lower()
):
v = c(**v)
break
else:
raise ValueError(
f"Type of {cls.__name__} with id={v.get('id', '')} and type={v.get('type', '')} is not recognized."
)
return super().validate(v)
RectangleCrsDef (CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=rectangle, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the rectangle input as described in UM Sec.C.16.1.2.
XYZCrsDef (YZCrsDef, CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=xyz, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the xyz input as described in UM Sec.C.16.1.5.
This class extends the YZCrsDef class with x-coordinates and an optional branchId field. Most other attributes are inherited, but the coordcount is overridden under the Pydantic alias "xyzCount".
Attributes:
| Name | Type | Description |
|---|---|---|
yzcount |
Optional[int] |
dummy attribute that should not be set nor used. Only present to mask the inherited attribute from parent class YZCrsDef. |
xyzcount |
int |
Number of XYZ-coordinates. Always use this instead of yzcount. |
validate_xyzcount_without_yzcount(field_value: int, values: dict) -> int
classmethod
¶
Validates whether this XYZCrsDef does have attribute xyzcount, but not the parent class's yzcount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_value |
Optional[Path] |
Value given for xyzcount. |
required |
values |
dict |
Dictionary of values already validated. |
required |
Exceptions:
| Type | Description |
|---|---|
ValueError |
When yzcount is present. |
Returns:
| Type | Description |
|---|---|
int |
The value given for xyzcount. |
Source code in hydrolib/core/io/crosssection/models.py
@validator("xyzcount")
@classmethod
def validate_xyzcount_without_yzcount(cls, field_value: int, values: dict) -> int:
"""
Validates whether this XYZCrsDef does have attribute xyzcount,
but not the parent class's yzcount.
Args:
field_value (Optional[Path]): Value given for xyzcount.
values (dict): Dictionary of values already validated.
Raises:
ValueError: When yzcount is present.
Returns:
int: The value given for xyzcount.
"""
# Retrieve the algorithm value (if not found use 0).
yzcount_value = values.get("yzcount")
if field_value is not None and yzcount_value is not None:
# yzcount should not be set, when xyzcount is set.
raise ValueError(
f"xyz cross section definition should not contain field yzCount (rather: xyzCount), current value: {yzcount_value}."
)
return field_value
YZCrsDef (CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=yz, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the yz input as described in UM Sec.C.16.1.6.
ZWCrsDef (CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=zw, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the zw input as described in UM Sec.C.16.1.4.
ZWRiverCrsDef (CrossSectionDefinition)
pydantic-model
¶
Crosssection definition with type=zwRiver, to be included in a crossdef file.
Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]
All lowercased attributes match with the zwRiver input as described in UM Sec.C.16.1.3.