rashdf 0.3.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cli.py +49 -6
- rashdf/geom.py +306 -86
- rashdf/plan.py +360 -0
- {rashdf-0.3.0.dist-info → rashdf-0.5.0.dist-info}/METADATA +7 -6
- rashdf-0.5.0.dist-info/RECORD +12 -0
- {rashdf-0.3.0.dist-info → rashdf-0.5.0.dist-info}/WHEEL +1 -1
- rashdf-0.3.0.dist-info/RECORD +0 -12
- {rashdf-0.3.0.dist-info → rashdf-0.5.0.dist-info}/LICENSE +0 -0
- {rashdf-0.3.0.dist-info → rashdf-0.5.0.dist-info}/entry_points.txt +0 -0
- {rashdf-0.3.0.dist-info → rashdf-0.5.0.dist-info}/top_level.txt +0 -0
cli.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from rashdf import RasGeomHdf, RasPlanHdf
|
|
4
4
|
from rashdf.utils import df_datetimes_to_str
|
|
5
5
|
|
|
6
|
-
import fiona
|
|
7
6
|
from geopandas import GeoDataFrame
|
|
8
7
|
|
|
9
8
|
import argparse
|
|
@@ -23,6 +22,8 @@ COMMANDS = [
|
|
|
23
22
|
"refinement_regions",
|
|
24
23
|
"bc_lines",
|
|
25
24
|
"breaklines",
|
|
25
|
+
"reference_lines",
|
|
26
|
+
"reference_points",
|
|
26
27
|
"structures",
|
|
27
28
|
]
|
|
28
29
|
|
|
@@ -50,6 +51,20 @@ def docstring_to_help(docstring: Optional[str]) -> str:
|
|
|
50
51
|
return help_text
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
def pyogrio_supported_drivers() -> List[str]:
|
|
55
|
+
"""Return a list of drivers supported by pyogrio for writing output files.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
list
|
|
60
|
+
A list of drivers supported by pyogrio for writing output files.
|
|
61
|
+
"""
|
|
62
|
+
import pyogrio
|
|
63
|
+
|
|
64
|
+
drivers = pyogrio.list_drivers(write=True)
|
|
65
|
+
return sorted(drivers)
|
|
66
|
+
|
|
67
|
+
|
|
53
68
|
def fiona_supported_drivers() -> List[str]:
|
|
54
69
|
"""Return a list of drivers supported by Fiona for writing output files.
|
|
55
70
|
|
|
@@ -58,18 +73,34 @@ def fiona_supported_drivers() -> List[str]:
|
|
|
58
73
|
list
|
|
59
74
|
A list of drivers supported by Fiona for writing output files.
|
|
60
75
|
"""
|
|
76
|
+
import fiona
|
|
77
|
+
|
|
61
78
|
drivers = [d for d, s in fiona.supported_drivers.items() if "w" in s]
|
|
62
|
-
return drivers
|
|
79
|
+
return sorted(drivers)
|
|
63
80
|
|
|
64
81
|
|
|
65
82
|
def parse_args(args: str) -> argparse.Namespace:
|
|
66
83
|
"""Parse command-line arguments."""
|
|
67
84
|
parser = argparse.ArgumentParser(description="Extract data from HEC-RAS HDF files.")
|
|
68
85
|
parser.add_argument(
|
|
69
|
-
"--
|
|
86
|
+
"--pyogrio-drivers",
|
|
70
87
|
action="store_true",
|
|
71
|
-
help="List the drivers supported by
|
|
88
|
+
help="List the drivers supported by pyogrio for writing output files.",
|
|
72
89
|
)
|
|
90
|
+
fiona_installed = False
|
|
91
|
+
engines = ["pyogrio"]
|
|
92
|
+
try:
|
|
93
|
+
import fiona
|
|
94
|
+
|
|
95
|
+
fiona_installed = True
|
|
96
|
+
engines.append("fiona")
|
|
97
|
+
parser.add_argument(
|
|
98
|
+
"--fiona-drivers",
|
|
99
|
+
action="store_true",
|
|
100
|
+
help="List the drivers supported by Fiona for writing output files.",
|
|
101
|
+
)
|
|
102
|
+
except ImportError:
|
|
103
|
+
pass
|
|
73
104
|
subparsers = parser.add_subparsers(help="Sub-command help")
|
|
74
105
|
for command in COMMANDS:
|
|
75
106
|
f = getattr(RasGeomHdf, command)
|
|
@@ -91,6 +122,13 @@ def parse_args(args: str) -> argparse.Namespace:
|
|
|
91
122
|
output_group.add_argument(
|
|
92
123
|
"--feather", action="store_true", help="Output as Feather."
|
|
93
124
|
)
|
|
125
|
+
output_group.add_argument(
|
|
126
|
+
"--engine",
|
|
127
|
+
type=str,
|
|
128
|
+
choices=engines,
|
|
129
|
+
default="pyogrio",
|
|
130
|
+
help="Engine for writing output data.",
|
|
131
|
+
)
|
|
94
132
|
subparser.add_argument(
|
|
95
133
|
"--kwargs",
|
|
96
134
|
type=str,
|
|
@@ -105,7 +143,11 @@ def parse_args(args: str) -> argparse.Namespace:
|
|
|
105
143
|
|
|
106
144
|
def export(args: argparse.Namespace) -> Optional[str]:
|
|
107
145
|
"""Act on parsed arguments to extract data from HEC-RAS HDF files."""
|
|
108
|
-
if args.
|
|
146
|
+
if args.pyogrio_drivers:
|
|
147
|
+
for driver in pyogrio_supported_drivers():
|
|
148
|
+
print(driver)
|
|
149
|
+
return
|
|
150
|
+
if hasattr(args, "fiona_drivers") and args.fiona_drivers:
|
|
109
151
|
for driver in fiona_supported_drivers():
|
|
110
152
|
print(driver)
|
|
111
153
|
return
|
|
@@ -138,6 +180,7 @@ def export(args: argparse.Namespace) -> Optional[str]:
|
|
|
138
180
|
),
|
|
139
181
|
)
|
|
140
182
|
result = gdf.to_json(**kwargs)
|
|
183
|
+
print("No output file!")
|
|
141
184
|
print(result)
|
|
142
185
|
return result
|
|
143
186
|
elif args.parquet:
|
|
@@ -153,7 +196,7 @@ def export(args: argparse.Namespace) -> Optional[str]:
|
|
|
153
196
|
# convert any datetime columns to string.
|
|
154
197
|
# TODO: besides Geopackage, which of the standard Fiona drivers allow datetime?
|
|
155
198
|
gdf = df_datetimes_to_str(gdf)
|
|
156
|
-
gdf.to_file(args.output_file, **kwargs)
|
|
199
|
+
gdf.to_file(args.output_file, engine=args.engine, **kwargs)
|
|
157
200
|
|
|
158
201
|
|
|
159
202
|
def main():
|
rashdf/geom.py
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
"""HEC-RAS Geometry HDF class."""
|
|
2
2
|
|
|
3
|
-
from .base import RasHdf
|
|
4
|
-
from .utils import (
|
|
5
|
-
convert_ras_hdf_string,
|
|
6
|
-
get_first_hdf_group,
|
|
7
|
-
hdf5_attrs_to_dict,
|
|
8
|
-
convert_ras_hdf_value,
|
|
9
|
-
)
|
|
10
|
-
|
|
11
3
|
import numpy as np
|
|
12
4
|
import pandas as pd
|
|
13
5
|
from geopandas import GeoDataFrame
|
|
14
6
|
from pyproj import CRS
|
|
15
7
|
from shapely import (
|
|
8
|
+
Geometry,
|
|
16
9
|
Polygon,
|
|
17
10
|
Point,
|
|
18
11
|
LineString,
|
|
19
12
|
MultiLineString,
|
|
20
13
|
MultiPolygon,
|
|
14
|
+
Point,
|
|
15
|
+
Polygon,
|
|
21
16
|
polygonize_full,
|
|
22
17
|
)
|
|
23
18
|
|
|
24
|
-
from typing import Dict, List, Optional
|
|
19
|
+
from typing import Dict, List, Optional, Union
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
from .base import RasHdf
|
|
23
|
+
from .utils import (
|
|
24
|
+
convert_ras_hdf_string,
|
|
25
|
+
convert_ras_hdf_value,
|
|
26
|
+
get_first_hdf_group,
|
|
27
|
+
hdf5_attrs_to_dict,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class RasGeomHdfError(Exception):
|
|
32
|
+
"""HEC-RAS Plan HDF error class."""
|
|
33
|
+
|
|
34
|
+
pass
|
|
25
35
|
|
|
26
36
|
|
|
27
37
|
class RasGeomHdf(RasHdf):
|
|
@@ -30,6 +40,12 @@ class RasGeomHdf(RasHdf):
|
|
|
30
40
|
GEOM_PATH = "Geometry"
|
|
31
41
|
GEOM_STRUCTURES_PATH = f"{GEOM_PATH}/Structures"
|
|
32
42
|
FLOW_AREA_2D_PATH = f"{GEOM_PATH}/2D Flow Areas"
|
|
43
|
+
BC_LINES_PATH = f"{GEOM_PATH}/Boundary Condition Lines"
|
|
44
|
+
BREAKLINES_PATH = f"{GEOM_PATH}/2D Flow Area Break Lines"
|
|
45
|
+
REFERENCE_LINES_PATH = f"{GEOM_PATH}/Reference Lines"
|
|
46
|
+
REFERENCE_POINTS_PATH = f"{GEOM_PATH}/Reference Points"
|
|
47
|
+
CROSS_SECTIONS = f"{GEOM_PATH}/Cross Sections"
|
|
48
|
+
RIVER_CENTERLINES = f"{GEOM_PATH}/River Centerlines"
|
|
33
49
|
|
|
34
50
|
def __init__(self, name: str, **kwargs):
|
|
35
51
|
"""Open a HEC-RAS Geometry HDF file.
|
|
@@ -262,6 +278,38 @@ class RasGeomHdf(RasHdf):
|
|
|
262
278
|
|
|
263
279
|
return d2_flow_area_attrs
|
|
264
280
|
|
|
281
|
+
def _get_polylines(
|
|
282
|
+
self,
|
|
283
|
+
path: str,
|
|
284
|
+
info_name: str = "Polyline Info",
|
|
285
|
+
parts_name: str = "Polyline Parts",
|
|
286
|
+
points_name: str = "Polyline Points",
|
|
287
|
+
) -> List[Geometry]:
|
|
288
|
+
polyline_info_path = f"{path}/{info_name}"
|
|
289
|
+
polyline_parts_path = f"{path}/{parts_name}"
|
|
290
|
+
polyline_points_path = f"{path}/{points_name}"
|
|
291
|
+
|
|
292
|
+
polyline_info = self[polyline_info_path][()]
|
|
293
|
+
polyline_parts = self[polyline_parts_path][()]
|
|
294
|
+
polyline_points = self[polyline_points_path][()]
|
|
295
|
+
|
|
296
|
+
geoms = []
|
|
297
|
+
for pnt_start, pnt_cnt, part_start, part_cnt in polyline_info:
|
|
298
|
+
points = polyline_points[pnt_start : pnt_start + pnt_cnt]
|
|
299
|
+
if part_cnt == 1:
|
|
300
|
+
geoms.append(LineString(points))
|
|
301
|
+
else:
|
|
302
|
+
parts = polyline_parts[part_start : part_start + part_cnt]
|
|
303
|
+
geoms.append(
|
|
304
|
+
MultiLineString(
|
|
305
|
+
list(
|
|
306
|
+
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
307
|
+
for part_pnt_start, part_pnt_cnt in parts
|
|
308
|
+
)
|
|
309
|
+
)
|
|
310
|
+
)
|
|
311
|
+
return geoms
|
|
312
|
+
|
|
265
313
|
def bc_lines(self) -> GeoDataFrame:
|
|
266
314
|
"""Return 2D mesh area boundary condition lines.
|
|
267
315
|
|
|
@@ -270,35 +318,15 @@ class RasGeomHdf(RasHdf):
|
|
|
270
318
|
GeoDataFrame
|
|
271
319
|
A GeoDataFrame containing the 2D mesh area boundary condition lines if they exist.
|
|
272
320
|
"""
|
|
273
|
-
if
|
|
321
|
+
if self.BC_LINES_PATH not in self:
|
|
274
322
|
return GeoDataFrame()
|
|
275
|
-
bc_line_data = self[
|
|
323
|
+
bc_line_data = self[self.BC_LINES_PATH]
|
|
276
324
|
bc_line_ids = range(bc_line_data["Attributes"][()].shape[0])
|
|
277
325
|
v_conv_str = np.vectorize(convert_ras_hdf_string)
|
|
278
326
|
names = v_conv_str(bc_line_data["Attributes"][()]["Name"])
|
|
279
327
|
mesh_names = v_conv_str(bc_line_data["Attributes"][()]["SA-2D"])
|
|
280
328
|
types = v_conv_str(bc_line_data["Attributes"][()]["Type"])
|
|
281
|
-
geoms =
|
|
282
|
-
for pnt_start, pnt_cnt, part_start, part_cnt in bc_line_data["Polyline Info"][
|
|
283
|
-
()
|
|
284
|
-
]:
|
|
285
|
-
points = bc_line_data["Polyline Points"][()][
|
|
286
|
-
pnt_start : pnt_start + pnt_cnt
|
|
287
|
-
]
|
|
288
|
-
if part_cnt == 1:
|
|
289
|
-
geoms.append(LineString(points))
|
|
290
|
-
else:
|
|
291
|
-
parts = bc_line_data["Polyline Parts"][()][
|
|
292
|
-
part_start : part_start + part_cnt
|
|
293
|
-
]
|
|
294
|
-
geoms.append(
|
|
295
|
-
MultiLineString(
|
|
296
|
-
list(
|
|
297
|
-
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
298
|
-
for part_pnt_start, part_pnt_cnt in parts
|
|
299
|
-
)
|
|
300
|
-
)
|
|
301
|
-
)
|
|
329
|
+
geoms = self._get_polylines(self.BC_LINES_PATH)
|
|
302
330
|
return GeoDataFrame(
|
|
303
331
|
{
|
|
304
332
|
"bc_line_id": bc_line_ids,
|
|
@@ -319,34 +347,14 @@ class RasGeomHdf(RasHdf):
|
|
|
319
347
|
GeoDataFrame
|
|
320
348
|
A GeoDataFrame containing the 2D mesh area breaklines if they exist.
|
|
321
349
|
"""
|
|
322
|
-
if
|
|
350
|
+
if self.BREAKLINES_PATH not in self:
|
|
323
351
|
return GeoDataFrame()
|
|
324
|
-
bl_line_data = self[
|
|
352
|
+
bl_line_data = self[self.BREAKLINES_PATH]
|
|
325
353
|
bl_line_ids = range(bl_line_data["Attributes"][()].shape[0])
|
|
326
354
|
names = np.vectorize(convert_ras_hdf_string)(
|
|
327
355
|
bl_line_data["Attributes"][()]["Name"]
|
|
328
356
|
)
|
|
329
|
-
geoms =
|
|
330
|
-
for pnt_start, pnt_cnt, part_start, part_cnt in bl_line_data["Polyline Info"][
|
|
331
|
-
()
|
|
332
|
-
]:
|
|
333
|
-
points = bl_line_data["Polyline Points"][()][
|
|
334
|
-
pnt_start : pnt_start + pnt_cnt
|
|
335
|
-
]
|
|
336
|
-
if part_cnt == 1:
|
|
337
|
-
geoms.append(LineString(points))
|
|
338
|
-
else:
|
|
339
|
-
parts = bl_line_data["Polyline Parts"][()][
|
|
340
|
-
part_start : part_start + part_cnt
|
|
341
|
-
]
|
|
342
|
-
geoms.append(
|
|
343
|
-
MultiLineString(
|
|
344
|
-
list(
|
|
345
|
-
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
346
|
-
for part_pnt_start, part_pnt_cnt in parts
|
|
347
|
-
)
|
|
348
|
-
)
|
|
349
|
-
)
|
|
357
|
+
geoms = self._get_polylines(self.BREAKLINES_PATH)
|
|
350
358
|
return GeoDataFrame(
|
|
351
359
|
{"bl_id": bl_line_ids, "name": names, "geometry": geoms},
|
|
352
360
|
geometry="geometry",
|
|
@@ -400,36 +408,21 @@ class RasGeomHdf(RasHdf):
|
|
|
400
408
|
GeoDataFrame
|
|
401
409
|
A GeoDataFrame containing the model structures if they exist.
|
|
402
410
|
"""
|
|
403
|
-
if
|
|
411
|
+
if self.GEOM_STRUCTURES_PATH not in self:
|
|
404
412
|
return GeoDataFrame()
|
|
405
|
-
struct_data = self[
|
|
413
|
+
struct_data = self[self.GEOM_STRUCTURES_PATH]
|
|
406
414
|
v_conv_val = np.vectorize(convert_ras_hdf_value)
|
|
407
415
|
sd_attrs = struct_data["Attributes"][()]
|
|
408
416
|
struct_dict = {"struct_id": range(sd_attrs.shape[0])}
|
|
409
417
|
struct_dict.update(
|
|
410
418
|
{name: v_conv_val(sd_attrs[name]) for name in sd_attrs.dtype.names}
|
|
411
419
|
)
|
|
412
|
-
geoms =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
]
|
|
419
|
-
if part_cnt == 1:
|
|
420
|
-
geoms.append(LineString(points))
|
|
421
|
-
else:
|
|
422
|
-
parts = struct_data["Centerline Parts"][()][
|
|
423
|
-
part_start : part_start + part_cnt
|
|
424
|
-
]
|
|
425
|
-
geoms.append(
|
|
426
|
-
MultiLineString(
|
|
427
|
-
list(
|
|
428
|
-
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
429
|
-
for part_pnt_start, part_pnt_cnt in parts
|
|
430
|
-
)
|
|
431
|
-
)
|
|
432
|
-
)
|
|
420
|
+
geoms = self._get_polylines(
|
|
421
|
+
self.GEOM_STRUCTURES_PATH,
|
|
422
|
+
info_name="Centerline Info",
|
|
423
|
+
parts_name="Centerline Parts",
|
|
424
|
+
points_name="Centerline Points",
|
|
425
|
+
)
|
|
433
426
|
struct_gdf = GeoDataFrame(
|
|
434
427
|
struct_dict,
|
|
435
428
|
geometry=geoms,
|
|
@@ -447,11 +440,153 @@ class RasGeomHdf(RasHdf):
|
|
|
447
440
|
def ic_points(self) -> GeoDataFrame: # noqa D102
|
|
448
441
|
raise NotImplementedError
|
|
449
442
|
|
|
450
|
-
def
|
|
451
|
-
|
|
443
|
+
def _reference_lines_points_names(
|
|
444
|
+
self, reftype: str = "lines", mesh_name: Optional[str] = None
|
|
445
|
+
) -> Union[Dict[str, List[str]], List[str]]:
|
|
446
|
+
"""Return reference line names.
|
|
452
447
|
|
|
453
|
-
|
|
454
|
-
|
|
448
|
+
If a mesh name is provided, return a list of the reference line names for that mesh area.
|
|
449
|
+
If no mesh name is provided, return a dictionary of mesh names and their reference line names.
|
|
450
|
+
|
|
451
|
+
Parameters
|
|
452
|
+
----------
|
|
453
|
+
mesh_name : str, optional
|
|
454
|
+
The name of the mesh area for which to return reference line names.
|
|
455
|
+
|
|
456
|
+
Returns
|
|
457
|
+
-------
|
|
458
|
+
Union[Dict[str, List[str]], List[str]]
|
|
459
|
+
A dictionary of mesh names and their reference line names if mesh_name is None.
|
|
460
|
+
A list of reference line names for the specified mesh area if mesh_name is not None.
|
|
461
|
+
"""
|
|
462
|
+
if reftype == "lines":
|
|
463
|
+
path = self.REFERENCE_LINES_PATH
|
|
464
|
+
sa_2d_field = "SA-2D"
|
|
465
|
+
elif reftype == "points":
|
|
466
|
+
path = self.REFERENCE_POINTS_PATH
|
|
467
|
+
sa_2d_field = "SA/2D"
|
|
468
|
+
else:
|
|
469
|
+
raise RasGeomHdfError(
|
|
470
|
+
f"Invalid reference type: {reftype} -- must be 'lines' or 'points'."
|
|
471
|
+
)
|
|
472
|
+
attributes_path = f"{path}/Attributes"
|
|
473
|
+
if mesh_name is None and attributes_path not in self:
|
|
474
|
+
return {m: [] for m in self.mesh_area_names()}
|
|
475
|
+
if mesh_name is not None and attributes_path not in self:
|
|
476
|
+
return []
|
|
477
|
+
attributes = self[attributes_path][()]
|
|
478
|
+
v_conv_str = np.vectorize(convert_ras_hdf_string)
|
|
479
|
+
names = np.vectorize(convert_ras_hdf_string)(attributes["Name"])
|
|
480
|
+
if mesh_name is not None:
|
|
481
|
+
return names[v_conv_str(attributes[sa_2d_field]) == mesh_name].tolist()
|
|
482
|
+
mesh_names = np.vectorize(convert_ras_hdf_string)(attributes[sa_2d_field])
|
|
483
|
+
return {m: names[mesh_names == m].tolist() for m in np.unique(mesh_names)}
|
|
484
|
+
|
|
485
|
+
def reference_lines_names(
|
|
486
|
+
self, mesh_name: Optional[str] = None
|
|
487
|
+
) -> Union[Dict[str, List[str]], List[str]]:
|
|
488
|
+
"""Return reference line names.
|
|
489
|
+
|
|
490
|
+
If a mesh name is provided, return a list of the reference line names for that mesh area.
|
|
491
|
+
If no mesh name is provided, return a dictionary of mesh names and their reference line names.
|
|
492
|
+
|
|
493
|
+
Parameters
|
|
494
|
+
----------
|
|
495
|
+
mesh_name : str, optional
|
|
496
|
+
The name of the mesh area for which to return reference line names.
|
|
497
|
+
|
|
498
|
+
Returns
|
|
499
|
+
-------
|
|
500
|
+
Union[Dict[str, List[str]], List[str]]
|
|
501
|
+
A dictionary of mesh names and their reference line names if mesh_name is None.
|
|
502
|
+
A list of reference line names for the specified mesh area if mesh_name is not None.
|
|
503
|
+
"""
|
|
504
|
+
return self._reference_lines_points_names("lines", mesh_name)
|
|
505
|
+
|
|
506
|
+
def reference_points_names(
|
|
507
|
+
self, mesh_name: Optional[str] = None
|
|
508
|
+
) -> Union[Dict[str, List[str]], List[str]]:
|
|
509
|
+
"""Return reference point names.
|
|
510
|
+
|
|
511
|
+
If a mesh name is provided, return a list of the reference point names for that mesh area.
|
|
512
|
+
If no mesh name is provided, return a dictionary of mesh names and their reference point names.
|
|
513
|
+
|
|
514
|
+
Parameters
|
|
515
|
+
----------
|
|
516
|
+
mesh_name : str, optional
|
|
517
|
+
The name of the mesh area for which to return reference point names.
|
|
518
|
+
|
|
519
|
+
Returns
|
|
520
|
+
-------
|
|
521
|
+
Union[Dict[str, List[str]], List[str]]
|
|
522
|
+
A dictionary of mesh names and their reference point names if mesh_name is None.
|
|
523
|
+
A list of reference point names for the specified mesh area if mesh_name is not None.
|
|
524
|
+
"""
|
|
525
|
+
return self._reference_lines_points_names("points", mesh_name)
|
|
526
|
+
|
|
527
|
+
def reference_lines(self) -> GeoDataFrame:
|
|
528
|
+
"""Return the reference lines geometry and attributes.
|
|
529
|
+
|
|
530
|
+
Returns
|
|
531
|
+
-------
|
|
532
|
+
GeoDataFrame
|
|
533
|
+
A GeoDataFrame containing the reference lines if they exist.
|
|
534
|
+
"""
|
|
535
|
+
attributes_path = f"{self.REFERENCE_LINES_PATH}/Attributes"
|
|
536
|
+
if attributes_path not in self:
|
|
537
|
+
return GeoDataFrame()
|
|
538
|
+
attributes = self[attributes_path][()]
|
|
539
|
+
refline_ids = range(attributes.shape[0])
|
|
540
|
+
v_conv_str = np.vectorize(convert_ras_hdf_string)
|
|
541
|
+
names = v_conv_str(attributes["Name"])
|
|
542
|
+
mesh_names = v_conv_str(attributes["SA-2D"])
|
|
543
|
+
try:
|
|
544
|
+
types = v_conv_str(attributes["Type"])
|
|
545
|
+
except ValueError:
|
|
546
|
+
# "Type" field doesn't exist -- observed in some RAS HDF files
|
|
547
|
+
types = np.array([""] * attributes.shape[0])
|
|
548
|
+
geoms = self._get_polylines(self.REFERENCE_LINES_PATH)
|
|
549
|
+
return GeoDataFrame(
|
|
550
|
+
{
|
|
551
|
+
"refln_id": refline_ids,
|
|
552
|
+
"refln_name": names,
|
|
553
|
+
"mesh_name": mesh_names,
|
|
554
|
+
"type": types,
|
|
555
|
+
"geometry": geoms,
|
|
556
|
+
},
|
|
557
|
+
geometry="geometry",
|
|
558
|
+
crs=self.projection(),
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
def reference_points(self) -> GeoDataFrame:
|
|
562
|
+
"""Return the reference points geometry and attributes.
|
|
563
|
+
|
|
564
|
+
Returns
|
|
565
|
+
-------
|
|
566
|
+
GeoDataFrame
|
|
567
|
+
A GeoDataFrame containing the reference points if they exist.
|
|
568
|
+
"""
|
|
569
|
+
attributes_path = f"{self.REFERENCE_POINTS_PATH}/Attributes"
|
|
570
|
+
if attributes_path not in self:
|
|
571
|
+
return GeoDataFrame()
|
|
572
|
+
ref_points_group = self[self.REFERENCE_POINTS_PATH]
|
|
573
|
+
attributes = ref_points_group["Attributes"][:]
|
|
574
|
+
v_conv_str = np.vectorize(convert_ras_hdf_string)
|
|
575
|
+
names = v_conv_str(attributes["Name"])
|
|
576
|
+
mesh_names = v_conv_str(attributes["SA/2D"])
|
|
577
|
+
cell_id = attributes["Cell Index"]
|
|
578
|
+
points = ref_points_group["Points"][()]
|
|
579
|
+
return GeoDataFrame(
|
|
580
|
+
{
|
|
581
|
+
"refpt_id": range(attributes.shape[0]),
|
|
582
|
+
"refpt_name": names,
|
|
583
|
+
"mesh_name": mesh_names,
|
|
584
|
+
"cell_id": cell_id,
|
|
585
|
+
"geometry": list(map(Point, points)),
|
|
586
|
+
},
|
|
587
|
+
geometry="geometry",
|
|
588
|
+
crs=self.projection(),
|
|
589
|
+
)
|
|
455
590
|
|
|
456
591
|
def pump_stations(self) -> GeoDataFrame: # noqa D102
|
|
457
592
|
raise NotImplementedError
|
|
@@ -465,11 +600,66 @@ class RasGeomHdf(RasHdf):
|
|
|
465
600
|
def terrain_modifications(self) -> GeoDataFrame: # noqa D102
|
|
466
601
|
raise NotImplementedError
|
|
467
602
|
|
|
468
|
-
def cross_sections(self) -> GeoDataFrame:
|
|
469
|
-
|
|
603
|
+
def cross_sections(self, datetime_to_str: bool = False) -> GeoDataFrame:
|
|
604
|
+
"""Return the model 1D cross sections.
|
|
470
605
|
|
|
471
|
-
|
|
472
|
-
|
|
606
|
+
Returns
|
|
607
|
+
-------
|
|
608
|
+
GeoDataFrame
|
|
609
|
+
A GeoDataFrame containing the model 1D cross sections if they exist.
|
|
610
|
+
"""
|
|
611
|
+
if self.CROSS_SECTIONS not in self:
|
|
612
|
+
return GeoDataFrame()
|
|
613
|
+
|
|
614
|
+
xs_data = self[self.CROSS_SECTIONS]
|
|
615
|
+
v_conv_val = np.vectorize(convert_ras_hdf_value)
|
|
616
|
+
xs_attrs = xs_data["Attributes"][()]
|
|
617
|
+
xs_dict = {"xs_id": range(xs_attrs.shape[0])}
|
|
618
|
+
xs_dict.update(
|
|
619
|
+
{name: v_conv_val(xs_attrs[name]) for name in xs_attrs.dtype.names}
|
|
620
|
+
)
|
|
621
|
+
geoms = self._get_polylines(self.CROSS_SECTIONS)
|
|
622
|
+
xs_gdf = GeoDataFrame(
|
|
623
|
+
xs_dict,
|
|
624
|
+
geometry=geoms,
|
|
625
|
+
crs=self.projection(),
|
|
626
|
+
)
|
|
627
|
+
if datetime_to_str:
|
|
628
|
+
xs_gdf["Last Edited"] = xs_gdf["Last Edited"].apply(
|
|
629
|
+
lambda x: pd.Timestamp.isoformat(x)
|
|
630
|
+
)
|
|
631
|
+
return xs_gdf
|
|
632
|
+
|
|
633
|
+
def river_reaches(self, datetime_to_str: bool = False) -> GeoDataFrame:
|
|
634
|
+
"""Return the model 1D river reach lines.
|
|
635
|
+
|
|
636
|
+
Returns
|
|
637
|
+
-------
|
|
638
|
+
GeoDataFrame
|
|
639
|
+
A GeoDataFrame containing the model 1D river reach lines if they exist.
|
|
640
|
+
"""
|
|
641
|
+
if self.RIVER_CENTERLINES not in self:
|
|
642
|
+
return GeoDataFrame()
|
|
643
|
+
|
|
644
|
+
river_data = self[self.RIVER_CENTERLINES]
|
|
645
|
+
v_conv_val = np.vectorize(convert_ras_hdf_value)
|
|
646
|
+
river_attrs = river_data["Attributes"][()]
|
|
647
|
+
river_dict = {"river_id": range(river_attrs.shape[0])}
|
|
648
|
+
river_dict.update(
|
|
649
|
+
{name: v_conv_val(river_attrs[name]) for name in river_attrs.dtype.names}
|
|
650
|
+
)
|
|
651
|
+
geoms = list()
|
|
652
|
+
geoms = self._get_polylines(self.RIVER_CENTERLINES)
|
|
653
|
+
river_gdf = GeoDataFrame(
|
|
654
|
+
river_dict,
|
|
655
|
+
geometry=geoms,
|
|
656
|
+
crs=self.projection(),
|
|
657
|
+
)
|
|
658
|
+
if datetime_to_str:
|
|
659
|
+
river_gdf["Last Edited"] = river_gdf["Last Edited"].apply(
|
|
660
|
+
lambda x: pd.Timestamp.isoformat(x)
|
|
661
|
+
)
|
|
662
|
+
return river_gdf
|
|
473
663
|
|
|
474
664
|
def flowpaths(self) -> GeoDataFrame: # noqa D102
|
|
475
665
|
raise NotImplementedError
|
|
@@ -488,3 +678,33 @@ class RasGeomHdf(RasHdf):
|
|
|
488
678
|
|
|
489
679
|
def blocked_obstructions(self) -> GeoDataFrame: # noqa D102
|
|
490
680
|
raise NotImplementedError
|
|
681
|
+
|
|
682
|
+
def cross_sections_elevations(self, round_to: int = 2) -> pd.DataFrame:
|
|
683
|
+
"""Return the model cross section elevation information.
|
|
684
|
+
|
|
685
|
+
Returns
|
|
686
|
+
-------
|
|
687
|
+
DataFrame
|
|
688
|
+
A DataFrame containing the model cross section elevation information if they exist.
|
|
689
|
+
"""
|
|
690
|
+
path = "/Geometry/Cross Sections"
|
|
691
|
+
if path not in self:
|
|
692
|
+
return pd.DataFrame()
|
|
693
|
+
|
|
694
|
+
xselev_data = self[path]
|
|
695
|
+
xs_df = self.cross_sections()
|
|
696
|
+
elevations = list()
|
|
697
|
+
for part_start, part_cnt in xselev_data["Station Elevation Info"][()]:
|
|
698
|
+
xzdata = xselev_data["Station Elevation Values"][()][
|
|
699
|
+
part_start : part_start + part_cnt
|
|
700
|
+
]
|
|
701
|
+
elevations.append(xzdata)
|
|
702
|
+
|
|
703
|
+
xs_elev_df = xs_df[
|
|
704
|
+
["xs_id", "River", "Reach", "RS", "Left Bank", "Right Bank"]
|
|
705
|
+
].copy()
|
|
706
|
+
xs_elev_df["Left Bank"] = xs_elev_df["Left Bank"].round(round_to).astype(str)
|
|
707
|
+
xs_elev_df["Right Bank"] = xs_elev_df["Right Bank"].round(round_to).astype(str)
|
|
708
|
+
xs_elev_df["elevation info"] = elevations
|
|
709
|
+
|
|
710
|
+
return xs_elev_df
|
rashdf/plan.py
CHANGED
|
@@ -25,6 +25,26 @@ class RasPlanHdfError(Exception):
|
|
|
25
25
|
pass
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
class XsSteadyOutputVar(Enum):
|
|
29
|
+
"""Summary of steady cross section output variables."""
|
|
30
|
+
|
|
31
|
+
ENERGY_GRADE = "Energy Grade"
|
|
32
|
+
FLOW = "Flow"
|
|
33
|
+
WATER_SURFACE = "Water Surface"
|
|
34
|
+
ENCROACHMENT_STATION_LEFT = "Encroachment Station Left"
|
|
35
|
+
ENCROACHMENT_STATION_RIGHT = "Encroachment Station Right"
|
|
36
|
+
AREA_INEFFECTIVE_TOTAL = "Area including Ineffective Total"
|
|
37
|
+
VELOCITY_TOTAL = "Velocity Total"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
XS_STEADY_OUTPUT_ADDITIONAL = [
|
|
41
|
+
XsSteadyOutputVar.ENCROACHMENT_STATION_LEFT,
|
|
42
|
+
XsSteadyOutputVar.ENCROACHMENT_STATION_RIGHT,
|
|
43
|
+
XsSteadyOutputVar.AREA_INEFFECTIVE_TOTAL,
|
|
44
|
+
XsSteadyOutputVar.VELOCITY_TOTAL,
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
28
48
|
class SummaryOutputVar(Enum):
|
|
29
49
|
"""Summary output variables."""
|
|
30
50
|
|
|
@@ -143,6 +163,14 @@ class RasPlanHdf(RasGeomHdf):
|
|
|
143
163
|
f"{BASE_OUTPUT_PATH}/Summary Output/2D Flow Areas"
|
|
144
164
|
)
|
|
145
165
|
UNSTEADY_TIME_SERIES_PATH = f"{BASE_OUTPUT_PATH}/Unsteady Time Series"
|
|
166
|
+
REFERENCE_LINES_OUTPUT_PATH = f"{UNSTEADY_TIME_SERIES_PATH}/Reference Lines"
|
|
167
|
+
REFERENCE_POINTS_OUTPUT_PATH = f"{UNSTEADY_TIME_SERIES_PATH}/Reference Points"
|
|
168
|
+
|
|
169
|
+
RESULTS_STEADY_PATH = "Results/Steady"
|
|
170
|
+
BASE_STEADY_PATH = f"{RESULTS_STEADY_PATH}/Output/Output Blocks/Base Output"
|
|
171
|
+
STEADY_PROFILES_PATH = f"{BASE_STEADY_PATH}/Steady Profiles"
|
|
172
|
+
STEADY_XS_PATH = f"{STEADY_PROFILES_PATH}/Cross Sections"
|
|
173
|
+
STEADY_XS_ADDITIONAL_PATH = f"{STEADY_XS_PATH}/Additional Variables"
|
|
146
174
|
|
|
147
175
|
def __init__(self, name: str, **kwargs):
|
|
148
176
|
"""Open a HEC-RAS Plan HDF file.
|
|
@@ -895,6 +923,214 @@ class RasPlanHdf(RasGeomHdf):
|
|
|
895
923
|
ds = self._mesh_timeseries_outputs(mesh_name, TIME_SERIES_OUTPUT_VARS_FACES)
|
|
896
924
|
return ds
|
|
897
925
|
|
|
926
|
+
def reference_timeseries_output(self, reftype: str = "lines") -> xr.Dataset:
|
|
927
|
+
"""Return timeseries output data for reference lines or points from a HEC-RAS HDF plan file.
|
|
928
|
+
|
|
929
|
+
Parameters
|
|
930
|
+
----------
|
|
931
|
+
reftype : str, optional
|
|
932
|
+
The type of reference data to retrieve. Must be either "lines" or "points".
|
|
933
|
+
(default: "lines")
|
|
934
|
+
|
|
935
|
+
Returns
|
|
936
|
+
-------
|
|
937
|
+
xr.Dataset
|
|
938
|
+
An xarray Dataset with reference line timeseries data.
|
|
939
|
+
"""
|
|
940
|
+
if reftype == "lines":
|
|
941
|
+
output_path = self.REFERENCE_LINES_OUTPUT_PATH
|
|
942
|
+
abbrev = "refln"
|
|
943
|
+
elif reftype == "points":
|
|
944
|
+
output_path = self.REFERENCE_POINTS_OUTPUT_PATH
|
|
945
|
+
abbrev = "refpt"
|
|
946
|
+
else:
|
|
947
|
+
raise ValueError('reftype must be either "lines" or "points".')
|
|
948
|
+
reference_group = self.get(output_path)
|
|
949
|
+
if reference_group is None:
|
|
950
|
+
raise RasPlanHdfError(
|
|
951
|
+
f"Could not find HDF group at path '{output_path}'."
|
|
952
|
+
f" Does the Plan HDF file contain reference {reftype[:-1]} output data?"
|
|
953
|
+
)
|
|
954
|
+
reference_names = reference_group["Name"][:]
|
|
955
|
+
names = []
|
|
956
|
+
mesh_areas = []
|
|
957
|
+
for s in reference_names:
|
|
958
|
+
name, mesh_area = s.decode("utf-8").split("|")
|
|
959
|
+
names.append(name)
|
|
960
|
+
mesh_areas.append(mesh_area)
|
|
961
|
+
|
|
962
|
+
times = self.unsteady_datetimes()
|
|
963
|
+
|
|
964
|
+
das = {}
|
|
965
|
+
for var in ["Flow", "Velocity", "Water Surface"]:
|
|
966
|
+
group = reference_group.get(var)
|
|
967
|
+
if group is None:
|
|
968
|
+
continue
|
|
969
|
+
try:
|
|
970
|
+
import dask.array as da
|
|
971
|
+
|
|
972
|
+
# TODO: user-specified chunks?
|
|
973
|
+
values = da.from_array(group, chunks=group.chunks)
|
|
974
|
+
except ImportError:
|
|
975
|
+
values = group[:]
|
|
976
|
+
units = group.attrs["Units"].decode("utf-8")
|
|
977
|
+
da = xr.DataArray(
|
|
978
|
+
values,
|
|
979
|
+
name=var,
|
|
980
|
+
dims=["time", f"{abbrev}_id"],
|
|
981
|
+
coords={
|
|
982
|
+
"time": times,
|
|
983
|
+
f"{abbrev}_id": range(values.shape[1]),
|
|
984
|
+
f"{abbrev}_name": (f"{abbrev}_id", names),
|
|
985
|
+
"mesh_name": (f"{abbrev}_id", mesh_areas),
|
|
986
|
+
},
|
|
987
|
+
attrs={"Units": units},
|
|
988
|
+
)
|
|
989
|
+
das[var] = da
|
|
990
|
+
return xr.Dataset(das)
|
|
991
|
+
|
|
992
|
+
def reference_lines_timeseries_output(self) -> xr.Dataset:
|
|
993
|
+
"""Return timeseries output data for reference lines from a HEC-RAS HDF plan file.
|
|
994
|
+
|
|
995
|
+
Returns
|
|
996
|
+
-------
|
|
997
|
+
xr.Dataset
|
|
998
|
+
An xarray Dataset with timeseries output data for reference lines.
|
|
999
|
+
"""
|
|
1000
|
+
return self.reference_timeseries_output(reftype="lines")
|
|
1001
|
+
|
|
1002
|
+
def reference_points_timeseries_output(self) -> xr.Dataset:
|
|
1003
|
+
"""Return timeseries output data for reference points from a HEC-RAS HDF plan file.
|
|
1004
|
+
|
|
1005
|
+
Returns
|
|
1006
|
+
-------
|
|
1007
|
+
xr.Dataset
|
|
1008
|
+
An xarray Dataset with timeseries output data for reference points.
|
|
1009
|
+
"""
|
|
1010
|
+
return self.reference_timeseries_output(reftype="points")
|
|
1011
|
+
|
|
1012
|
+
def reference_summary_output(self, reftype: str = "lines") -> DataFrame:
|
|
1013
|
+
"""Return summary output data for reference lines or points from a HEC-RAS HDF plan file.
|
|
1014
|
+
|
|
1015
|
+
Returns
|
|
1016
|
+
-------
|
|
1017
|
+
DataFrame
|
|
1018
|
+
A DataFrame with reference line summary output data.
|
|
1019
|
+
"""
|
|
1020
|
+
if reftype == "lines":
|
|
1021
|
+
abbrev = "refln"
|
|
1022
|
+
elif reftype == "points":
|
|
1023
|
+
abbrev = "refpt"
|
|
1024
|
+
else:
|
|
1025
|
+
raise ValueError('reftype must be either "lines" or "points".')
|
|
1026
|
+
ds = self.reference_timeseries_output(reftype=reftype)
|
|
1027
|
+
result = {
|
|
1028
|
+
f"{abbrev}_id": ds[f"{abbrev}_id"],
|
|
1029
|
+
f"{abbrev}_name": ds[f"{abbrev}_name"],
|
|
1030
|
+
"mesh_name": ds.mesh_name,
|
|
1031
|
+
}
|
|
1032
|
+
vars = {
|
|
1033
|
+
"Flow": "q",
|
|
1034
|
+
"Water Surface": "ws",
|
|
1035
|
+
"Velocity": "v",
|
|
1036
|
+
}
|
|
1037
|
+
for var, abbrev in vars.items():
|
|
1038
|
+
if var not in ds:
|
|
1039
|
+
continue
|
|
1040
|
+
max_var = ds[var].max(dim="time")
|
|
1041
|
+
max_time = ds[var].time[ds[var].argmax(dim="time")]
|
|
1042
|
+
min_var = ds[var].min(dim="time")
|
|
1043
|
+
min_time = ds[var].time[ds[var].argmin(dim="time")]
|
|
1044
|
+
result[f"max_{abbrev}"] = max_var
|
|
1045
|
+
result[f"max_{abbrev}_time"] = max_time
|
|
1046
|
+
result[f"min_{abbrev}"] = min_var
|
|
1047
|
+
result[f"min_{abbrev}_time"] = min_time
|
|
1048
|
+
return DataFrame(result)
|
|
1049
|
+
|
|
1050
|
+
def _reference_lines_points(
|
|
1051
|
+
self,
|
|
1052
|
+
reftype: str = "lines",
|
|
1053
|
+
include_output: bool = True,
|
|
1054
|
+
datetime_to_str: bool = False,
|
|
1055
|
+
) -> GeoDataFrame:
|
|
1056
|
+
if reftype == "lines":
|
|
1057
|
+
abbrev = "refln"
|
|
1058
|
+
gdf = super().reference_lines()
|
|
1059
|
+
elif reftype == "points":
|
|
1060
|
+
abbrev = "refpt"
|
|
1061
|
+
gdf = super().reference_points()
|
|
1062
|
+
else:
|
|
1063
|
+
raise ValueError('reftype must be either "lines" or "points".')
|
|
1064
|
+
if include_output is False:
|
|
1065
|
+
return gdf
|
|
1066
|
+
summary_output = self.reference_summary_output(reftype=reftype)
|
|
1067
|
+
gdf = gdf.merge(
|
|
1068
|
+
summary_output,
|
|
1069
|
+
on=[f"{abbrev}_id", f"{abbrev}_name", "mesh_name"],
|
|
1070
|
+
how="left",
|
|
1071
|
+
)
|
|
1072
|
+
if datetime_to_str:
|
|
1073
|
+
gdf = df_datetimes_to_str(gdf)
|
|
1074
|
+
return gdf
|
|
1075
|
+
|
|
1076
|
+
def reference_lines(
|
|
1077
|
+
self, include_output: bool = True, datetime_to_str: bool = False
|
|
1078
|
+
) -> GeoDataFrame:
|
|
1079
|
+
"""Return the reference lines from a HEC-RAS HDF plan file.
|
|
1080
|
+
|
|
1081
|
+
Includes summary output data for each reference line:
|
|
1082
|
+
- Maximum flow & time (max_q, max_q_time)
|
|
1083
|
+
- Minimum flow & time (min_q, min_q_time)
|
|
1084
|
+
- Maximum water surface elevation & time (max_ws, max_ws_time)
|
|
1085
|
+
- Minimum water surface elevation & time (min_ws, min_ws_time)
|
|
1086
|
+
|
|
1087
|
+
Parameters
|
|
1088
|
+
----------
|
|
1089
|
+
include_output : bool, optional
|
|
1090
|
+
If True, include summary output data in the GeoDataFrame. (default: True)
|
|
1091
|
+
datetime_to_str : bool, optional
|
|
1092
|
+
If True, convert datetime columns to strings. (default: False)
|
|
1093
|
+
|
|
1094
|
+
Returns
|
|
1095
|
+
-------
|
|
1096
|
+
GeoDataFrame
|
|
1097
|
+
A GeoDataFrame with reference line geometry and summary output data.
|
|
1098
|
+
"""
|
|
1099
|
+
return self._reference_lines_points(
|
|
1100
|
+
reftype="lines",
|
|
1101
|
+
include_output=include_output,
|
|
1102
|
+
datetime_to_str=datetime_to_str,
|
|
1103
|
+
)
|
|
1104
|
+
|
|
1105
|
+
def reference_points(
|
|
1106
|
+
self, include_output: bool = True, datetime_to_str: bool = False
|
|
1107
|
+
) -> GeoDataFrame:
|
|
1108
|
+
"""Return the reference points from a HEC-RAS HDF plan file.
|
|
1109
|
+
|
|
1110
|
+
Parameters
|
|
1111
|
+
----------
|
|
1112
|
+
include_output : bool, optional
|
|
1113
|
+
If True, include summary output data in the GeoDataFrame. (default: True)
|
|
1114
|
+
datetime_to_str : bool, optional
|
|
1115
|
+
If True, convert datetime columns to strings. (default: False)
|
|
1116
|
+
|
|
1117
|
+
Includes summary output data for each reference point:
|
|
1118
|
+
- Maximum flow & time (max_q, max_q_time)
|
|
1119
|
+
- Minimum flow & time (min_q, min_q_time)
|
|
1120
|
+
- Maximum water surface elevation & time (max_ws, max_ws_time)
|
|
1121
|
+
- Minimum water surface elevation & time (min_ws, min_ws_time)
|
|
1122
|
+
|
|
1123
|
+
Returns
|
|
1124
|
+
-------
|
|
1125
|
+
GeoDataFrame
|
|
1126
|
+
A GeoDataFrame with reference point geometry and summary output data.
|
|
1127
|
+
"""
|
|
1128
|
+
return self._reference_lines_points(
|
|
1129
|
+
reftype="points",
|
|
1130
|
+
include_output=include_output,
|
|
1131
|
+
datetime_to_str=datetime_to_str,
|
|
1132
|
+
)
|
|
1133
|
+
|
|
898
1134
|
def get_plan_info_attrs(self) -> Dict:
|
|
899
1135
|
"""Return plan information attributes from a HEC-RAS HDF plan file.
|
|
900
1136
|
|
|
@@ -957,3 +1193,127 @@ class RasPlanHdf(RasGeomHdf):
|
|
|
957
1193
|
|
|
958
1194
|
def enroachment_points(self) -> GeoDataFrame: # noqa: D102
|
|
959
1195
|
raise NotImplementedError
|
|
1196
|
+
|
|
1197
|
+
def steady_flow_names(self) -> list:
|
|
1198
|
+
"""Return the profile information for each steady flow event.
|
|
1199
|
+
|
|
1200
|
+
Returns
|
|
1201
|
+
-------
|
|
1202
|
+
DataFrame
|
|
1203
|
+
A Dataframe containing the profile names for each event
|
|
1204
|
+
"""
|
|
1205
|
+
if self.STEADY_PROFILES_PATH not in self:
|
|
1206
|
+
return pd.DataFrame()
|
|
1207
|
+
|
|
1208
|
+
profile_data = self[self.STEADY_PROFILES_PATH]
|
|
1209
|
+
profile_attrs = profile_data["Profile Names"][()]
|
|
1210
|
+
|
|
1211
|
+
return [x.decode("utf-8") for x in profile_attrs]
|
|
1212
|
+
|
|
1213
|
+
def steady_profile_xs_output(
|
|
1214
|
+
self, var: XsSteadyOutputVar, round_to: int = 2
|
|
1215
|
+
) -> DataFrame:
|
|
1216
|
+
"""Create a Dataframe from steady cross section results based on path.
|
|
1217
|
+
|
|
1218
|
+
Parameters
|
|
1219
|
+
----------
|
|
1220
|
+
var : XsSteadyOutputVar
|
|
1221
|
+
The name of the table in the steady results that information is to be retireved from.
|
|
1222
|
+
|
|
1223
|
+
round_to : int, optional
|
|
1224
|
+
Number of decimal places to round output data to.
|
|
1225
|
+
|
|
1226
|
+
Returns
|
|
1227
|
+
-------
|
|
1228
|
+
Dataframe with desired hdf data.
|
|
1229
|
+
"""
|
|
1230
|
+
if var in XS_STEADY_OUTPUT_ADDITIONAL:
|
|
1231
|
+
path = f"{self.STEADY_XS_ADDITIONAL_PATH}/{var.value}"
|
|
1232
|
+
else:
|
|
1233
|
+
path = f"{self.STEADY_XS_PATH}/{var.value}"
|
|
1234
|
+
if path not in self:
|
|
1235
|
+
return DataFrame()
|
|
1236
|
+
|
|
1237
|
+
profiles = self.steady_flow_names()
|
|
1238
|
+
|
|
1239
|
+
steady_data = self[path]
|
|
1240
|
+
df = DataFrame(steady_data, index=profiles)
|
|
1241
|
+
df_t = df.T.copy()
|
|
1242
|
+
for p in profiles:
|
|
1243
|
+
df_t[p] = df_t[p].apply(lambda x: round(x, round_to))
|
|
1244
|
+
|
|
1245
|
+
return df_t
|
|
1246
|
+
|
|
1247
|
+
def cross_sections_wsel(self) -> DataFrame:
|
|
1248
|
+
"""Return the water surface elevation information for each 1D Cross Section.
|
|
1249
|
+
|
|
1250
|
+
Returns
|
|
1251
|
+
-------
|
|
1252
|
+
DataFrame
|
|
1253
|
+
A Dataframe containing the water surface elevations for each cross section and event
|
|
1254
|
+
"""
|
|
1255
|
+
return self.steady_profile_xs_output(XsSteadyOutputVar.WATER_SURFACE)
|
|
1256
|
+
|
|
1257
|
+
def cross_sections_flow(self) -> DataFrame:
|
|
1258
|
+
"""Return the Flow information for each 1D Cross Section.
|
|
1259
|
+
|
|
1260
|
+
Returns
|
|
1261
|
+
-------
|
|
1262
|
+
DataFrame
|
|
1263
|
+
A Dataframe containing the flow for each cross section and event
|
|
1264
|
+
"""
|
|
1265
|
+
return self.steady_profile_xs_output(XsSteadyOutputVar.FLOW)
|
|
1266
|
+
|
|
1267
|
+
def cross_sections_energy_grade(self) -> DataFrame:
|
|
1268
|
+
"""Return the energy grade information for each 1D Cross Section.
|
|
1269
|
+
|
|
1270
|
+
Returns
|
|
1271
|
+
-------
|
|
1272
|
+
DataFrame
|
|
1273
|
+
A Dataframe containing the water surface elevations for each cross section and event
|
|
1274
|
+
"""
|
|
1275
|
+
return self.steady_profile_xs_output(XsSteadyOutputVar.ENERGY_GRADE)
|
|
1276
|
+
|
|
1277
|
+
def cross_sections_additional_enc_station_left(self) -> DataFrame:
|
|
1278
|
+
"""Return the left side encroachment information for a floodway plan hdf.
|
|
1279
|
+
|
|
1280
|
+
Returns
|
|
1281
|
+
-------
|
|
1282
|
+
DataFrame
|
|
1283
|
+
A DataFrame containing the cross sections left side encroachment stations
|
|
1284
|
+
"""
|
|
1285
|
+
return self.steady_profile_xs_output(
|
|
1286
|
+
XsSteadyOutputVar.ENCROACHMENT_STATION_LEFT
|
|
1287
|
+
)
|
|
1288
|
+
|
|
1289
|
+
def cross_sections_additional_enc_station_right(self) -> DataFrame:
|
|
1290
|
+
"""Return the right side encroachment information for a floodway plan hdf.
|
|
1291
|
+
|
|
1292
|
+
Returns
|
|
1293
|
+
-------
|
|
1294
|
+
DataFrame
|
|
1295
|
+
A DataFrame containing the cross sections right side encroachment stations
|
|
1296
|
+
"""
|
|
1297
|
+
return self.steady_profile_xs_output(
|
|
1298
|
+
XsSteadyOutputVar.ENCROACHMENT_STATION_RIGHT
|
|
1299
|
+
)
|
|
1300
|
+
|
|
1301
|
+
def cross_sections_additional_area_total(self) -> DataFrame:
|
|
1302
|
+
"""Return the 1D cross section area for each profile.
|
|
1303
|
+
|
|
1304
|
+
Returns
|
|
1305
|
+
-------
|
|
1306
|
+
DataFrame
|
|
1307
|
+
A DataFrame containing the wet area inside the cross sections
|
|
1308
|
+
"""
|
|
1309
|
+
return self.steady_profile_xs_output(XsSteadyOutputVar.AREA_INEFFECTIVE_TOTAL)
|
|
1310
|
+
|
|
1311
|
+
def cross_sections_additional_velocity_total(self) -> DataFrame:
|
|
1312
|
+
"""Return the 1D cross section velocity for each profile.
|
|
1313
|
+
|
|
1314
|
+
Returns
|
|
1315
|
+
-------
|
|
1316
|
+
DataFrame
|
|
1317
|
+
A DataFrame containing the velocity inside the cross sections
|
|
1318
|
+
"""
|
|
1319
|
+
return self.steady_profile_xs_output(XsSteadyOutputVar.VELOCITY_TOTAL)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: rashdf
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Read data from HEC-RAS HDF files.
|
|
5
5
|
Project-URL: repository, https://github.com/fema-ffrd/rashdf
|
|
6
6
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Requires-Dist: h5py
|
|
17
|
-
Requires-Dist: geopandas
|
|
17
|
+
Requires-Dist: geopandas <2.0,>=1.0
|
|
18
18
|
Requires-Dist: pyarrow
|
|
19
19
|
Requires-Dist: xarray
|
|
20
20
|
Provides-Extra: dev
|
|
@@ -22,6 +22,7 @@ Requires-Dist: pre-commit ; extra == 'dev'
|
|
|
22
22
|
Requires-Dist: ruff ; extra == 'dev'
|
|
23
23
|
Requires-Dist: pytest ; extra == 'dev'
|
|
24
24
|
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
25
|
+
Requires-Dist: fiona ; extra == 'dev'
|
|
25
26
|
Provides-Extra: docs
|
|
26
27
|
Requires-Dist: sphinx ; extra == 'docs'
|
|
27
28
|
Requires-Dist: numpydoc ; extra == 'docs'
|
|
@@ -76,8 +77,8 @@ Also, methods to extract certain HDF group attributes as dictionaries:
|
|
|
76
77
|
```python
|
|
77
78
|
>>> from rashdf import RasPlanHdf
|
|
78
79
|
>>> with RasPlanHdf("path/to/rasmodel/Muncie.p04.hdf") as plan_hdf:
|
|
79
|
-
>>>
|
|
80
|
-
>>>
|
|
80
|
+
>>> results_unsteady_summary_attrs = plan_hdf.get_results_unsteady_summary_attrs()
|
|
81
|
+
>>> results_unsteady_summary_attrs
|
|
81
82
|
{'Computation Time DSS': datetime.timedelta(0),
|
|
82
83
|
'Computation Time Total': datetime.timedelta(seconds=23),
|
|
83
84
|
'Maximum WSEL Error': 0.0099277812987566,
|
|
@@ -101,9 +102,9 @@ CLI help:
|
|
|
101
102
|
$ rashdf --help
|
|
102
103
|
```
|
|
103
104
|
|
|
104
|
-
Print the output formats supported by
|
|
105
|
+
Print the output formats supported by pyorgio:
|
|
105
106
|
```
|
|
106
|
-
$ rashdf --
|
|
107
|
+
$ rashdf --pyogrio-drivers
|
|
107
108
|
```
|
|
108
109
|
|
|
109
110
|
Help for a specific subcommand:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
cli.py,sha256=yItWmCxnYLcuOpJVRpUsfv_NLS9IxLjojZB9GrxfKAU,6571
|
|
2
|
+
rashdf/__init__.py,sha256=XXFtJDgLPCimqAhfsFz_pTWYECJiRT0i-Kb1uflXmVU,156
|
|
3
|
+
rashdf/base.py,sha256=lHYVDwFTA1qFI34QYZ55QKcp7b8CeZsmDfESdkYISbg,2432
|
|
4
|
+
rashdf/geom.py,sha256=2aTfj6mqZGP6rysflQ5L8FeItlYJsknO00sKHo-yaTw,26090
|
|
5
|
+
rashdf/plan.py,sha256=ggXzP4Ryx9MxMSHFrkMpFIjYCdIBufWiFPsFx5SFY6c,47426
|
|
6
|
+
rashdf/utils.py,sha256=93arHtIT-iL9dIpbYr7esjrxv1uJabTRJSruyjvr8mw,10168
|
|
7
|
+
rashdf-0.5.0.dist-info/LICENSE,sha256=L_0QaLpQVHPcglVjiaJPnOocwzP8uXevDRjUPr9DL1Y,1065
|
|
8
|
+
rashdf-0.5.0.dist-info/METADATA,sha256=hnF7VT4q5-tBkwMZQvF1VfGArEQ4y1jznn1A4L0PwGs,5729
|
|
9
|
+
rashdf-0.5.0.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
10
|
+
rashdf-0.5.0.dist-info/entry_points.txt,sha256=LHHMR1lLy4wRyscMuW1RlYDXemtPgqQhNcILz0DtStY,36
|
|
11
|
+
rashdf-0.5.0.dist-info/top_level.txt,sha256=SrmLb6FFTJtM_t6O1v0M0JePshiQJMHr0yYVkHL7ztk,11
|
|
12
|
+
rashdf-0.5.0.dist-info/RECORD,,
|
rashdf-0.3.0.dist-info/RECORD
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
cli.py,sha256=dnTMEBid99xqorBFKZnUwOTDyTmIg08D83bSCkJ6104,5389
|
|
2
|
-
rashdf/__init__.py,sha256=XXFtJDgLPCimqAhfsFz_pTWYECJiRT0i-Kb1uflXmVU,156
|
|
3
|
-
rashdf/base.py,sha256=lHYVDwFTA1qFI34QYZ55QKcp7b8CeZsmDfESdkYISbg,2432
|
|
4
|
-
rashdf/geom.py,sha256=Kf8e9u0U-dRi6lVcSPxPMeAYKwgZDIpNZ2o0Qu4WEJA,17609
|
|
5
|
-
rashdf/plan.py,sha256=W4Q4yjneDEJSeubnMDUgQ7T12fcWDYPL0RDZrsmFZ0A,34556
|
|
6
|
-
rashdf/utils.py,sha256=93arHtIT-iL9dIpbYr7esjrxv1uJabTRJSruyjvr8mw,10168
|
|
7
|
-
rashdf-0.3.0.dist-info/LICENSE,sha256=L_0QaLpQVHPcglVjiaJPnOocwzP8uXevDRjUPr9DL1Y,1065
|
|
8
|
-
rashdf-0.3.0.dist-info/METADATA,sha256=-5zzZFS6V4Uiv8pjpwznAXnPj1KpZPwuJpE6aOOXBtk,5658
|
|
9
|
-
rashdf-0.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
10
|
-
rashdf-0.3.0.dist-info/entry_points.txt,sha256=LHHMR1lLy4wRyscMuW1RlYDXemtPgqQhNcILz0DtStY,36
|
|
11
|
-
rashdf-0.3.0.dist-info/top_level.txt,sha256=SrmLb6FFTJtM_t6O1v0M0JePshiQJMHr0yYVkHL7ztk,11
|
|
12
|
-
rashdf-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|