Skip to content

Commit

Permalink
Remove deprecations for ResultReach
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-kipawa committed Dec 19, 2024
1 parent 602b4e3 commit c08e279
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _create_dataframe_data_dict(self, reaches: ResultReaches) -> dict[str, tuple
"geometry": [],
}
for reach in reaches.values():
for res1d_reach in reach.reaches:
for res1d_reach in reach.res1d_reaches:
data["group"].append(TimeSeriesIdGroup.REACH)
data["name"].append(reach.name)
data["tag"].append(TimeSeriesId.create_reach_span_tag(res1d_reach))
Expand Down
2 changes: 1 addition & 1 deletion mikeio1d/result_network/result_gridpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_m1d_dataset(self, m1d_dataitem: IDataItem = None) -> IRes1DGridPoint:
IRes1DDataSet object associated with ResultGridPoint.
"""
return self.reach
return self.res1d_reach

def get_query(self, data_item: IDataItem) -> QueryDataReach:
"""Get a QueryDataReach for given data item."""
Expand Down
21 changes: 0 additions & 21 deletions mikeio1d/result_network/result_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ def __repr__(self) -> str:
"""Return a string representation of ResultReach."""
return f"<Reach: {self.name}>"

def __getattr__(self, name: str):
"""Get attributes, warnings of deprecated attributes."""
# TODO: Remove this in 1.0.0
if hasattr(self.res1d_reaches[0], name):
warnings.warn(
f"Accessing IRes1DReach attribute {name} like this is deprecated. Use static attributes instead, or .reaches[0].{name}."
)
return getattr(self.res1d_reaches[0], name)
else:
object.__getattribute__(self, name)

def __getitem__(self, key: str | int) -> ResultGridPoint:
"""Get a ResultGridPoint object by chainage."""
if isinstance(key, int):
Expand Down Expand Up @@ -215,16 +204,6 @@ def interpolate_reach_critical_level(self, chainage: float) -> float:
"""
return self._creator._interpolate_reach_critical_level(chainage)

# region Deprecated methods and attributes of ResultReach.

@property
def reaches(self) -> List[IRes1DReach]:
"""List of IRes1DReach corresponding to this result location."""
warnings.warn("The 'reaches' property is deprecated. Use 'res1d_reaches' instead.")
return self.res1d_reaches

# endregion


class ResultReachCreator(ResultLocationCreator):
"""Helper class for creating ResultReach.
Expand Down
18 changes: 9 additions & 9 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,28 @@ def test_reach_chainage_from_geometric_distance(self, reach_geometry):
assert reach_geometry.chainage_from_geometric_distance((1**2 + 1**2) ** 0.5) == 10

def test_from_res1d_reaches(self, river_reach):
g = ReachGeometry.from_res1d_reaches(river_reach.reaches)
expected_n_gridpoints = sum([reach.GridPoints.Count for reach in river_reach.reaches])
g = ReachGeometry.from_res1d_reaches(river_reach.res1d_reaches)
expected_n_gridpoints = sum([reach.GridPoints.Count for reach in river_reach.res1d_reaches])
assert len(g.gridpoints) == expected_n_gridpoints
expected_n_digipoints = sum([reach.DigiPoints.Count for reach in river_reach.reaches])
expected_n_digipoints = sum([reach.DigiPoints.Count for reach in river_reach.res1d_reaches])
assert len(g.digipoints) == expected_n_digipoints
assert len(g.points) == expected_n_gridpoints + expected_n_digipoints
gp_start = river_reach.reaches[0].GridPoints[0]
gp_start = river_reach.res1d_reaches[0].GridPoints[0]
assert g.gridpoints[0].x == pytest.approx(gp_start.X)
assert g.gridpoints[0].y == pytest.approx(gp_start.Y)
assert g.gridpoints[0].z == pytest.approx(gp_start.Z)
assert g.gridpoints[0].chainage == pytest.approx(gp_start.Chainage)
dp_start = river_reach.reaches[0].DigiPoints[0]
dp_start = river_reach.res1d_reaches[0].DigiPoints[0]
assert g.digipoints[0].x == pytest.approx(dp_start.X)
assert g.digipoints[0].y == pytest.approx(dp_start.Y)
assert g.digipoints[0].z == pytest.approx(dp_start.Z)
assert g.digipoints[0].chainage == pytest.approx(dp_start.M)
gp_end = list(river_reach.reaches[-1].GridPoints)[-1]
gp_end = list(river_reach.res1d_reaches[-1].GridPoints)[-1]
assert g.gridpoints[-1].x == pytest.approx(gp_end.X)
assert g.gridpoints[-1].y == pytest.approx(gp_end.Y)
assert g.gridpoints[-1].z == pytest.approx(gp_end.Z)
assert g.gridpoints[-1].chainage == pytest.approx(gp_end.Chainage)
dp_end = list(river_reach.reaches[-1].DigiPoints)[-1]
dp_end = list(river_reach.res1d_reaches[-1].DigiPoints)[-1]
assert g.digipoints[-1].x == pytest.approx(dp_end.X)
assert g.digipoints[-1].y == pytest.approx(dp_end.Y)
assert g.digipoints[-1].z == pytest.approx(dp_end.Z)
Expand All @@ -114,7 +114,7 @@ def test_from_res1d_reaches(self, river_reach):
assert g.length == pytest.approx(2024.2276598819008)

def test_reaches_point_interpolation_matches_mikeplus(self, river_reach):
g = ReachGeometry.from_res1d_reaches(river_reach.reaches)
g = ReachGeometry.from_res1d_reaches(river_reach.res1d_reaches)
shape = g.to_shapely()
# from MIKE+ chainage_points
expected_coords = {
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_geometry_from_nodes_runs(many_nodes):

def test_geometry_from_reaches_runs(many_reaches):
for reach in many_reaches:
g = ReachGeometry.from_res1d_reaches(reach.reaches).to_shapely()
g = ReachGeometry.from_res1d_reaches(reach.res1d_reaches).to_shapely()
assert isinstance(g, shapely.LineString)


Expand Down
6 changes: 4 additions & 2 deletions tests/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ def test_geopandas_reaches_converter_segmented(res1d_river_network):
converter = GeoPandasReachesConverterSegmented()
gdf = converter.to_geopandas(res1d_river_network.reaches)
assert isinstance(gdf, GeoDataFrame)
number_of_segments = sum(len(reach.reaches) for reach in res1d_river_network.reaches.values())
number_of_segments = sum(
len(reach.res1d_reaches) for reach in res1d_river_network.reaches.values()
)
assert len(gdf) == number_of_segments
assert ["group", "name", "tag", "geometry"] == list(gdf.columns)
sample_reach_name = "river"
sample_reach_segments = res1d_river_network.reaches[sample_reach_name].reaches
sample_reach_segments = res1d_river_network.reaches[sample_reach_name].res1d_reaches
sample_reach = sample_reach_segments[len(sample_reach_segments) // 2]
sample_reach_tag = TimeSeriesId.create_reach_span_tag(sample_reach)
geometry = gdf.query(f"name == '{sample_reach_name}' and tag == '{sample_reach_tag}'").iloc[0][
Expand Down
8 changes: 0 additions & 8 deletions tests/test_res1d_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,3 @@ def test_structure_reach_maintains_backweards_compatibility(res1d_network):

with pytest.warns(UserWarning):
assert structures.s_119w1.structure_id == structures.s_119w1.id


def test_reaches_dict_access_maintains_backwards_compatibility(res1d_network, res1d_river_network):
with pytest.warns(UserWarning):
# Indexing reaches could return a single dotnet reach
reach = res1d_network.reaches["100l1"]
assert reach.Name == "100l1"
assert reach.Length == pytest.approx(47.6827148432828)

0 comments on commit c08e279

Please sign in to comment.