Skip to content

Commit

Permalink
tests: make sure they pass
Browse files Browse the repository at this point in the history
  • Loading branch information
brey authored and pmav99 committed Aug 20, 2024
1 parent 2cafc87 commit 9859d25
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
21 changes: 11 additions & 10 deletions pyposeidon/mjigsaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ def read_msh(filename, **kwargs):

A, idxA = np.unique(nodes["tag"], return_inverse=True)
B, idxB = np.unique(tria["a"], return_inverse=True)
IDX = np.in1d(A, B)
IDX = np.isin(A, B)
tria["a"] = idxA[IDX][idxB]
B, idxB = np.unique(tria["b"], return_inverse=True)
IDX = np.in1d(A, B)
IDX = np.isin(A, B)
tria["b"] = idxA[IDX][idxB]
B, idxB = np.unique(tria["c"], return_inverse=True)
IDX = np.in1d(A, B)
IDX = np.isin(A, B)
tria["c"] = idxA[IDX][idxB]

# Drop invalid edges
Expand All @@ -258,10 +258,10 @@ def read_msh(filename, **kwargs):
### Re-index edges
A, idxA = np.unique(nodes["tag"], return_inverse=True)
B, idxB = np.unique(edges["e1"], return_inverse=True)
IDX = np.in1d(A, B)
IDX = np.isin(A, B)
edges["e1"] = idxA[IDX][idxB]
B, idxB = np.unique(edges["e2"], return_inverse=True)
IDX = np.in1d(A, B)
IDX = np.isin(A, B)
edges["e2"] = idxA[IDX][idxB]
# clean up
nodes = nodes.drop("tag", axis=1)
Expand Down Expand Up @@ -479,20 +479,21 @@ def get(contours, **kwargs):

hfun_scal = kwargs.get("hfun_scal", "ABSOLUTE")
hfun_min = kwargs.get("hfun_min", 0.0)
hfun_max = kwargs.get("hfun_max", 1000.0)
hfun_max = kwargs.get("hfun_max", 100.0)
mesh_eps1 = kwargs.get("mesh_eps1", 0.3)

with open(fjig, "w") as f:
f.write("GEOM_FILE ={}\n".format(tag + "-geo.msh"))
f.write("MESH_FILE ={}\n".format(tag + ".msh"))
if bgmesh:
f.write("HFUN_FILE ={}\n".format(tag + "-hfun.msh"))
f.write("HFUN_SCAL = {}\n".format(hfun_scal))
f.write("HFUN_HMAX = {}\n".format(hfun_max))
f.write("HFUN_HMIN = {}\n".format(hfun_min))
f.write(f"HFUN_SCAL = {hfun_scal}\n")
f.write(f"HFUN_HMAX = {hfun_max}\n")
f.write(f"HFUN_HMIN = {hfun_min}\n")
f.write("MESH_DIMS = 2\n")
f.write("MESH_TOP1 = TRUE\n")
# f.write('MESH_TOP2 = TRUE\n')
f.write("MESH_EPS1 = 1.0\n")
f.write(f"MESH_EPS1 = {mesh_eps1}\n")
f.write("MESH_RAD2 = 1\n")
f.write("GEOM_FEAT = TRUE\n")
f.write("VERBOSITY = 2")
Expand Down
3 changes: 1 addition & 2 deletions pyposeidon/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def setup_logging(
logger.addHandler(file_handler)


# TODO Handle master/develop version
def parse_schism_version(version_output: str) -> str:
if "schism develop" in version_output:
version = "develop"
Expand Down Expand Up @@ -530,7 +529,7 @@ def dequantize(
missing_value: int,
dtype: npt.DTypeLike,
) -> npt.NDArray[np.float_]:
array = bn.replace(array.astype(np.float_), missing_value, np.nan)
array = bn.replace(array.astype(np.float64), missing_value, np.nan)
dequantized = (array * scale_factor) + add_offset
return dequantized

Expand Down
6 changes: 3 additions & 3 deletions pyposeidon/utils/coastfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def simplify(geo):

if (geo.geom_type == "Polygon").all():
try:
geo_ = list(geo.buffer(0).unary_union.geoms)
geo_ = list(geo.buffer(0).union_all().geoms)
except TypeError:
geo_ = [geo.buffer(0).unary_union]
geo_ = [geo.buffer(0).union_all()]

geo = gp.GeoDataFrame(geometry=geo_)
geo = gp.GeoDataFrame(geometry=geo.buffer(0))
Expand All @@ -40,7 +40,7 @@ def simplify(geo):
for idx, geom in dg.iterrows():
pl = shapely.polygonize_full(dg.loc[[idx]].boundary.explode(index_parts=False).values)
df = gp.GeoDataFrame(geometry=[pl[0]]).explode(index_parts=False)
dff = gp.GeoDataFrame(geometry=[df.unary_union])
dff = gp.GeoDataFrame(geometry=[df.union_all()])
geo.loc[idx, "geometry"] = dff.geometry.buffer(0).values[0]

if geo.is_valid.all() and (geo.boundary.geom_type == "LineString").all():
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def save_as(url: str, path: pathlib.Path) -> None:


TEST_DATA = {
DATA_DIR / "ocean.zip": "https://www.dropbox.com/sh/cgyk6ychwimjlzr/AADlueXH1I1F01mlgerMUSb6a?dl=1",
DATA_DIR
/ "ocean.parquet": "https://www.dropbox.com/scl/fi/msiru06qdh7cq99lsxicx/ocean.parquet?rlkey=ku7afiues47y91a15hdvtcybu&st=nayi0hc2&dl=1",
DATA_DIR / "bl.zip": "https://www.dropbox.com/sh/9tfdl67sll1ax8c/AACntQeIavCzRfTZZ9Tp8uFda?dl=1",
DATA_DIR / "dem.nc": "https://www.dropbox.com/s/l16crheqc9d89gy/dem.nc?dl=1",
DATA_DIR / "dem.tif": "https://www.dropbox.com/s/dgdlnr2p5q66np7/dem.tif?dl=1",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

noaa = DATA_DIR / "bl.zip"

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()

land = gp.read_file(COAST_FILE).drop("FID", axis=1)
land = gp.read_file(COAST_FILE)
coast = gp.GeoDataFrame(geometry=land.boundary)

INPUTS = pytest.mark.parametrize("input", [land, coast])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dem_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from . import DATA_DIR

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()

DEM_SOURCES = pytest.mark.parametrize(
"dem_source",
Expand All @@ -29,7 +29,7 @@

@pytest.fixture(scope="session")
def coasts():
coast = gp.read_file(COAST_FILE).drop("FID", axis=1)
coast = gp.read_file(COAST_FILE)
return coast


Expand Down
4 changes: 2 additions & 2 deletions tests/test_dem_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from . import DATA_DIR

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()

DEM_SOURCES = pytest.mark.parametrize(
"dem_source",
Expand All @@ -18,7 +18,7 @@

@pytest.fixture(scope="session")
def coasts():
# coast = gp.read_file(COAST_FILE).drop("FID", axis=1)
# coast = gp.read_file(COAST_FILE)
cr = "h"
coast = cf.NaturalEarthFeature(
category="physical", name="land", scale="{}m".format({"l": 110, "i": 50, "h": 10}[cr])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from . import DATA_DIR

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()

WINDOWS = pytest.mark.parametrize(
"window",
Expand Down
9 changes: 6 additions & 3 deletions tests/test_mesh_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

DEM_FILE = (DATA_DIR / "dem.nc").as_posix()

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()


@pytest.mark.parametrize("ggor", ["jigsaw", "gmsh"])
@pytest.mark.parametrize("bgmesh", [None, DEM_FILE])
@pytest.mark.parametrize("bindings", [True, False])
@pytest.mark.parametrize("cbuffer", [None, 0.001])
@pytest.mark.parametrize("cbuffer", [None, 0.01])
def test_io(pytestconfig, tmpdir, ggor, bgmesh, bindings, cbuffer):
# Skip the test unless --runslow has been passed
if bgmesh is not None:
Expand Down Expand Up @@ -61,14 +61,17 @@ def test_io(pytestconfig, tmpdir, ggor, bgmesh, bindings, cbuffer):
@pytest.mark.parametrize("ggor", ["jigsaw", "gmsh"])
@pytest.mark.parametrize("bgmesh", [None, DEM_FILE])
@pytest.mark.parametrize("bindings", [True, False])
@pytest.mark.parametrize("cbuffer", [None, 0.001])
@pytest.mark.parametrize("cbuffer", [None, 0.01])
def test_validate(pytestconfig, tmpdir, ggor, cbuffer, bgmesh, bindings):
if bgmesh is not None:
if not pytestconfig.getoption("--runslow"):
pytest.skip("slow test")
if ggor == "jigsaw":
pytest.xfail("Fixing these is a WIP")

# if ggor == "jigsaw":
# pytest.xfail("Fixing these is a WIP")

mesh = pmesh.set(
type="tri2d",
geometry="global",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schism_total.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

DEM_FILE = DATA_DIR / "dem.nc"

COAST_FILE = (DATA_DIR / "ocean.zip").as_posix()
COAST_FILE = (DATA_DIR / "ocean.parquet").as_posix()

WINDOWS = pytest.mark.parametrize(
"window",
Expand Down

0 comments on commit 9859d25

Please sign in to comment.