rashdf 0.10.0__tar.gz → 0.11.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rashdf
3
- Version: 0.10.0
3
+ Version: 0.11.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
@@ -17,6 +17,7 @@ Requires-Dist: h5py
17
17
  Requires-Dist: geopandas<2.0,>=1.0
18
18
  Requires-Dist: pyarrow
19
19
  Requires-Dist: xarray<=2025.4.0
20
+ Requires-Dist: pandas<3.0,>=2.0
20
21
  Provides-Extra: dev
21
22
  Requires-Dist: pre-commit; extra == "dev"
22
23
  Requires-Dist: ruff; extra == "dev"
@@ -29,6 +30,7 @@ Requires-Dist: fsspec; extra == "dev"
29
30
  Requires-Dist: s3fs; extra == "dev"
30
31
  Requires-Dist: fiona==1.9.6; extra == "dev"
31
32
  Requires-Dist: numcodecs<0.16; extra == "dev"
33
+ Requires-Dist: rioxarray; extra == "dev"
32
34
  Provides-Extra: docs
33
35
  Requires-Dist: sphinx; extra == "docs"
34
36
  Requires-Dist: numpydoc; extra == "docs"
@@ -12,8 +12,14 @@ classifiers = [
12
12
  "Programming Language :: Python :: 3.12",
13
13
  "Programming Language :: Python :: 3.13",
14
14
  ]
15
- version = "0.10.0"
16
- dependencies = ["h5py", "geopandas>=1.0,<2.0", "pyarrow", "xarray<=2025.4.0"]
15
+ version = "0.11.0"
16
+ dependencies = [
17
+ "h5py",
18
+ "geopandas>=1.0,<2.0",
19
+ "pyarrow",
20
+ "xarray<=2025.4.0",
21
+ "pandas>=2.0,<3.0"
22
+ ]
17
23
 
18
24
  [project.optional-dependencies]
19
25
  dev = [
@@ -27,7 +33,8 @@ dev = [
27
33
  "fsspec",
28
34
  "s3fs",
29
35
  "fiona==1.9.6",
30
- "numcodecs<0.16"
36
+ "numcodecs<0.16",
37
+ "rioxarray",
31
38
  ]
32
39
  docs = ["sphinx", "numpydoc", "sphinx_rtd_theme"]
33
40
 
@@ -150,13 +150,13 @@ class RasGeomHdf(RasHdf):
150
150
  ][()][:, 0]
151
151
  face_id_lists = list(
152
152
  np.vectorize(
153
- lambda cell_id,
154
- cell_face_values=cell_face_values,
155
- cell_face_info=cell_face_info: str(
156
- cell_face_values[
157
- cell_face_info[cell_id][0] : cell_face_info[cell_id][0]
158
- + cell_face_info[cell_id][1]
159
- ]
153
+ lambda cell_id, cell_face_values=cell_face_values, cell_face_info=cell_face_info: (
154
+ str(
155
+ cell_face_values[
156
+ cell_face_info[cell_id][0] : cell_face_info[cell_id][0]
157
+ + cell_face_info[cell_id][1]
158
+ ]
159
+ )
160
160
  )
161
161
  )(cell_ids)
162
162
  )
@@ -4,6 +4,7 @@ from .geom import RasGeomHdf
4
4
  from .utils import (
5
5
  df_datetimes_to_str,
6
6
  ras_timesteps_to_datetimes,
7
+ parse_ras_datetime,
7
8
  parse_ras_datetime_ms,
8
9
  deprecated,
9
10
  convert_ras_hdf_value,
@@ -18,7 +19,7 @@ import xarray as xr
18
19
 
19
20
  from datetime import datetime
20
21
  from enum import Enum
21
- from typing import Dict, List, Optional, Tuple, Union
22
+ from typing import Dict, List, Optional, Tuple, Union, Sequence
22
23
 
23
24
  # Shared constant
24
25
  WATER_SURFACE = "Water Surface"
@@ -1927,3 +1928,65 @@ class RasPlanHdf(RasGeomHdf):
1927
1928
  }
1928
1929
 
1929
1930
  return wide_df
1931
+
1932
+ def gridded_precip(
1933
+ self,
1934
+ timestamps: Optional[Union[Sequence[datetime], pd.Series]] = None,
1935
+ precip_attrs: Optional[Dict] = None,
1936
+ ) -> xr.DataArray:
1937
+ """Return precipitation timeseries input data from a HEC-RAS HDF plan file.
1938
+
1939
+ Requires the 'rioxarray' package.
1940
+
1941
+ Parameters
1942
+ ----------
1943
+ timestamps : Optional[Union[Sequence[datetime], pd.Series]], optional
1944
+ Optional sequence of timestamps to use for the time coordinate. If None, timestamps will be read from the HDF file.
1945
+ precip_attrs : Optional[Dict], optional
1946
+ Optional dictionary of precipitation attributes. If None, attributes will be read from the HDF file.
1947
+
1948
+ Returns
1949
+ -------
1950
+ xr.DataArray
1951
+ An xarray DataArray with precipitation timeseries input data.
1952
+ """
1953
+ import rioxarray
1954
+
1955
+ precip_group = self[self.PRECIP_PATH]
1956
+ precip_values: h5py.Dataset = precip_group["Values"]
1957
+ if timestamps is None:
1958
+ ds_timestamps: h5py.Dataset = precip_group["Timestamp"]
1959
+ timestamps = pd.Series(ds_timestamps.asstr()[:]).map(parse_ras_datetime)
1960
+ if precip_attrs is None:
1961
+ precip_attrs = self.get_meteorology_precip_attrs()
1962
+ crs = precip_attrs.get("Projection")
1963
+ rows = precip_attrs.get("Raster Rows")
1964
+ cols = precip_attrs.get("Raster Cols")
1965
+ top = precip_attrs.get("Raster Top")
1966
+ left = precip_attrs.get("Raster Left")
1967
+ cell_size = precip_attrs.get("Raster Cellsize")
1968
+ if not all([rows, cols, top, left, cell_size]):
1969
+ raise RasPlanHdfError(
1970
+ "Precipitation raster metadata is missing or incomplete."
1971
+ )
1972
+
1973
+ precip_values: np.ndarray = precip_values[:]
1974
+ precip_values = precip_values.reshape(precip_values.shape[0], rows, cols)
1975
+ x_coords = left + np.arange(cols) * cell_size + cell_size / 2
1976
+ y_coords = top - np.arange(rows) * cell_size - cell_size / 2
1977
+ precip = xr.DataArray(
1978
+ precip_values,
1979
+ name="Precipitation",
1980
+ dims=["time", "y", "x"],
1981
+ coords={
1982
+ "time": timestamps,
1983
+ "y": y_coords,
1984
+ "x": x_coords,
1985
+ },
1986
+ attrs={
1987
+ "units": precip_attrs.get("Units"),
1988
+ "hdf_path": f"{self.PRECIP_PATH}/Values",
1989
+ },
1990
+ )
1991
+ precip = precip.rio.write_crs(crs)
1992
+ return precip
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rashdf
3
- Version: 0.10.0
3
+ Version: 0.11.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
@@ -17,6 +17,7 @@ Requires-Dist: h5py
17
17
  Requires-Dist: geopandas<2.0,>=1.0
18
18
  Requires-Dist: pyarrow
19
19
  Requires-Dist: xarray<=2025.4.0
20
+ Requires-Dist: pandas<3.0,>=2.0
20
21
  Provides-Extra: dev
21
22
  Requires-Dist: pre-commit; extra == "dev"
22
23
  Requires-Dist: ruff; extra == "dev"
@@ -29,6 +30,7 @@ Requires-Dist: fsspec; extra == "dev"
29
30
  Requires-Dist: s3fs; extra == "dev"
30
31
  Requires-Dist: fiona==1.9.6; extra == "dev"
31
32
  Requires-Dist: numcodecs<0.16; extra == "dev"
33
+ Requires-Dist: rioxarray; extra == "dev"
32
34
  Provides-Extra: docs
33
35
  Requires-Dist: sphinx; extra == "docs"
34
36
  Requires-Dist: numpydoc; extra == "docs"
@@ -2,6 +2,7 @@ h5py
2
2
  geopandas<2.0,>=1.0
3
3
  pyarrow
4
4
  xarray<=2025.4.0
5
+ pandas<3.0,>=2.0
5
6
 
6
7
  [dev]
7
8
  pre-commit
@@ -15,6 +16,7 @@ fsspec
15
16
  s3fs
16
17
  fiona==1.9.6
17
18
  numcodecs<0.16
19
+ rioxarray
18
20
 
19
21
  [docs]
20
22
  sphinx
@@ -834,3 +834,23 @@ def test_bc_lines_flow(tmp_path: Path):
834
834
  dtype={"Flow": np.float32},
835
835
  )
836
836
  assert_frame_equal(df_bcline7, valid_df, check_dtype=False)
837
+
838
+
839
+ def test_gridded_precip():
840
+ plan_hdf = RasPlanHdf(TEST_DATA / "ras/ElkMiddle.gridded-precip.p01.hdf")
841
+ precip = plan_hdf.gridded_precip()
842
+ assert precip.shape == (24, 160, 110)
843
+ assert (
844
+ precip.attrs["units"]
845
+ == plan_hdf["/Event Conditions/Meteorology/Precipitation"]
846
+ .attrs["Units"]
847
+ .decode()
848
+ )
849
+
850
+
851
+ def test_gridded_precip_bad_precip_attrs():
852
+ plan_hdf = RasPlanHdf(TEST_DATA / "ras/ElkMiddle.gridded-precip.p01.hdf")
853
+ precip_attrs = plan_hdf.get_meteorology_precip_attrs()
854
+ precip_attrs.pop("Raster Rows")
855
+ with pytest.raises(RasPlanHdfError):
856
+ plan_hdf.gridded_precip(precip_attrs=precip_attrs)
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
File without changes