rashdf 0.4.0__tar.gz → 0.5.0__tar.gz
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.
- {rashdf-0.4.0 → rashdf-0.5.0}/PKG-INFO +7 -6
- {rashdf-0.4.0 → rashdf-0.5.0}/README.md +4 -4
- {rashdf-0.4.0 → rashdf-0.5.0}/pyproject.toml +3 -3
- {rashdf-0.4.0 → rashdf-0.5.0}/src/cli.py +49 -6
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf/geom.py +216 -112
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf/plan.py +210 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/PKG-INFO +7 -6
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/requires.txt +2 -1
- {rashdf-0.4.0 → rashdf-0.5.0}/tests/test_cli.py +55 -1
- {rashdf-0.4.0 → rashdf-0.5.0}/tests/test_geom.py +30 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/tests/test_plan.py +82 -3
- {rashdf-0.4.0 → rashdf-0.5.0}/LICENSE +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/setup.cfg +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf/__init__.py +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf/base.py +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf/utils.py +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/SOURCES.txt +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/dependency_links.txt +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/entry_points.txt +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/src/rashdf.egg-info/top_level.txt +0 -0
- {rashdf-0.4.0 → rashdf-0.5.0}/tests/test_utils.py +0 -0
|
@@ -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<0.
|
|
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:
|
|
@@ -47,8 +47,8 @@ Also, methods to extract certain HDF group attributes as dictionaries:
|
|
|
47
47
|
```python
|
|
48
48
|
>>> from rashdf import RasPlanHdf
|
|
49
49
|
>>> with RasPlanHdf("path/to/rasmodel/Muncie.p04.hdf") as plan_hdf:
|
|
50
|
-
>>>
|
|
51
|
-
>>>
|
|
50
|
+
>>> results_unsteady_summary_attrs = plan_hdf.get_results_unsteady_summary_attrs()
|
|
51
|
+
>>> results_unsteady_summary_attrs
|
|
52
52
|
{'Computation Time DSS': datetime.timedelta(0),
|
|
53
53
|
'Computation Time Total': datetime.timedelta(seconds=23),
|
|
54
54
|
'Maximum WSEL Error': 0.0099277812987566,
|
|
@@ -72,9 +72,9 @@ CLI help:
|
|
|
72
72
|
$ rashdf --help
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Print the output formats supported by
|
|
75
|
+
Print the output formats supported by pyorgio:
|
|
76
76
|
```
|
|
77
|
-
$ rashdf --
|
|
77
|
+
$ rashdf --pyogrio-drivers
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
Help for a specific subcommand:
|
|
@@ -12,11 +12,11 @@ classifiers = [
|
|
|
12
12
|
"Programming Language :: Python :: 3.11",
|
|
13
13
|
"Programming Language :: Python :: 3.12",
|
|
14
14
|
]
|
|
15
|
-
version = "0.
|
|
16
|
-
dependencies = ["h5py", "geopandas>=0.
|
|
15
|
+
version = "0.5.0"
|
|
16
|
+
dependencies = ["h5py", "geopandas>=1.0,<2.0", "pyarrow", "xarray"]
|
|
17
17
|
|
|
18
18
|
[project.optional-dependencies]
|
|
19
|
-
dev = ["pre-commit", "ruff", "pytest", "pytest-cov"]
|
|
19
|
+
dev = ["pre-commit", "ruff", "pytest", "pytest-cov", "fiona"]
|
|
20
20
|
docs = ["sphinx", "numpydoc", "sphinx_rtd_theme"]
|
|
21
21
|
|
|
22
22
|
[project.urls]
|
|
@@ -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():
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"""HEC-RAS Geometry HDF class."""
|
|
2
2
|
|
|
3
|
-
from typing import Dict, List, Optional
|
|
4
|
-
|
|
5
3
|
import numpy as np
|
|
6
4
|
import pandas as pd
|
|
7
5
|
from geopandas import GeoDataFrame
|
|
8
6
|
from pyproj import CRS
|
|
9
7
|
from shapely import (
|
|
8
|
+
Geometry,
|
|
9
|
+
Polygon,
|
|
10
|
+
Point,
|
|
10
11
|
LineString,
|
|
11
12
|
MultiLineString,
|
|
12
13
|
MultiPolygon,
|
|
@@ -15,6 +16,9 @@ from shapely import (
|
|
|
15
16
|
polygonize_full,
|
|
16
17
|
)
|
|
17
18
|
|
|
19
|
+
from typing import Dict, List, Optional, Union
|
|
20
|
+
|
|
21
|
+
|
|
18
22
|
from .base import RasHdf
|
|
19
23
|
from .utils import (
|
|
20
24
|
convert_ras_hdf_string,
|
|
@@ -24,12 +28,24 @@ from .utils import (
|
|
|
24
28
|
)
|
|
25
29
|
|
|
26
30
|
|
|
31
|
+
class RasGeomHdfError(Exception):
|
|
32
|
+
"""HEC-RAS Plan HDF error class."""
|
|
33
|
+
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
27
37
|
class RasGeomHdf(RasHdf):
|
|
28
38
|
"""HEC-RAS Geometry HDF class."""
|
|
29
39
|
|
|
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
|
|
@@ -473,33 +608,17 @@ class RasGeomHdf(RasHdf):
|
|
|
473
608
|
GeoDataFrame
|
|
474
609
|
A GeoDataFrame containing the model 1D cross sections if they exist.
|
|
475
610
|
"""
|
|
476
|
-
if
|
|
611
|
+
if self.CROSS_SECTIONS not in self:
|
|
477
612
|
return GeoDataFrame()
|
|
478
613
|
|
|
479
|
-
xs_data = self[
|
|
614
|
+
xs_data = self[self.CROSS_SECTIONS]
|
|
480
615
|
v_conv_val = np.vectorize(convert_ras_hdf_value)
|
|
481
616
|
xs_attrs = xs_data["Attributes"][()]
|
|
482
617
|
xs_dict = {"xs_id": range(xs_attrs.shape[0])}
|
|
483
618
|
xs_dict.update(
|
|
484
619
|
{name: v_conv_val(xs_attrs[name]) for name in xs_attrs.dtype.names}
|
|
485
620
|
)
|
|
486
|
-
geoms =
|
|
487
|
-
for pnt_start, pnt_cnt, part_start, part_cnt in xs_data["Polyline Info"][()]:
|
|
488
|
-
points = xs_data["Polyline Points"][()][pnt_start : pnt_start + pnt_cnt]
|
|
489
|
-
if part_cnt == 1:
|
|
490
|
-
geoms.append(LineString(points))
|
|
491
|
-
else:
|
|
492
|
-
parts = xs_data["Polyline Parts"][()][
|
|
493
|
-
part_start : part_start + part_cnt
|
|
494
|
-
]
|
|
495
|
-
geoms.append(
|
|
496
|
-
MultiLineString(
|
|
497
|
-
list(
|
|
498
|
-
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
499
|
-
for part_pnt_start, part_pnt_cnt in parts
|
|
500
|
-
)
|
|
501
|
-
)
|
|
502
|
-
)
|
|
621
|
+
geoms = self._get_polylines(self.CROSS_SECTIONS)
|
|
503
622
|
xs_gdf = GeoDataFrame(
|
|
504
623
|
xs_dict,
|
|
505
624
|
geometry=geoms,
|
|
@@ -519,10 +638,10 @@ class RasGeomHdf(RasHdf):
|
|
|
519
638
|
GeoDataFrame
|
|
520
639
|
A GeoDataFrame containing the model 1D river reach lines if they exist.
|
|
521
640
|
"""
|
|
522
|
-
if
|
|
641
|
+
if self.RIVER_CENTERLINES not in self:
|
|
523
642
|
return GeoDataFrame()
|
|
524
643
|
|
|
525
|
-
river_data = self[
|
|
644
|
+
river_data = self[self.RIVER_CENTERLINES]
|
|
526
645
|
v_conv_val = np.vectorize(convert_ras_hdf_value)
|
|
527
646
|
river_attrs = river_data["Attributes"][()]
|
|
528
647
|
river_dict = {"river_id": range(river_attrs.shape[0])}
|
|
@@ -530,22 +649,7 @@ class RasGeomHdf(RasHdf):
|
|
|
530
649
|
{name: v_conv_val(river_attrs[name]) for name in river_attrs.dtype.names}
|
|
531
650
|
)
|
|
532
651
|
geoms = list()
|
|
533
|
-
|
|
534
|
-
points = river_data["Polyline Points"][()][pnt_start : pnt_start + pnt_cnt]
|
|
535
|
-
if part_cnt == 1:
|
|
536
|
-
geoms.append(LineString(points))
|
|
537
|
-
else:
|
|
538
|
-
parts = river_data["Polyline Parts"][()][
|
|
539
|
-
part_start : part_start + part_cnt
|
|
540
|
-
]
|
|
541
|
-
geoms.append(
|
|
542
|
-
MultiLineString(
|
|
543
|
-
list(
|
|
544
|
-
points[part_pnt_start : part_pnt_start + part_pnt_cnt]
|
|
545
|
-
for part_pnt_start, part_pnt_cnt in parts
|
|
546
|
-
)
|
|
547
|
-
)
|
|
548
|
-
)
|
|
652
|
+
geoms = self._get_polylines(self.RIVER_CENTERLINES)
|
|
549
653
|
river_gdf = GeoDataFrame(
|
|
550
654
|
river_dict,
|
|
551
655
|
geometry=geoms,
|
|
@@ -163,6 +163,8 @@ class RasPlanHdf(RasGeomHdf):
|
|
|
163
163
|
f"{BASE_OUTPUT_PATH}/Summary Output/2D Flow Areas"
|
|
164
164
|
)
|
|
165
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"
|
|
166
168
|
|
|
167
169
|
RESULTS_STEADY_PATH = "Results/Steady"
|
|
168
170
|
BASE_STEADY_PATH = f"{RESULTS_STEADY_PATH}/Output/Output Blocks/Base Output"
|
|
@@ -921,6 +923,214 @@ class RasPlanHdf(RasGeomHdf):
|
|
|
921
923
|
ds = self._mesh_timeseries_outputs(mesh_name, TIME_SERIES_OUTPUT_VARS_FACES)
|
|
922
924
|
return ds
|
|
923
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
|
+
|
|
924
1134
|
def get_plan_info_attrs(self) -> Dict:
|
|
925
1135
|
"""Return plan information attributes from a HEC-RAS HDF plan file.
|
|
926
1136
|
|
|
@@ -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<0.
|
|
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:
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
from src.cli import
|
|
1
|
+
from src.cli import (
|
|
2
|
+
parse_args,
|
|
3
|
+
export,
|
|
4
|
+
docstring_to_help,
|
|
5
|
+
fiona_supported_drivers,
|
|
6
|
+
pyogrio_supported_drivers,
|
|
7
|
+
)
|
|
2
8
|
|
|
3
9
|
import geopandas as gpd
|
|
4
10
|
from pyproj import CRS
|
|
11
|
+
import pytest
|
|
5
12
|
|
|
13
|
+
import builtins
|
|
6
14
|
import json
|
|
7
15
|
from pathlib import Path
|
|
8
16
|
|
|
@@ -30,6 +38,15 @@ def test_fiona_supported_drivers():
|
|
|
30
38
|
assert "ESRI Shapefile" in drivers
|
|
31
39
|
assert "GeoJSON" in drivers
|
|
32
40
|
assert "GPKG" in drivers
|
|
41
|
+
assert "MBTiles" not in drivers
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_pyogrio_supported_drivers():
|
|
45
|
+
drivers = pyogrio_supported_drivers()
|
|
46
|
+
assert "ESRI Shapefile" in drivers
|
|
47
|
+
assert "GeoJSON" in drivers
|
|
48
|
+
assert "GPKG" in drivers
|
|
49
|
+
assert "MBTiles" in drivers
|
|
33
50
|
|
|
34
51
|
|
|
35
52
|
def test_parse_args():
|
|
@@ -114,3 +131,40 @@ def test_export_plan_hdf():
|
|
|
114
131
|
exported = json.loads(export(args))
|
|
115
132
|
gdf = gpd.GeoDataFrame.from_features(exported)
|
|
116
133
|
assert len(gdf) == 4425
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_fiona_missing(monkeypatch):
|
|
137
|
+
# Test behavior when fiona isn't installed
|
|
138
|
+
|
|
139
|
+
def mock_import(name, globals=None, locals=None, fromlist=(), level=0):
|
|
140
|
+
if name == "fiona":
|
|
141
|
+
raise ImportError("No module named 'fiona'")
|
|
142
|
+
return real_import(name, globals, locals, fromlist, level)
|
|
143
|
+
|
|
144
|
+
real_import = builtins.__import__
|
|
145
|
+
|
|
146
|
+
# Replace the built-in __import__ function with our mock
|
|
147
|
+
monkeypatch.setattr(builtins, "__import__", mock_import)
|
|
148
|
+
|
|
149
|
+
# Verify that the --fiona-drivers argument is not available
|
|
150
|
+
# when fiona is not installed
|
|
151
|
+
args = parse_args(["structures", "fake_file.hdf"])
|
|
152
|
+
assert not hasattr(args, "fiona_drivers")
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def test_print_pyogrio_supported_drivers(capfd):
|
|
156
|
+
export(parse_args(["--pyogrio-drivers"]))
|
|
157
|
+
captured = capfd.readouterr()
|
|
158
|
+
assert "ESRI Shapefile" in captured.out
|
|
159
|
+
assert "GeoJSON" in captured.out
|
|
160
|
+
assert "GPKG" in captured.out
|
|
161
|
+
assert "MBTiles" in captured.out
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_print_fiona_supported_drivers(capfd):
|
|
165
|
+
export(parse_args(["--fiona-drivers"]))
|
|
166
|
+
captured = capfd.readouterr()
|
|
167
|
+
assert "ESRI Shapefile" in captured.out
|
|
168
|
+
assert "GeoJSON" in captured.out
|
|
169
|
+
assert "GPKG" in captured.out
|
|
170
|
+
assert "MBTiles" not in captured.out
|
|
@@ -10,6 +10,7 @@ MUNCIE_G05 = TEST_DATA / "ras/Muncie.g05.hdf"
|
|
|
10
10
|
COAL_G01 = TEST_DATA / "ras/Coal.g01.hdf"
|
|
11
11
|
BAXTER_P01 = TEST_DATA / "ras_1d/Baxter.p01.hdf"
|
|
12
12
|
TEST_JSON = TEST_DATA / "json"
|
|
13
|
+
BALD_EAGLE_P18_REF = TEST_DATA / "ras/BaldEagleDamBrk.reflines-refpts.p18.hdf"
|
|
13
14
|
|
|
14
15
|
TEST_ATTRS = {"test_attribute1": "test_str1", "test_attribute2": 500}
|
|
15
16
|
|
|
@@ -119,6 +120,35 @@ def test_structs():
|
|
|
119
120
|
assert _gdf_matches_json(ghdf.structures(datetime_to_str=True), structs_json)
|
|
120
121
|
|
|
121
122
|
|
|
123
|
+
def test_reference_lines_names():
|
|
124
|
+
with RasGeomHdf(BALD_EAGLE_P18_REF) as geom_hdf:
|
|
125
|
+
assert geom_hdf.reference_lines_names() == {
|
|
126
|
+
"BaldEagleCr": [
|
|
127
|
+
"Reference Line 1",
|
|
128
|
+
"Reference Line 2",
|
|
129
|
+
"Reference Line 3",
|
|
130
|
+
"Reference Line 4",
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
assert geom_hdf.reference_lines_names("Upper 2D Area") == []
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_reference_points_names():
|
|
137
|
+
with RasGeomHdf(BALD_EAGLE_P18_REF) as geom_hdf:
|
|
138
|
+
assert geom_hdf.reference_points_names() == {
|
|
139
|
+
"Upper 2D Area": [
|
|
140
|
+
"Reference Point 1",
|
|
141
|
+
],
|
|
142
|
+
"BaldEagleCr": [
|
|
143
|
+
"Reference Point 2",
|
|
144
|
+
"Reference Point 3",
|
|
145
|
+
],
|
|
146
|
+
}
|
|
147
|
+
assert geom_hdf.reference_points_names("Upper 2D Area") == [
|
|
148
|
+
"Reference Point 1",
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
|
|
122
152
|
def test_structs_not_found():
|
|
123
153
|
with RasGeomHdf(COAL_G01) as ghdf:
|
|
124
154
|
assert (ghdf.structures(), None)
|
|
@@ -25,6 +25,7 @@ TEST_CSV = TEST_DATA / "csv"
|
|
|
25
25
|
TEST_ATTRS = {"test_attribute1": "test_str1", "test_attribute2": 500}
|
|
26
26
|
BALD_EAGLE_P18 = TEST_DATA / "ras/BaldEagleDamBrk.p18.hdf"
|
|
27
27
|
BALD_EAGLE_P18_TIMESERIES = TEST_DATA / "ras/BaldEagleDamBrk.p18.timeseries.hdf"
|
|
28
|
+
BALD_EAGLE_P18_REF = TEST_DATA / "ras/BaldEagleDamBrk.reflines-refpts.p18.hdf"
|
|
28
29
|
MUNCIE_G05 = TEST_DATA / "ras/Muncie.g05.hdf"
|
|
29
30
|
COAL_G01 = TEST_DATA / "ras/Coal.g01.hdf"
|
|
30
31
|
BAXTER_P01 = TEST_DATA / "ras_1d/Baxter.p01.hdf"
|
|
@@ -143,7 +144,7 @@ def test_mesh_cell_points_with_output(tmp_path):
|
|
|
143
144
|
)
|
|
144
145
|
temp_points = tmp_path / "temp-bald-eagle-mesh-cell-points.geojson"
|
|
145
146
|
gdf = gdf.to_crs(4326)
|
|
146
|
-
gdf.to_file(temp_points)
|
|
147
|
+
gdf.to_file(temp_points, engine="fiona")
|
|
147
148
|
valid = get_sha1_hash(TEST_JSON / "bald-eagle-mesh-cell-points.geojson")
|
|
148
149
|
test = get_sha1_hash(temp_points)
|
|
149
150
|
assert valid == test
|
|
@@ -160,7 +161,7 @@ def test_mesh_cell_polygons_with_output(tmp_path):
|
|
|
160
161
|
],
|
|
161
162
|
)
|
|
162
163
|
temp_polygons = tmp_path / "temp-bald-eagle-mesh-cell-polygons.geojson"
|
|
163
|
-
gdf.to_crs(4326).to_file(temp_polygons)
|
|
164
|
+
gdf.to_crs(4326).to_file(temp_polygons, engine="fiona")
|
|
164
165
|
valid = get_sha1_hash(TEST_JSON / "bald-eagle-mesh-cell-polygons.geojson")
|
|
165
166
|
test = get_sha1_hash(temp_polygons)
|
|
166
167
|
assert valid == test
|
|
@@ -176,7 +177,7 @@ def test_mesh_cell_faces_with_output(tmp_path):
|
|
|
176
177
|
],
|
|
177
178
|
)
|
|
178
179
|
temp_faces = tmp_path / "temp-bald-eagle-mesh-cell-faces.geojson"
|
|
179
|
-
gdf.to_crs(4326).to_file(temp_faces)
|
|
180
|
+
gdf.to_crs(4326).to_file(temp_faces, engine="fiona")
|
|
180
181
|
valid = get_sha1_hash(TEST_JSON / "bald-eagle-mesh-cell-faces.geojson")
|
|
181
182
|
test = get_sha1_hash(temp_faces)
|
|
182
183
|
assert valid == test
|
|
@@ -266,6 +267,84 @@ def test_mesh_timeseries_output_faces():
|
|
|
266
267
|
assert_frame_equal(df, valid_df)
|
|
267
268
|
|
|
268
269
|
|
|
270
|
+
def test_reference_lines(tmp_path: Path):
|
|
271
|
+
plan_hdf = RasPlanHdf(BALD_EAGLE_P18_REF)
|
|
272
|
+
gdf = plan_hdf.reference_lines(datetime_to_str=True)
|
|
273
|
+
temp_lines = tmp_path / "temp-bald-eagle-reference-lines.geojson"
|
|
274
|
+
gdf.to_crs(4326).to_file(temp_lines, engine="fiona")
|
|
275
|
+
with open(TEST_JSON / "bald-eagle-reflines.geojson") as f:
|
|
276
|
+
valid_lines = f.read()
|
|
277
|
+
with open(temp_lines) as f:
|
|
278
|
+
test_lines = f.read()
|
|
279
|
+
assert valid_lines == test_lines
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def test_reference_lines_timeseries(tmp_path: Path):
|
|
283
|
+
plan_hdf = RasPlanHdf(BALD_EAGLE_P18_REF)
|
|
284
|
+
ds = plan_hdf.reference_lines_timeseries_output()
|
|
285
|
+
assert "time" in ds.coords
|
|
286
|
+
assert "refln_id" in ds.coords
|
|
287
|
+
assert "refln_name" in ds.coords
|
|
288
|
+
assert "mesh_name" in ds.coords
|
|
289
|
+
assert "Water Surface" in ds.variables
|
|
290
|
+
assert "Flow" in ds.variables
|
|
291
|
+
|
|
292
|
+
ws = ds["Water Surface"]
|
|
293
|
+
assert ws.shape == (37, 4)
|
|
294
|
+
assert ws.attrs["Units"] == "ft"
|
|
295
|
+
q = ds["Flow"]
|
|
296
|
+
assert q.shape == (37, 4)
|
|
297
|
+
assert q.attrs["Units"] == "cfs"
|
|
298
|
+
|
|
299
|
+
df = ds.sel(refln_id=2).to_dataframe()
|
|
300
|
+
valid_df = pd.read_csv(
|
|
301
|
+
TEST_CSV / "BaldEagleDamBrk.reflines.2.csv",
|
|
302
|
+
index_col="time",
|
|
303
|
+
parse_dates=True,
|
|
304
|
+
dtype={"Water Surface": np.float32, "Flow": np.float32},
|
|
305
|
+
)
|
|
306
|
+
assert_frame_equal(df, valid_df)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def test_reference_points(tmp_path: Path):
|
|
310
|
+
plan_hdf = RasPlanHdf(BALD_EAGLE_P18_REF)
|
|
311
|
+
gdf = plan_hdf.reference_points(datetime_to_str=True)
|
|
312
|
+
temp_lines = tmp_path / "temp-bald-eagle-reference-points.geojson"
|
|
313
|
+
gdf.to_crs(4326).to_file(temp_lines, engine="fiona")
|
|
314
|
+
with open(TEST_JSON / "bald-eagle-refpoints.geojson") as f:
|
|
315
|
+
valid_points = f.read()
|
|
316
|
+
with open(temp_lines) as f:
|
|
317
|
+
test_points = f.read()
|
|
318
|
+
assert valid_points == test_points
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def test_reference_points_timeseries():
|
|
322
|
+
plan_hdf = RasPlanHdf(BALD_EAGLE_P18_REF)
|
|
323
|
+
ds = plan_hdf.reference_points_timeseries_output()
|
|
324
|
+
assert "time" in ds.coords
|
|
325
|
+
assert "refpt_id" in ds.coords
|
|
326
|
+
assert "refpt_name" in ds.coords
|
|
327
|
+
assert "mesh_name" in ds.coords
|
|
328
|
+
assert "Water Surface" in ds.variables
|
|
329
|
+
assert "Velocity" in ds.variables
|
|
330
|
+
|
|
331
|
+
ws = ds["Water Surface"]
|
|
332
|
+
assert ws.shape == (37, 3)
|
|
333
|
+
assert ws.attrs["Units"] == "ft"
|
|
334
|
+
v = ds["Velocity"]
|
|
335
|
+
assert v.attrs["Units"] == "ft/s"
|
|
336
|
+
assert v.shape == (37, 3)
|
|
337
|
+
|
|
338
|
+
df = ds.sel(refpt_id=1).to_dataframe()
|
|
339
|
+
valid_df = pd.read_csv(
|
|
340
|
+
TEST_CSV / "BaldEagleDamBrk.refpoints.1.csv",
|
|
341
|
+
index_col="time",
|
|
342
|
+
parse_dates=True,
|
|
343
|
+
dtype={"Water Surface": np.float32, "Velocity": np.float32},
|
|
344
|
+
)
|
|
345
|
+
assert_frame_equal(df, valid_df)
|
|
346
|
+
|
|
347
|
+
|
|
269
348
|
def test_cross_sections_additional_velocity_total():
|
|
270
349
|
xs_velocity_json = TEST_JSON / "xs_velocity.json"
|
|
271
350
|
with RasPlanHdf(BAXTER_P01) as phdf:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|