@@ -15,7 +15,7 @@ def _readline(fd: bytes) -> bytes:
1515 return fd .readline ().split (b"=" )[0 ].split (b"!" )[0 ].strip ()
1616
1717
18- def parse_hgrid (
18+ def parse_gr3 (
1919 path : os .PathLike [str ] | str ,
2020 include_boundaries : bool = False ,
2121 sep : str | None = None ,
@@ -39,17 +39,17 @@ def parse_hgrid(
3939 rvalue ["elements" ] = elements
4040 # boundaries
4141 if include_boundaries :
42- boundaries = collections .defaultdict (list )
42+ boundaries = collections .defaultdict (lambda : collections . defaultdict ( list ) )
4343 no_open_boundaries = int (_readline (fd ))
4444 total_open_boundary_nodes = int (_readline (fd ))
4545 for i in range (no_open_boundaries ):
4646 no_nodes_in_boundary = int (_readline (fd ))
47- boundary_nodes = np .loadtxt (fd , delimiter = sep , usecols = (0 ,), dtype = int )
48- boundaries ["open" ].append (boundary_nodes - 1 ) # 0-based index
47+ boundary_nodes = np .genfromtxt (fd , delimiter = sep , usecols = (0 ,), max_rows = no_nodes_in_boundary , dtype = int )
48+ boundaries ["open" ][ i ] .append (boundary_nodes - 1 ) # 0-based index
4949 # closed boundaries
5050 no_closed_boundaries = int (_readline (fd ))
5151 total_closed_boundary_nodes = int (_readline (fd ))
52- for _ in range (no_closed_boundaries ):
52+ for i in range (no_closed_boundaries ):
5353 # Sometimes it seems that the closed boundaries don't have a "type indicator"
5454 # For example: Test_COSINE_SFBay/hgrid.gr3
5555 # In this cases we assume that boundary type is 0 (i.e. land in schism)
@@ -61,8 +61,7 @@ def parse_hgrid(
6161 else :
6262 no_nodes_in_boundary , boundary_type = map (int , (p for p in parsed if p ))
6363 boundary_nodes = np .genfromtxt (fd , delimiter = sep , usecols = (0 ,), max_rows = no_nodes_in_boundary , dtype = int )
64- boundary_nodes -= 1 # 0-based-index
65- boundaries [boundary_type ].append (boundary_nodes )
64+ boundaries [boundary_type ][i ].append (boundary_nodes - 1 ) # 0-based index
6665 rvalue ["boundaries" ] = boundaries
6766 return rvalue
6867
@@ -94,7 +93,7 @@ def get_skews_and_base_cfls_from_path(
9493 g : float = 9.81 ,
9594 minimum_depth : float = 0.1 ,
9695) -> tuple [npt .NDArray [np .float64 ], npt .NDArray [np .float64 ]]:
97- parsed = parse_hgrid (path )
96+ parsed = parse_gr3 (path )
9897 tri = parsed ["elements" ]
9998 nodes = parsed ["nodes" ]
10099 lons = nodes [:, 0 ][tri ].T
0 commit comments