Sample files¶
Sample .xyz files contain spatial input point data for a D-Flow FM model, and are used in various other input files.
A sample data file is described by the classes below.
Model¶
XYZModel (ParsableFileModel)
pydantic-model
¶
Sample or forcing file.
Attributes:
Name | Type | Description |
---|---|---|
points |
List[hydrolib.core.dflowfm.xyz.models.XYZPoint] |
List of |
dict(self, *args, **kwargs)
¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Source code in hydrolib/core/dflowfm/xyz/models.py
def dict(self, *args, **kwargs):
# speed up serializing by not converting these lowest models to dict
return dict(points=self.points)
XYZPoint (BaseModel)
pydantic-model
¶
Single sample or forcing point.
Attributes:
Name | Type | Description |
---|---|---|
x |
float |
x or λ coordinate |
y |
float |
y or φ coordinate |
z |
float |
sample value or group number (forcing) |
comment |
Optional[str] |
keyword for grouping (forcing) |
comment: str
pydantic-field
¶
comment or group name
Parser¶
XYZParser
¶
A parser for .xyz files which are like this:
number number number number number number # comment
Note that the whitespace can vary and the comment left out.
Serializer¶
XYZSerializer
¶
serialize(path: Path, data: Dict, config: SerializerConfig) -> None
staticmethod
¶
Serializes the XYZ data to the file at the specified path.
Attributes:
Name | Type | Description |
---|---|---|
path |
Path |
The path to the destination file. |
data |
Dict |
The data to be serialized. |
config |
SerializerConfig |
The serialization configuration. |
Source code in hydrolib/core/dflowfm/xyz/serializer.py
@staticmethod
def serialize(path: Path, data: Dict, config: SerializerConfig) -> None:
"""
Serializes the XYZ data to the file at the specified path.
Attributes:
path (Path): The path to the destination file.
data (Dict): The data to be serialized.
config (SerializerConfig): The serialization configuration.
"""
path.parent.mkdir(parents=True, exist_ok=True)
space = 1 * " "
format_float = lambda x: f"{x:{config.float_format}}"
with path.open("w") as f:
for point in data["points"]:
geometry: str = space.join(
[format_float(p) for p in XYZSerializer._get_point_values(point)]
)
if point.comment:
f.write(f"{geometry} # {point.comment}\n")
else:
f.write(f"{geometry}\n")