Skip to content

Commit

Permalink
consolidate example data, mark tests, remove pytest-cases
Browse files Browse the repository at this point in the history
* consolidate test005_advgw_tidal data dir
* remove unused mf2k_test dir
* update .gitignore
* rename lak1b_bath.txt -> l1b2k_bath.txt
* update l1b2k_bath.nam
* remove unused mppth/mpend files
* mark tests requiring geopandas
* remove pytest-cases from testing dependencies
* refactor mp6 tests without pytest-cases
* refactor grid tests without pytest-cases
  • Loading branch information
wpbonelli committed Feb 1, 2024
1 parent 92853a9 commit 657581a
Show file tree
Hide file tree
Showing 32 changed files with 367 additions and 16,089 deletions.
1 change: 0 additions & 1 deletion .docs/Notebooks/mf6_complex_model_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"examples",
"data",
"mf6",
"create_tests",
"test005_advgw_tidal",
)
assert os.path.isdir(data_pth)
Expand Down
1 change: 1 addition & 0 deletions .docs/Notebooks/mf_error_tutorial01.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

try:
import pandas as pd

summary_pth = os.path.join(workspace, "checksummary.csv")
df = pd.read_csv(summary_pth)
except:
Expand Down
7 changes: 1 addition & 6 deletions .docs/Notebooks/mf_watertable_recharge_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ def analytical_water_table_solution(h1, h2, z, R, K, L, x):
# x -= dx
b1 = h1 - z
b2 = h2 - z
h = (
np.sqrt(
b1**2 - (x / L) * (b1**2 - b2**2) + (R * x / K) * (L - x)
)
+ z
)
h = np.sqrt(b1**2 - (x / L) * (b1**2 - b2**2) + (R * x / K) * (L - x)) + z
return h


Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@ venv
app

# IDE files
.vscode
.vscode

# mac files
**.DS_Store
2 changes: 1 addition & 1 deletion autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path):
# init paths
test_ex_name = "test005_advgw_tidal"
model_name = "AdvGW_tidal"
pth = example_data_path / "mf6" / "create_tests" / test_ex_name
pth = example_data_path / "mf6" / test_ex_name
expected_output_folder = pth / "expected_output"
expected_head_file = expected_output_folder / "AdvGW_tidal.hds"

Expand Down
1 change: 0 additions & 1 deletion autotest/test_binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def test_get_headfile_precision(example_data_path):
precision = get_headfile_precision(
example_data_path
/ "mf6"
/ "create_tests"
/ "test005_advgw_tidal"
/ "expected_output"
/ "AdvGW_tidal.hds"
Expand Down
1 change: 1 addition & 0 deletions autotest/test_copy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test copying of flopy objects.
"""

import copy
import inspect

Expand Down
6 changes: 3 additions & 3 deletions autotest/test_geospatial_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def test_polygon_collection(polygon, poly_w_hole, multipolygon):
assert is_equal, "GeoSpatialCollection Polygon conversion error"


@requires_pkg("shapely", "geojson")
@requires_pkg("shapely", "geojson", "geopandas")
def test_point_collection(point, multipoint):
col = [Shape.from_geojson(point), Shape.from_geojson(multipoint)]

Expand Down Expand Up @@ -427,7 +427,7 @@ def test_point_collection(point, multipoint):
)


@requires_pkg("shapely", "geojson")
@requires_pkg("shapely", "geojson", "geopandas")
def test_linestring_collection(linestring, multilinestring):
col = [Shape.from_geojson(linestring), Shape.from_geojson(multilinestring)]

Expand Down Expand Up @@ -457,7 +457,7 @@ def test_linestring_collection(linestring, multilinestring):
)


@requires_pkg("shapely", "geojson")
@requires_pkg("shapely", "geojson", "geopandas")
def test_mixed_collection(
polygon,
poly_w_hole,
Expand Down
9 changes: 6 additions & 3 deletions autotest/test_get_modflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test get-modflow utility."""

import os
import platform
import sys
Expand All @@ -20,9 +21,11 @@
flopy_dir = get_project_root_path()
get_modflow_script = flopy_dir / "flopy" / "utils" / "get_modflow.py"
bindir_options = {
"flopy": Path(expandvars(r"%LOCALAPPDATA%\flopy")) / "bin"
if system() == "Windows"
else Path.home() / ".local" / "share" / "flopy" / "bin",
"flopy": (
Path(expandvars(r"%LOCALAPPDATA%\flopy")) / "bin"
if system() == "Windows"
else Path.home() / ".local" / "share" / "flopy" / "bin"
),
"python": Path(sys.prefix)
/ ("Scripts" if system() == "Windows" else "bin"),
"home": Path.home() / ".local" / "bin",
Expand Down
49 changes: 32 additions & 17 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from contextlib import nullcontext
from warnings import warn

import geopandas
import matplotlib
import numpy as np
import pytest
Expand All @@ -14,11 +13,11 @@
from matplotlib import pyplot as plt
from modflow_devtools.markers import requires_exe, requires_pkg
from modflow_devtools.misc import has_pkg
from pytest_cases import parametrize_with_cases

from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid
from flopy.mf6 import MFSimulation
from flopy.modflow import Modflow, ModflowDis
from flopy.utils import import_optional_dependency
from flopy.utils.crs import get_authority_crs
from flopy.utils.cvfdutil import gridlist_to_disv_gridprops, to_cvfd
from flopy.utils.triangle import Triangle
Expand Down Expand Up @@ -1090,7 +1089,17 @@ def test_voronoi_vertex_grid(function_tmpdir):
@flaky
@requires_exe("triangle")
@requires_pkg("shapely", "scipy")
@parametrize_with_cases("grid_info", cases=GridCases, prefix="voronoi")
@pytest.mark.parametrize(
"grid_info",
[
GridCases.voronoi_polygon(),
GridCases.voronoi_rectangle(),
GridCases.voronoi_circle(),
GridCases.voronoi_nested_circles(),
GridCases.voronoi_polygons(),
GridCases.voronoi_many_polygons(),
],
)
def test_voronoi_grid(request, function_tmpdir, grid_info):
name = (
request.node.name.replace("/", "_")
Expand Down Expand Up @@ -1239,13 +1248,11 @@ def test_unstructured_neighbors(unstructured_grid):
queen_neighbors = unstructured_grid.neighbors(
5, method="queen", reset=True
)
assert np.allclose(
queen_neighbors, [0, 10, 1, 6, 11, 2, 3, 7, 8, 12, 13]
)
assert np.allclose(queen_neighbors, [0, 10, 1, 6, 11, 2, 3, 7, 8, 12, 13])


@parametrize_with_cases("grid", cases=GridCases, prefix="structured_cbd")
def test_structured_ncb_thickness(grid):
def test_structured_ncb_thickness():
grid = GridCases.structured_cbd_small()
thickness = grid.cell_thickness

assert thickness.shape[0] == grid.nlay + np.count_nonzero(
Expand All @@ -1267,29 +1274,40 @@ def test_structured_ncb_thickness(grid):
), "saturated_thickness is not properly indexing confining beds"


@parametrize_with_cases("grid", cases=GridCases, prefix="unstructured")
@pytest.mark.parametrize(
"grid", [GridCases.unstructured_small(), GridCases.unstructured_medium()]
)
def test_unstructured_iverts(grid):
iverts = grid.iverts
assert not any(
None in l for l in iverts
), "None type should not be returned in iverts list"


@parametrize_with_cases("grid", cases=GridCases, prefix="structured")
@pytest.mark.parametrize(
"grid", [GridCases.structured_small(), GridCases.structured_cbd_small()]
)
def test_get_lni_structured(grid):
for nn in range(0, grid.nnodes):
layer, i = grid.get_lni([nn])[0]
assert layer * grid.ncpl + i == nn


@parametrize_with_cases("grid", cases=GridCases, prefix="vertex")
@pytest.mark.parametrize(
"grid",
[
GridCases.vertex_small(),
],
)
def test_get_lni_vertex(grid):
for nn in range(0, grid.nnodes):
layer, i = grid.get_lni([nn])[0]
assert layer * grid.ncpl + i == nn


@parametrize_with_cases("grid", cases=GridCases, prefix="unstructured")
@pytest.mark.parametrize(
"grid", [GridCases.unstructured_small(), GridCases.unstructured_medium()]
)
def test_get_lni_unstructured(grid):
for nn in range(0, grid.nnodes):
layer, i = grid.get_lni([nn])[0]
Expand Down Expand Up @@ -1344,11 +1362,8 @@ def test_unstructured_convert(unstructured_grid):

@requires_pkg("geopandas")
def test_geo_dataframe(structured_grid, vertex_grid, unstructured_grid):
grids = (
structured_grid,
vertex_grid,
unstructured_grid
)
geopandas = import_optional_dependency("geopandas")
grids = (structured_grid, vertex_grid, unstructured_grid)

for grid in grids:
gdf = grid.geo_dataframe
Expand Down
Loading

0 comments on commit 657581a

Please sign in to comment.