4444 Tuple ,
4545 Union ,
4646 Callable ,
47+ Set ,
4748)
4849
4950import os
5051import numpy as np
5152import pandas as pd
53+ from numpy .polynomial .legendre import leggauss
5254from schimpy .stacked_dem_fill import create_dem_sampler
53- from schimpy .schism_mesh import read_mesh , write_mesh
54-
55- # Shoreline helper functions
56-
57- from dataclasses import dataclass
58- from typing import Iterable , Tuple , Dict , Set , List , Optional
59- import numpy as np
60- import os
61-
62- # requested import
63- from schimpy .schism_mesh import read_mesh
55+ from schimpy .schism_mesh import *
6456import matplotlib .pyplot as plt
65-
57+ from collections import defaultdict , deque
58+ import csv
59+ import argparse
60+ import logging
6661
6762try :
6863 from shapely .geometry import Point , LineString , mapping
@@ -152,7 +147,6 @@ def _perimeter_edges_of_region(mesh, in_region: np.ndarray) -> Set[int]:
152147
153148def _build_perimeter_loops (mesh , perim_edges : Set [int ]) -> List [Dict ]:
154149 """Deterministic ordering of loops and edges."""
155- from collections import defaultdict
156150
157151 edges = mesh .edges
158152 adj = defaultdict (list )
@@ -282,7 +276,6 @@ def floodfill_always_wet(
282276
283277 # Stage 1 BFS
284278 in1 = np .zeros (nE , dtype = bool )
285- from collections import deque
286279
287280 q = deque ()
288281 for ei in seeds :
@@ -594,7 +587,6 @@ def edge_id(k):
594587
595588
596589def _write_perimeter_csv (mesh , labels : Dict [int , str ], path : str ) -> None :
597- import csv
598590
599591 with open (path , "w" , newline = "" ) as f :
600592 w = csv .writer (f )
@@ -605,7 +597,6 @@ def _write_perimeter_csv(mesh, labels: Dict[int, str], path: str) -> None:
605597
606598
607599def _write_wet_elems_csv (mask : np .ndarray , path : str ) -> None :
608- import csv
609600
610601 idxs = np .flatnonzero (mask .astype (bool ))
611602 with open (path , "w" , newline = "" ) as f :
@@ -620,6 +611,7 @@ def _write_perimeter_shapefile(
620611) -> None :
621612 """
622613 Write 2D polyline Shapefile (.shp + .shx + .dbf, and .prj if EPSG given) for perimeter edges.
614+ Uses geopandas + shapely only.
623615 """
624616
625617 xs , ys = mesh .nodes [:, 0 ], mesh .nodes [:, 1 ]
@@ -654,8 +646,6 @@ def _write_perimeter_shapefile(
654646
655647
656648# ------------------------ Merging + Visualization -----------------------------
657- from typing import Dict , List , Tuple , Iterable , Optional , Set
658- import numpy as np
659649
660650
661651def _edge_pairs (mesh , edge_ids : Iterable [int ]) -> List [Tuple [int , int ]]:
@@ -671,7 +661,6 @@ def _build_chains_from_edges(pairs: List[Tuple[int, int]]) -> List[List[int]]:
671661 Given undirected edge (n1,n2) pairs, split into maximal paths or cycles and
672662 return ordered node lists (one per chain).
673663 """
674- from collections import defaultdict
675664
676665 adj = defaultdict (list )
677666 edge_set = set ()
@@ -797,7 +786,6 @@ def _write_merged_shapefile(polylines, path: str, epsg: int = None):
797786
798787
799788def _write_nodes_csv (node_rows , path : str , epsg : int = None ):
800- import csv
801789
802790 with open (path , "w" , newline = "" ) as f :
803791 if epsg :
@@ -894,17 +882,6 @@ def _roll(arr, k, mode):
894882
895883# ------------------- Variational/TVD refinement -------------------
896884
897- from dataclasses import dataclass
898- from typing import Callable , Dict , List , Optional , Tuple , Union
899- import os
900-
901-
902- import numpy as np
903-
904-
905- from schimpy .stacked_dem_fill import create_dem_sampler
906- from schimpy .schism_mesh import *
907-
908885# ---- Lightweight geometry/quadrature and TV machinery (adapted & trimmed) ----
909886
910887
@@ -961,7 +938,6 @@ def _map_tri(xy: np.ndarray, bary: np.ndarray) -> np.ndarray:
961938
962939 @staticmethod
963940 def _gauss_legendre_1d (n : int ) -> Tuple [np .ndarray , np .ndarray ]:
964- from numpy .polynomial .legendre import leggauss
965941
966942 return leggauss (n )
967943
@@ -1231,7 +1207,6 @@ def _build_S_tri6() -> np.ndarray:
12311207
12321208 @staticmethod
12331209 def _build_S_quad (n : int ) -> np .ndarray :
1234- from numpy .polynomial .legendre import leggauss
12351210
12361211 xi1d , _ = leggauss (n )
12371212 XI , ETA = np .meshgrid (xi1d , xi1d )
@@ -1671,7 +1646,6 @@ def build_shore_floor_from_df(
16711646 mask : numpy.ndarray of bool
16721647 True where a floor value is defined.
16731648 """
1674- import numpy as np
16751649
16761650 df = df .copy ()
16771651 df ["node0" ] = df ["node" ].astype (int ) - 1
@@ -2083,8 +2057,6 @@ def refine_volume_tvd(
20832057 # Optional triple profiles
20842058 if (shoreline is not None ) and (profiles is not None and len (profiles ) > 0 ):
20852059 try :
2086- import pandas as pd
2087- import matplotlib .pyplot as plt
20882060
20892061 # Reuse the function from the example without importing to avoid circularity
20902062 # Compute distances and dump a quick triple for selected ids
@@ -2111,7 +2083,6 @@ def refine_volume_tvd(
21112083 z_fin = z [nodes ]
21122084 # Try to plot a filtered floor if available
21132085 z_flt = z_floor [nodes ] if (z_floor is not None ) else None
2114- import matplotlib .pyplot as plt
21152086
21162087 fig , ax = plt .subplots (figsize = (8 , 3.0 ))
21172088 (base_line ,) = ax .plot (s , z_orig , label = f"original" )
@@ -2143,8 +2114,6 @@ def refine_volume_tvd(
21432114
21442115
21452116def _cli ():
2146- import argparse
2147- import logging
21482117
21492118 ap = argparse .ArgumentParser (
21502119 description = "TVD-regularized volume tuning (shoreline + floor + TVD)."
0 commit comments