Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Jan 16, 2020
1 parent e9093b1 commit 292ebf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 16 additions & 3 deletions pyschism/mesh/gr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from pyschism.mesh.gmesh import Gmesh
from functools import lru_cache
from collections import defaultdict
from collections import defaultdict, namedtuple


def writer(grd, path, overwrite=False):
Expand Down Expand Up @@ -142,7 +142,12 @@ def to_mesh(nodes, elements):
quads = {id: geom for id, geom in elements.items()
if len(geom) == 4}
values = [value for coord, value in nodes.values()]
return coords, triangles, quads, values
msh = namedtuple("msh", ["coords", "triangles", "quads", "values"])
return msh(
coords=coords,
triangles=triangles,
quads=quads,
values=values)


class Gr3(Gmesh):
Expand All @@ -154,7 +159,15 @@ def __init__(
crs=None,
description=None,
):
super().__init__(*to_mesh(nodes, elements), crs, description)
msh = to_mesh(nodes, elements)
super().__init__(
msh.coords,
msh.triangles,
msh.quads,
msh.values,
crs,
description
)

@classmethod
def open(cls, gr3, crs=None):
Expand Down
10 changes: 9 additions & 1 deletion tests/mesh/test_gr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
import pathlib
import tempfile
from pyschism.mesh.gr3 import reader, writer
from pyschism.mesh.gr3 import reader, writer, Gr3


class Gr3TestCase(unittest.TestCase):
Expand Down Expand Up @@ -71,6 +71,14 @@ def test_overwrite(self):
pathlib.Path(tmpdir.name) / 'hgrid.gr3'
)

def test_Gr3_description_override(self):
self.grd.pop('boundaries')
self.grd.update({"crs": 3395})
self.assertEqual(
Gr3(**self.grd).grd['description'],
"gr3_unittest CRS: epsg:3395"
)


if __name__ == '__main__':
unittest.main()
8 changes: 7 additions & 1 deletion tests/mesh/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import tempfile
import pathlib
from pyschism.mesh.friction import Fgrid
from pyschism.mesh import Mesh
from pyschism.mesh import Mesh, Vgrid
from unittest.mock import patch
import unittest


Expand Down Expand Up @@ -115,3 +116,8 @@ def test_make_plot(self):
def test_default_fgrid(self):
m = Mesh.open(self.hgrid)
assert isinstance(m.fgrid, Fgrid)

@patch.object(Vgrid, 'is3D', return_value=True)
def test_make_plot_3D(self, mock):
m = Mesh.open(self.hgrid)
self.assertRaises(NotImplementedError, m.make_plot)

0 comments on commit 292ebf4

Please sign in to comment.