From d95635b9852ed47f911e25139009194081242259 Mon Sep 17 00:00:00 2001 From: Wes Bonelli Date: Tue, 19 Sep 2023 00:16:48 -0400 Subject: [PATCH] refactor(triangle): raise if output files not found --- flopy/utils/triangle.py | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/flopy/utils/triangle.py b/flopy/utils/triangle.py index d974d367fa..9d7c5bb7b4 100644 --- a/flopy/utils/triangle.py +++ b/flopy/utils/triangle.py @@ -57,7 +57,6 @@ def __init__( self._nodes = nodes self.additional_args = additional_args self._initialize_vars() - return def add_polygon(self, polygon): """ @@ -90,7 +89,6 @@ def add_polygon(self, polygon): if len(polygon) > 1: for hole in polygon[1:]: self.add_hole(hole) - return def add_hole(self, hole): """ @@ -107,7 +105,6 @@ def add_hole(self, hole): """ self._holes.append(hole) - return def add_region(self, point, attribute=0, maximum_area=None): """ @@ -131,7 +128,6 @@ def add_region(self, point, attribute=0, maximum_area=None): """ self._regions.append([point, attribute, maximum_area]) - return def build(self, verbose=False): """ @@ -196,8 +192,6 @@ def build(self, verbose=False): for row in self.ele: self.iverts.append([row[1], row[2], row[3]]) - return - def plot( self, ax=None, @@ -320,7 +314,6 @@ def plot_boundary(self, ibm, ax=None, **kwargs): y1 = self.node["y"][iv1] y2 = self.node["y"][iv2] ax.plot([x1, x2], [y1, y2], **kwargs) - return def plot_vertices(self, ax=None, **kwargs): """ @@ -342,7 +335,6 @@ def plot_vertices(self, ax=None, **kwargs): if ax is None: ax = plt.gca() ax.plot(self.node["x"], self.node["y"], lw=0, **kwargs) - return def label_vertices(self, ax=None, onebased=True, **kwargs): """ @@ -374,7 +366,6 @@ def label_vertices(self, ax=None, onebased=True, **kwargs): if onebased: s += 1 ax.text(x, y, str(s), **kwargs) - return def plot_centroids(self, ax=None, **kwargs): """ @@ -397,7 +388,6 @@ def plot_centroids(self, ax=None, **kwargs): ax = plt.gca() xcyc = self.get_xcyc() ax.plot(xcyc[:, 0], xcyc[:, 1], lw=0, **kwargs) - return def label_cells(self, ax=None, onebased=True, **kwargs): """ @@ -430,7 +420,6 @@ def label_cells(self, ax=None, onebased=True, **kwargs): if onebased: s += 1 ax.text(x, y, str(s), **kwargs) - return def get_xcyc(self): """ @@ -600,7 +589,6 @@ def clean(self): os.remove(fname) if os.path.isfile(fname): print(f"Could not remove: {fname}") - return def _initialize_vars(self): self.file_prefix = "_triangle" @@ -613,7 +601,6 @@ def _initialize_vars(self): self.verts = None self.iverts = None self.edgedict = None - return def _load_results(self): # node file @@ -621,8 +608,7 @@ def _load_results(self): dt = [("ivert", int), ("x", float), ("y", float)] fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}") setattr(self, ext, None) - if os.path.isfile(fname): - f = open(fname, "r") + with open(fname, "r") as f: line = f.readline() f.close() ll = line.strip().split() @@ -644,8 +630,7 @@ def _load_results(self): dt = [("icell", int), ("iv1", int), ("iv2", int), ("iv3", int)] fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}") setattr(self, ext, None) - if os.path.isfile(fname): - f = open(fname, "r") + with open(fname, "r") as f: line = f.readline() f.close() ll = line.strip().split() @@ -664,8 +649,7 @@ def _load_results(self): dt = [("iedge", int), ("endpoint1", int), ("endpoint2", int)] fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}") setattr(self, ext, None) - if os.path.isfile(fname): - f = open(fname, "r") + with open(fname, "r") as f: line = f.readline() f.close() ll = line.strip().split() @@ -687,8 +671,7 @@ def _load_results(self): ] fname = os.path.join(self.model_ws, f"{self.file_prefix}.1.{ext}") setattr(self, ext, None) - if os.path.isfile(fname): - f = open(fname, "r") + with open(fname, "r") as f: line = f.readline() f.close() ll = line.strip().split() @@ -699,8 +682,6 @@ def _load_results(self): assert a.shape[0] == ncells setattr(self, ext, a) - return - def _write_nodefile(self, fname): f = open(fname, "w") nvert = 0 @@ -776,7 +757,6 @@ def _write_polyfile(self, fname): f.write(s) f.close() - return def _create_edge_dict(self): """ @@ -789,4 +769,3 @@ def _create_edge_dict(self): edgedict[(iv1, iv2)] = iseg edgedict[(iv2, iv1)] = iseg self.edgedict = edgedict - return