diff --git a/tests/test_boundary.py b/tests/test_boundary.py index 3085f04c..e5ad0864 100644 --- a/tests/test_boundary.py +++ b/tests/test_boundary.py @@ -1,29 +1,23 @@ import pyposeidon.boundary as pb import pytest import geopandas as gp -import cartopy.feature as cf from . import DATA_DIR noaa = DATA_DIR / "bl.zip" -land = cf.NaturalEarthFeature(category="physical", name="land", scale="50m") -nland = gp.GeoDataFrame(geometry=[x for x in land.geometries()]) +COAST_FILE = (DATA_DIR / "ocean.zip").as_posix() -coast = cf.NaturalEarthFeature(category="physical", name="coastline", scale="50m") -ncoast = gp.GeoDataFrame(geometry=[x for x in coast.geometries()]) +land = gp.read_file(COAST_FILE).drop("FID", axis=1) +coast = gp.GeoDataFrame(geometry=land.boundary) -# gh = cf.GSHHSFeature(scale="intermediate", levels=[1]) -# iGSHHS = gp.GeoDataFrame(geometry=[x for x in gh.geometries()]) - - -INPUTS = pytest.mark.parametrize("input", [nland, ncoast]) # , iGSHHS]) +INPUTS = pytest.mark.parametrize("input", [land, coast]) CUSTOM = pytest.mark.parametrize("boundary", [noaa]) WINDOWS = pytest.mark.parametrize( "window", [ {"lon_min": -30, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 70.0}, - {"lon_min": 175.0, "lon_max": 184.0, "lat_min": 14.5, "lat_max": 16.5}, + {"lon_min": 175.0, "lon_max": 184.0, "lat_min": -50, "lat_max": -30}, ], ) DEM_SOURCES = pytest.mark.parametrize( @@ -61,21 +55,21 @@ def test_buffer(tmpdir, window, input): assert isinstance(df.contours, gp.GeoDataFrame) -#@INPUTS -#@WINDOWS -#@DEM_SOURCES -#def test_isodem(tmpdir, window, input, dem_source): +# @INPUTS +# @WINDOWS +# @DEM_SOURCES +# def test_isodem(tmpdir, window, input, dem_source): # df = pb.Boundary(geometry=window, dem_source=dem_source, blevels=[-100], rpath=str(tmpdir) + "/") # assert isinstance(df.contours, gp.GeoDataFrame) -@pytest.mark.slow -def test_isodem_with_url(tmpdir): - input = nland - window = {"lon_min": 176.5, "lon_max": 177.0, "lat_min": 16.0, "lat_max": 16.5} - dem_source = "https://coastwatch.pfeg.noaa.gov/erddap/griddap/srtm30plus" - df = pb.Boundary(geometry=window, dem_source=dem_source, blevels=[-100], rpath=str(tmpdir) + "/") - assert isinstance(df.contours, gp.GeoDataFrame) +# @pytest.mark.slow +# def test_isodem_with_url(tmpdir): +# input = nland +# window = {"lon_min": 176.5, "lon_max": 177.0, "lat_min": 16.0, "lat_max": 16.5} +# dem_source = "https://coastwatch.pfeg.noaa.gov/erddap/griddap/srtm30plus" +# df = pb.Boundary(geometry=window, dem_source=dem_source, blevels=[-100], rpath=str(tmpdir) + "/") +# assert isinstance(df.contours, gp.GeoDataFrame) @CUSTOM diff --git a/tests/test_dem_fix.py b/tests/test_dem_fix.py index d1f20ae7..18cff7b7 100644 --- a/tests/test_dem_fix.py +++ b/tests/test_dem_fix.py @@ -3,10 +3,11 @@ import pytest import numpy as np import geopandas as gp -import cartopy.feature as cf from . import DATA_DIR +COAST_FILE = (DATA_DIR / "ocean.zip").as_posix() + DEM_SOURCES = pytest.mark.parametrize( "dem_source", [ @@ -19,26 +20,25 @@ "window", [ {"lon_min": -30, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 70.0}, - {"lon_min": 175.0, "lon_max": 185.0, "lat_min": -21.5, "lat_max": -14.5}, - {"lon_min": -185.0, "lon_max": -175.0, "lat_min": -21.5, "lat_max": -14.5}, + {"lon_min": 165.0, "lon_max": 185.0, "lat_min": -50, "lat_max": -30}, + {"lon_min": -185.0, "lon_max": -165.0, "lat_min": -50, "lat_max": -30}, {"lon_min": -3, "lon_max": 1.0, "lat_min": 42.0, "lat_max": 45.0}, ], ) @pytest.fixture(scope="session") -def natural_earth(): - coast = cf.NaturalEarthFeature(category="physical", name="land", scale="110m") - gdf = gp.GeoDataFrame(geometry=[x.buffer(0.001) for x in coast.geometries()]) - return gdf +def coasts(): + coast = gp.read_file(COAST_FILE).drop("FID", axis=1) + return coast @DEM_SOURCES @WINDOWS -def test_dem_adjust(natural_earth, dem_source, window): +def test_dem_adjust(coasts, dem_source, window): # Just elevation df = pdem.Dem(**window, dem_source=dem_source) # get dem - df.adjust(natural_earth) + df.adjust(coasts) assert np.isnan(df.Dataset.adjusted.values).sum() == 0 @@ -46,11 +46,11 @@ def test_dem_adjust(natural_earth, dem_source, window): @pytest.mark.schism @DEM_SOURCES @WINDOWS -def test_schism_mesh(tmpdir, natural_earth, dem_source, window): +def test_schism_mesh(tmpdir, coasts, dem_source, window): mesh = pmesh.set( type="tri2d", geometry=window, - coastlines=natural_earth, + coastlines=coasts, mesh_generator="jigsaw", rpath=str(tmpdir) + "/", ) @@ -58,7 +58,7 @@ def test_schism_mesh(tmpdir, natural_earth, dem_source, window): yg = mesh.Dataset.SCHISM_hgrid_node_y.values dem = pdem.Dem(**window, dem_source=dem_source, adjust_dem=False) # get dem dem.Dataset = pdem.dem_on_mesh(dem.Dataset, grid_x=xg, grid_y=yg) # get dem on mesh - dem.adjust(natural_earth) + dem.adjust(coasts) assert np.isnan(dem.Dataset.fval.values).sum() == 0 @@ -66,11 +66,11 @@ def test_schism_mesh(tmpdir, natural_earth, dem_source, window): @pytest.mark.delft @DEM_SOURCES @WINDOWS -def test_d3d_mesh(tmpdir, natural_earth, dem_source, window): +def test_d3d_mesh(tmpdir, coasts, dem_source, window): mesh = pmesh.set(type="r2d", geometry=window, resolution=0.1, rpath=str(tmpdir) + "/") gr = mesh.Dataset xp, yp = gr.lons.values, gr.lats.values dem = pdem.Dem(**window, dem_source=dem_source, adjust_dem=False) # get dem dem.Dataset = pdem.dem_on_mesh(dem.Dataset, grid_x=xp, grid_y=yp) # get dem on mesh - dem.adjust(natural_earth) + dem.adjust(coasts) assert np.isnan(dem.Dataset.fval.values).sum() == 0 diff --git a/tests/test_grid.py b/tests/test_grid.py index 249e5d3a..dae4945e 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -2,56 +2,30 @@ import numpy as np import pytest import os -import geopandas as gp -import cartopy.feature as cf +from . import DATA_DIR -cr = "i" -coast = cf.NaturalEarthFeature( - category="physical", - name="land", - scale="{}m".format({"l": 110, "i": 50, "h": 10}[cr]), -) - - -natural_earth = gp.GeoDataFrame(geometry=[x for x in coast.geometries()]) - -coast = cf.GSHHSFeature(scale="auto", levels=[1]) - -GSHHS = gp.GeoDataFrame(geometry=[x for x in coast.geometries()]) - +COAST_FILE = (DATA_DIR / "ocean.zip").as_posix() -# define the lat/lon window and time frame of interest -window0 = {"lon_min": -30, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 70.0} - -window1 = { - "lon_min": 175.0, - "lon_max": 184.0, - "lat_min": -21.5, - "lat_max": -14.5, -} # lat/lon window - -window2 = {"lon_min": -20.0, "lon_max": -10.0, "lat_min": 63.0, "lat_max": 67.0} - -window3 = { - "lon_min": 175.0 - 360.0, - "lon_max": 184.0 - 360.0, - "lat_min": -21.5, - "lat_max": -14.5, -} # lat/lon window - -window4 = {"lon_min": -25.0, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 68.0} +WINDOWS = pytest.mark.parametrize( + "window", + [ + {"lon_min": -30, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 70.0}, + {"lon_min": 165.0, "lon_max": 185.0, "lat_min": -50, "lat_max": -30}, + {"lon_min": -185.0, "lon_max": -165.0, "lat_min": -50, "lat_max": -30}, + {"lon_min": -25.0, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 68.0}, + ], +) -@pytest.mark.parametrize("window", [window0, window1, window2, window3, window4]) -@pytest.mark.parametrize("coast", [natural_earth, GSHHS]) +@WINDOWS @pytest.mark.parametrize("ggor", ["jigsaw", "gmsh"]) -def test_answer(tmpdir, window, coast, ggor): +def test_answer(tmpdir, window, ggor): mesh = pmesh.set( type="tri2d", geometry=window, - coastlines=coast, + coastlines=COAST_FILE, rpath=str(tmpdir) + "/", mesh_generator=ggor, ) diff --git a/tests/test_grid_global.py b/tests/test_grid_global.py index f147043c..510ee8e4 100644 --- a/tests/test_grid_global.py +++ b/tests/test_grid_global.py @@ -3,7 +3,6 @@ import pytest import os import geopandas as gp -import cartopy.feature as cf from . import DATA_DIR @@ -21,6 +20,11 @@ def test_io(pytestconfig, tmpdir, ggor, bgmesh, bindings): if not pytestconfig.getoption("--runslow"): pytest.skip("slow test") + if ggor == "jigsaw": + cb = 0.001 + else: + cb = None + mesh = pmesh.set( type="tri2d", geometry="global", @@ -29,6 +33,7 @@ def test_io(pytestconfig, tmpdir, ggor, bgmesh, bindings): mesh_generator=ggor, dem_source=bgmesh, use_bindings=bindings, + cbuffer=cb, ) # save to file @@ -63,6 +68,11 @@ def test_validate(pytestconfig, tmpdir, ggor, bgmesh, bindings): if not pytestconfig.getoption("--runslow"): pytest.skip("slow test") + if ggor == "jigsaw": + cb = 0.001 + else: + cb = None + mesh = pmesh.set( type="tri2d", geometry="global", @@ -71,6 +81,7 @@ def test_validate(pytestconfig, tmpdir, ggor, bgmesh, bindings): mesh_generator=ggor, dem_source=bgmesh, use_bindings=bindings, + cbuffer=cb, ) rpath = str(tmpdir) + "/" diff --git a/tests/test_schism_total.py b/tests/test_schism_total.py index de419a8e..48c10520 100644 --- a/tests/test_schism_total.py +++ b/tests/test_schism_total.py @@ -3,23 +3,19 @@ import os import multiprocessing import geopandas as gp -import cartopy.feature as cf from . import DATA_DIR DEM_FILE = DATA_DIR / "dem.nc" -coast = cf.GSHHSFeature(scale="auto", levels=[1]) - -GSHHS = gp.GeoDataFrame(geometry=[x for x in coast.geometries()]) - +COAST_FILE = (DATA_DIR / "ocean.zip").as_posix() WINDOWS = pytest.mark.parametrize( "window", [ {"lon_min": -30, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 70.0}, - {"lon_min": 175.0, "lon_max": 185.0, "lat_min": -21.5, "lat_max": -14.5}, - {"lon_min": -185.0, "lon_max": -175.0, "lat_min": -21.5, "lat_max": -14.5}, + {"lon_min": 165.0, "lon_max": 185.0, "lat_min": -50, "lat_max": -30}, + {"lon_min": -185.0, "lon_max": -165.0, "lat_min": -50, "lat_max": -30}, {"lon_min": -25.0, "lon_max": -10.0, "lat_min": 60.0, "lat_max": 68.0}, ], ) @@ -32,13 +28,13 @@ def test_schism(tmpdir, window): dic = { "solver_name": "schism", "geometry": window, - "coastlines": GSHHS, + "coastlines": COAST_FILE, "manning": 0.12, "windrot": 0.00001, "tag": "test", "start_date": "2017-10-1 0:0:0", "time_frame": "12H", - "mesh_generator": "jigsaw", + "mesh_generator": "gmsh", "meteo_source": [DATA_DIR / "erai.grib"], # meteo file "dem_source": DEM_FILE, "update": ["all"], # update only meteo, keep dem