From 22037a0ba9c530f87ee872768f81bd0ce7d18631 Mon Sep 17 00:00:00 2001 From: Prisca van der Sluis Date: Thu, 16 Nov 2023 14:04:45 +0100 Subject: [PATCH] #569: Add docs and remove code smells --- hydrolib/core/dflowfm/net/models.py | 19 ++++++++++++++----- tests/dflowfm/test_net.py | 3 +-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hydrolib/core/dflowfm/net/models.py b/hydrolib/core/dflowfm/net/models.py index 99d98fe98..36f6b3291 100644 --- a/hydrolib/core/dflowfm/net/models.py +++ b/hydrolib/core/dflowfm/net/models.py @@ -1151,13 +1151,17 @@ def to_file(self, file: Path) -> None: writer.write(self, file) @property - def is_geographic(self): + def is_geographic(self) -> bool: + """Whether or not this network has a geographic projection. + + Returns: + bool: True if this network is geographic; otherwise, False. + """ projection = self.meshkernel.get_projection() if projection == mk.ProjectionType.CARTESIAN: - is_geographic = False + return False else: - is_geographic = True - return is_geographic + return True def link1d2d_from_1d_to_2d( self, branchids: List[str] = None, polygon: GeometryList = None @@ -1218,8 +1222,13 @@ def mesh1d_add_branch( return name def plot(self, ax=None): - import matplotlib.pyplot as plt + """Create a plot of the 1d2d links and edges within this network. + Args: + ax (matplotlib.pyplot.Axes, optional): The axes where to plot the edges. Defaults to None. + """ + import matplotlib.pyplot as plt + if ax is None: _, ax = plt.subplots() mesh2d_output = self._mesh2d.get_mesh2d() diff --git a/tests/dflowfm/test_net.py b/tests/dflowfm/test_net.py index 8e7350d6a..b7cfacb5b 100644 --- a/tests/dflowfm/test_net.py +++ b/tests/dflowfm/test_net.py @@ -152,7 +152,6 @@ def test_create_1d_2d_1d2d(): # read from written file network2 = NetworkModel(file_out) - mesh2d_output = network2._mesh2d.get_mesh2d() assert len(network2._mesh2d.mesh2d_face_x) == 152 mesh1d_output = network2._mesh1d._get_mesh1d() assert len(mesh1d_output.node_x) == 110 @@ -169,7 +168,7 @@ def test_create_1d_2d_1d2d(): # plot both networks import matplotlib.pyplot as plt - fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4)) + _, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4)) network.plot(ax=ax1) network2.plot(ax=ax2)