From ddb5f0f480046b429453cf189794c3912e6431c2 Mon Sep 17 00:00:00 2001 From: Jacob Bates Date: Mon, 24 Feb 2025 16:30:30 -0600 Subject: [PATCH] add encroachment_points method and test coverage --- src/rashdf/plan.py | 43 ++- tests/data/json/encroachment_points.json | 461 +++++++++++++++++++++++ tests/test_plan.py | 9 + 3 files changed, 511 insertions(+), 2 deletions(-) create mode 100644 tests/data/json/encroachment_points.json diff --git a/src/rashdf/plan.py b/src/rashdf/plan.py index 65de63b..ca2f21c 100644 --- a/src/rashdf/plan.py +++ b/src/rashdf/plan.py @@ -1381,8 +1381,47 @@ def get_results_volume_accounting_attrs(self) -> Dict: """ return self.get_attrs(self.VOLUME_ACCOUNTING_PATH) - def enroachment_points(self) -> GeoDataFrame: # noqa: D102 - raise NotImplementedError + def encroachment_points(self, profile_name: str) -> GeoDataFrame: + """Return encroachment points from a HEC-RAS plan HDF file based on a user-specified flow profile. + + Returns + ------- + GeoDataframe + A GeoDataFrame with cross-section encroachments represented as Point geometry features along with pertinent attributes. + """ + XSs = self.cross_sections() + XSs["Enc_Profile"] = profile_name + + leftmost_sta = self.cross_sections_elevations()["elevation info"].apply( + lambda x: x[0][0] + ) + left_enc_sta = self.cross_sections_additional_enc_station_left()[profile_name] + left_enc_points = GeoDataFrame( + pd.concat( + [ + XSs[["River", "Reach", "RS", "Enc_Profile"]], + left_enc_sta.rename("Enc_Sta", inplace=False), + ], + axis=1, + ), + geometry=XSs.geometry.interpolate(left_enc_sta - leftmost_sta), + ) + left_enc_points["Side"] = "Left" + + right_enc_sta = self.cross_sections_additional_enc_station_right()[profile_name] + right_enc_points = GeoDataFrame( + pd.concat( + [ + XSs[["River", "Reach", "RS", "Enc_Profile"]], + right_enc_sta.rename("Enc_Sta", inplace=False), + ], + axis=1, + ), + geometry=XSs.geometry.interpolate(right_enc_sta - leftmost_sta), + ) + right_enc_points["Side"] = "Right" + + return GeoDataFrame(pd.concat([left_enc_points, right_enc_points])) def steady_flow_names(self) -> list: """Return the profile information for each steady flow event. diff --git a/tests/data/json/encroachment_points.json b/tests/data/json/encroachment_points.json new file mode 100644 index 0000000..69c2744 --- /dev/null +++ b/tests/data/json/encroachment_points.json @@ -0,0 +1,461 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "id": "0", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.99", + "Enc_Profile": "PF#2", + "Enc_Sta": 176.92, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.01388839937458, + 0.74513518786371 + ] + } + }, + { + "id": "1", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.875*", + "Enc_Profile": "PF#2", + "Enc_Sta": 332.68, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.05704636004153, + 0.685733938522 + ] + } + }, + { + "id": "2", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.76", + "Enc_Profile": "PF#2", + "Enc_Sta": 341.0, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.07624024530036, + 0.58536612039423 + ] + } + }, + { + "id": "3", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.685*", + "Enc_Profile": "PF#2", + "Enc_Sta": 441.45, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.11155702963727, + 0.53394210024077 + ] + } + }, + { + "id": "4", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.61", + "Enc_Profile": "PF#2", + "Enc_Sta": 494.17, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.16475043154013, + 0.47702052748622 + ] + } + }, + { + "id": "5", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.49*", + "Enc_Profile": "PF#2", + "Enc_Sta": 343.44, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.23254723288707, + 0.36363811202698 + ] + } + }, + { + "id": "6", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.41", + "Enc_Profile": "PF#2", + "Enc_Sta": 313.68, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.29152704920011, + 0.26359860431742 + ] + } + }, + { + "id": "7", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.39", + "Enc_Profile": "PF#2", + "Enc_Sta": 313.68, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.30945415041177, + 0.24717319851861 + ] + } + }, + { + "id": "8", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.24*", + "Enc_Profile": "PF#2", + "Enc_Sta": 85.7, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.39560665779075, + 0.03210483108838 + ] + } + }, + { + "id": "9", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.13", + "Enc_Profile": "PF#2", + "Enc_Sta": 145.0, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.50378765947858, + -0.09164774601 + ] + } + }, + { + "id": "10", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.065*", + "Enc_Profile": "PF#2", + "Enc_Sta": 264.5, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.59867100150556, + -0.1379749574311 + ] + } + }, + { + "id": "11", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.0", + "Enc_Profile": "PF#2", + "Enc_Sta": 384.0, + "Side": "Left" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.70284530409094, + -0.1732475206763 + ] + } + }, + { + "id": "0", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.99", + "Enc_Profile": "PF#2", + "Enc_Sta": 1202.33, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.01388839937458, + 0.74513518786371 + ] + } + }, + { + "id": "1", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.875*", + "Enc_Profile": "PF#2", + "Enc_Sta": 1242.07, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.05704636004153, + 0.685733938522 + ] + } + }, + { + "id": "2", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.76", + "Enc_Profile": "PF#2", + "Enc_Sta": 1016.91, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.07624024530036, + 0.58536612039423 + ] + } + }, + { + "id": "3", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.685*", + "Enc_Profile": "PF#2", + "Enc_Sta": 1241.63, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.11155702963727, + 0.53394210024077 + ] + } + }, + { + "id": "4", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.61", + "Enc_Profile": "PF#2", + "Enc_Sta": 1326.61, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.16475043154013, + 0.47702052748622 + ] + } + }, + { + "id": "5", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.49*", + "Enc_Profile": "PF#2", + "Enc_Sta": 1232.25, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.23254723288707, + 0.36363811202698 + ] + } + }, + { + "id": "6", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.41", + "Enc_Profile": "PF#2", + "Enc_Sta": 1292.23, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.29152704920011, + 0.26359860431742 + ] + } + }, + { + "id": "7", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.39", + "Enc_Profile": "PF#2", + "Enc_Sta": 1292.23, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.30945415041177, + 0.24717319851861 + ] + } + }, + { + "id": "8", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.24*", + "Enc_Profile": "PF#2", + "Enc_Sta": 1067.45, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.39560665779075, + 0.03210483108838 + ] + } + }, + { + "id": "9", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.13", + "Enc_Profile": "PF#2", + "Enc_Sta": 660.11, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.50378765947858, + -0.09164774601 + ] + } + }, + { + "id": "10", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.065*", + "Enc_Profile": "PF#2", + "Enc_Sta": 906.65, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.59867100150556, + -0.1379749574311 + ] + } + }, + { + "id": "11", + "type": "Feature", + "properties": { + "River": "Beaver Creek", + "Reach": "Kentwood", + "RS": "5.0", + "Enc_Profile": "PF#2", + "Enc_Sta": 1296.57, + "Side": "Right" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 0.70284530409094, + -0.1732475206763 + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/test_plan.py b/tests/test_plan.py index 26c24e0..c8dbd5a 100644 --- a/tests/test_plan.py +++ b/tests/test_plan.py @@ -650,3 +650,12 @@ def test_observed_timeseries_input_rasplanhdf_error(): with RasPlanHdf(BALD_EAGLE_P18) as phdf: with pytest.raises(RasPlanHdfError): phdf.observed_timeseries_input(vartype="Flow") + + +def test_encroachment_points(): + enc_pnts_json = TEST_JSON / "encroachment_points.json" + with RasPlanHdf(FLODENCR_P01) as phdf: + assert _gdf_matches_json_alt( + phdf.encroachment_points(profile_name="PF#2"), + enc_pnts_json, + )