Skip to content

Commit 1856c71

Browse files
author
Stevenray Janke
committed
Merge branch 'main' into Feature/ras_1d
2 parents 996a2d8 + af72a1a commit 1856c71

21 files changed

+19790
-32
lines changed

docs/source/RasPlanHdf.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ RasPlanHdf
33
.. currentmodule:: rashdf
44
.. autoclass:: RasPlanHdf
55
:show-inheritance:
6-
:members: get_plan_info_attrs,
6+
:members: mesh_cell_points,
7+
mesh_cell_polygons,
8+
mesh_cell_faces,
9+
mesh_max_ws,
10+
mesh_min_ws,
11+
mesh_max_face_v,
12+
mesh_min_face_v,
13+
mesh_max_ws_err,
14+
mesh_max_iter,
15+
mesh_last_iter,
16+
get_plan_info_attrs,
717
get_plan_param_attrs,
818
get_meteorology_precip_attrs,
919
get_results_unsteady_attrs,

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ classifiers = [
1212
"Programming Language :: Python :: 3.11",
1313
"Programming Language :: Python :: 3.12",
1414
]
15-
version = "0.2.2"
16-
dependencies = ["h5py", "geopandas", "pyarrow"]
15+
version = "0.3.0"
16+
dependencies = ["h5py", "geopandas", "pyarrow", "xarray"]
1717

1818
[project.optional-dependencies]
1919
dev = ["pre-commit", "ruff", "pytest", "pytest-cov"]

src/cli.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""rashdf CLI."""
22

3-
from rashdf import RasGeomHdf
3+
from rashdf import RasGeomHdf, RasPlanHdf
44
from rashdf.utils import df_datetimes_to_str
55

66
import fiona
@@ -10,6 +10,7 @@
1010
from ast import literal_eval
1111
from pathlib import Path
1212
import sys
13+
import re
1314
from typing import List, Optional
1415
import warnings
1516

@@ -108,17 +109,22 @@ def export(args: argparse.Namespace) -> Optional[str]:
108109
for driver in fiona_supported_drivers():
109110
print(driver)
110111
return
111-
if "://" in args.hdf_file:
112-
geom_hdf = RasGeomHdf.open_uri(args.hdf_file)
112+
if re.match(r"^.*\.p\d\d\.hdf$", args.hdf_file):
113+
ras_hdf_class = RasPlanHdf
113114
else:
114-
geom_hdf = RasGeomHdf(args.hdf_file)
115+
ras_hdf_class = RasGeomHdf
116+
if re.match(r"^\w+://", args.hdf_file):
117+
geom_hdf = ras_hdf_class.open_uri(args.hdf_file)
118+
else:
119+
geom_hdf = ras_hdf_class(args.hdf_file)
115120
func = getattr(geom_hdf, args.func)
116121
gdf: GeoDataFrame = func()
117122
kwargs = literal_eval(args.kwargs) if args.kwargs else {}
118123
if args.to_crs:
119124
gdf = gdf.to_crs(args.to_crs)
120125
if not args.output_file:
121-
# convert any datetime columns to strings
126+
# If an output file path isn't provided, write the GeoDataFrame to stdout
127+
# as GeoJSON. Convert any datetime columns to strings.
122128
gdf = df_datetimes_to_str(gdf)
123129
with warnings.catch_warnings():
124130
# Squash warnings about converting the CRS to OGC URN format.
@@ -143,9 +149,9 @@ def export(args: argparse.Namespace) -> Optional[str]:
143149
output_file_path = Path(args.output_file)
144150
output_file_ext = output_file_path.suffix
145151
if output_file_ext not in [".gpkg"]:
146-
# unless the user specifies a format that supports datetime,
147-
# convert any datetime columns to string
148-
# TODO: besides Geopackage, which of the standard Fiona formats allow datetime?
152+
# Unless the user specifies a format that supports datetime,
153+
# convert any datetime columns to string.
154+
# TODO: besides Geopackage, which of the standard Fiona drivers allow datetime?
149155
gdf = df_datetimes_to_str(gdf)
150156
gdf.to_file(args.output_file, **kwargs)
151157

src/rashdf/geom.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def mesh_area_names(self) -> List[str]:
6666
List[str]
6767
A list of the 2D mesh area names (str) within the RAS geometry if 2D areas exist.
6868
"""
69-
if "/Geometry/2D Flow Areas" not in self:
69+
if self.FLOW_AREA_2D_PATH not in self:
7070
return list()
7171
return list(
7272
[
7373
convert_ras_hdf_string(n)
74-
for n in self["/Geometry/2D Flow Areas/Attributes"][()]["Name"]
74+
for n in self[f"{self.FLOW_AREA_2D_PATH}/Attributes"][()]["Name"]
7575
]
7676
)
7777

@@ -87,7 +87,7 @@ def mesh_areas(self) -> GeoDataFrame:
8787
if not mesh_area_names:
8888
return GeoDataFrame()
8989
mesh_area_polygons = [
90-
Polygon(self[f"/Geometry/2D Flow Areas/{n}/Perimeter"][()])
90+
Polygon(self[f"{self.FLOW_AREA_2D_PATH}/{n}/Perimeter"][()])
9191
for n in mesh_area_names
9292
]
9393
return GeoDataFrame(
@@ -112,13 +112,13 @@ def mesh_cell_polygons(self) -> GeoDataFrame:
112112

113113
cell_dict = {"mesh_name": [], "cell_id": [], "geometry": []}
114114
for i, mesh_name in enumerate(mesh_area_names):
115-
cell_cnt = self["/Geometry/2D Flow Areas/Cell Info"][()][i][1]
115+
cell_cnt = self[f"{self.FLOW_AREA_2D_PATH}/Cell Info"][()][i][1]
116116
cell_ids = list(range(cell_cnt))
117117
cell_face_info = self[
118-
f"/Geometry/2D Flow Areas/{mesh_name}/Cells Face and Orientation Info"
118+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/Cells Face and Orientation Info"
119119
][()]
120120
cell_face_values = self[
121-
f"/Geometry/2D Flow Areas/{mesh_name}/Cells Face and Orientation Values"
121+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/Cells Face and Orientation Values"
122122
][()][:, 0]
123123
face_id_lists = list(
124124
np.vectorize(
@@ -169,8 +169,8 @@ def mesh_cell_points(self) -> GeoDataFrame:
169169
return GeoDataFrame()
170170
pnt_dict = {"mesh_name": [], "cell_id": [], "geometry": []}
171171
for i, mesh_name in enumerate(mesh_area_names):
172-
starting_row, count = self["/Geometry/2D Flow Areas/Cell Info"][()][i]
173-
cell_pnt_coords = self["/Geometry/2D Flow Areas/Cell Points"][()][
172+
starting_row, count = self[f"{self.FLOW_AREA_2D_PATH}/Cell Info"][()][i]
173+
cell_pnt_coords = self[f"{self.FLOW_AREA_2D_PATH}/Cell Points"][()][
174174
starting_row : starting_row + count
175175
]
176176
pnt_dict["mesh_name"] += [mesh_name] * cell_pnt_coords.shape[0]
@@ -196,16 +196,16 @@ def mesh_cell_faces(self) -> GeoDataFrame:
196196
face_dict = {"mesh_name": [], "face_id": [], "geometry": []}
197197
for mesh_name in mesh_area_names:
198198
facepoints_index = self[
199-
f"/Geometry/2D Flow Areas/{mesh_name}/Faces FacePoint Indexes"
199+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/Faces FacePoint Indexes"
200200
][()]
201201
facepoints_coordinates = self[
202-
f"/Geometry/2D Flow Areas/{mesh_name}/FacePoints Coordinate"
202+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/FacePoints Coordinate"
203203
][()]
204204
faces_perimeter_info = self[
205-
f"/Geometry/2D Flow Areas/{mesh_name}/Faces Perimeter Info"
205+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/Faces Perimeter Info"
206206
][()]
207207
faces_perimeter_values = self[
208-
f"/Geometry/2D Flow Areas/{mesh_name}/Faces Perimeter Values"
208+
f"{self.FLOW_AREA_2D_PATH}/{mesh_name}/Faces Perimeter Values"
209209
][()]
210210
face_id = -1
211211
for pnt_a_index, pnt_b_index in facepoints_index:

0 commit comments

Comments
 (0)