Skip to content

Commit aee329e

Browse files
committed
Changed implementation on mesh module
Gmesh class only contained implementation for ocean boundaries, this was moved to Hgrid class. Gmesh class has been removed and all meshes now inherit from mesh.base.EuclideanMesh2D
1 parent 20f4f29 commit aee329e

12 files changed

+315
-685
lines changed

pyschism/mesh/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
Namespace definitions for pyschism.mesh module
33
"""
44

5-
from pyschism.mesh.gmesh import Gmesh
65
from pyschism.mesh.hgrid import Hgrid
76
from pyschism.mesh.vgrid import Vgrid
87
from pyschism.mesh.mesh import Mesh
98

109
__all__ = [
11-
"Gmesh",
1210
"Hgrid",
1311
"Vgrid",
1412
"Mesh"

pyschism/mesh/base.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,38 @@ def __init__(
3232

3333
@classmethod
3434
def open(cls, path, crs=None, fmt="grd"):
35-
assert fmt.lower() in ['grd', 'gr3', 'adcirc', 'schism', '2dm', 'sms',
36-
'msh']
35+
assert fmt.lower() in [
36+
'grd', 'gr3', 'adcirc', 'schism',
37+
# '2dm', 'sms',
38+
# 'msh'
39+
]
3740

3841
if fmt.lower() in ['grd', 'gr3', 'adcirc', 'schism']:
3942
return cls.open_grd(path, crs)
4043

41-
elif fmt.lower() in ['2dm', 'sms']:
42-
return cls.open_2dm(path, crs)
44+
# elif fmt.lower() in ['2dm', 'sms']:
45+
# return cls.open_2dm(path, crs)
4346

44-
@classmethod
45-
def open_2dm(cls, path, crs=None):
46-
raise NotImplementedError
47+
# @classmethod
48+
# def open_2dm(cls, path, crs=None):
49+
# raise NotImplementedError
4750

4851
@classmethod
4952
def open_grd(cls, path, crs=None):
50-
_grd = grd.reader(path)
51-
_grd.pop('boundaries')
52-
return cls.from_grd(_grd, crs)
53+
grid = grd.reader(path)
54+
grid.update({"crs": crs})
55+
return cls.from_grd(grid)
5356

5457
@classmethod
5558
def open_gr3(cls, path, crs=None):
5659
return cls.open_grd(path, crs)
5760

5861
@classmethod
59-
def from_grd(cls, grid, crs=None):
60-
grid = grd.to_gmesh(grid)
61-
if 'boundaries' in grid:
62-
grid.pop('boundaries')
63-
return cls(**grid, crs=crs)
62+
def from_grd(cls, grid):
63+
"""
64+
grd is a dictionary of of the form:
65+
"""
66+
return cls(**grd.euclidean_mesh(grid))
6467

6568
def transform_to(self, dst_crs):
6669
dst_crs = CRS.from_user_input(dst_crs)
@@ -71,9 +74,7 @@ def transform_to(self, dst_crs):
7174
)
7275
xy = list(zip(*transformer.transform(self.x, self.y)))
7376
ids = list(self._coords.keys())
74-
self._coords = {
75-
ids[i]: coord for i, coord in enumerate(xy)
76-
}
77+
self._coords = {ids[i]: coord for i, coord in enumerate(xy)}
7778
self._crs = dst_crs
7879

7980
def get_node_index(self, id):
@@ -115,8 +116,8 @@ def write(self, path, overwrite=False, fmt='gr3'):
115116
def ascii_string(self, fmt):
116117
if fmt.lower() in ['grd', 'gr3', 'adcirc', 'schism']:
117118
return self.grd
118-
if fmt.lower() in ['sms', '2dm']:
119-
return self.sms
119+
# if fmt.lower() in ['sms', '2dm']:
120+
# return self.sms
120121

121122
@_figure
122123
def tricontourf(self, axes=None, show=True, figsize=None, **kwargs):

pyschism/mesh/friction/fgrid.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
from pyschism.mesh import grd
2-
from pyschism.mesh.gmesh import Gmesh
2+
from pyschism.mesh.base import EuclideanMesh2D
33

44

5-
class Fgrid(Gmesh):
5+
class Fgrid(EuclideanMesh2D):
66
"""
77
Base class for all friction types (e.g. manning.grd, drag.grd, etc...)
88
"""
99
def __init__(
1010
self,
1111
nodes,
1212
elements,
13-
boundaries=None,
1413
crs=None,
1514
description=None,
1615
):
17-
super().__init__(**grd.to_gmesh({
16+
msh = grd.euclidean_mesh({
1817
'nodes': nodes,
1918
'elements': elements,
2019
'description': description,
21-
'boundaries': boundaries}),
22-
crs=crs)
20+
'crs': crs})
21+
msh.update({"crs": crs})
22+
super().__init__(**msh)
2323

2424
@staticmethod
2525
def open(path, crs=None):
26-
return Fgrid(**grd.reader(path), crs=crs)
26+
msh = grd.reader(path)
27+
msh.update({"crs": crs})
28+
return Fgrid(**msh)

pyschism/mesh/gmesh.py

-233
This file was deleted.

0 commit comments

Comments
 (0)