Skip to content

Commit

Permalink
feat(PRT): add utilities to configure/plot PRT models
Browse files Browse the repository at this point in the history
* to_coords() and to_prt() methods on particle data classes
* to_mp7_[pathlines/endpoints]() dtype conversion functions
* support plotting PRT pathlines in map/cross-section plots
  • Loading branch information
wpbonelli committed Sep 6, 2023
1 parent 4f6cd47 commit 2b24104
Show file tree
Hide file tree
Showing 23 changed files with 2,601 additions and 893 deletions.
48 changes: 35 additions & 13 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,28 @@ jobs:
run: |
pip install --upgrade pip
pip install .
pip install ".[test,optional]"
- name: Install Modflow executables
pip install ".[test, optional]"
- name: Install executables
uses: modflowpy/install-modflow-action@v1

- name: Smoke test
working-directory: autotest
run: pytest -v -n=auto --smoke --cov=flopy --cov-report=xml --durations=0 --keep-failed=.failed

# todo restore below before merging
- name: Install MODFLOW 6 PRT build
uses: modflowpy/install-modflow-action@v1
with:
# repo: modflow6-nightly-build
owner: aprovost-usgs
repo: modflow6

- name: Update FloPy packages
if: runner.os != 'Windows'
# run: python -c 'import flopy; flopy.mf6.utils.generate_classes(ref="develop", backup=False)'
run: python -c 'import flopy; flopy.mf6.utils.generate_classes(owner="aprovost-usgs", ref="PRT", backup=False)'

- name: Run smoke tests
working-directory: ./autotest
run: |
pytest -v -n=auto --smoke --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -150,7 +164,10 @@ jobs:

test:
name: Test
needs: smoke
needs:
- build
- lint
- smoke
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -205,22 +222,27 @@ jobs:
pip install xmipy
pip install .
- name: Install Modflow-related executables
- name: Install executables
uses: modflowpy/install-modflow-action@v1

- name: Install Modflow dev build executables
# todo restore below when prt merges to mf6 develop
- name: Install MODFLOW 6 PRT build
uses: modflowpy/install-modflow-action@v1
with:
repo: modflow6-nightly-build
# repo: modflow6-nightly-build
owner: aprovost-usgs
repo: modflow6

- name: Update FloPy packages
if: runner.os != 'Windows'
run: python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
# run: python -c 'import flopy; flopy.mf6.utils.generate_classes(ref="develop", backup=False)'
run: python -c 'import flopy; flopy.mf6.utils.generate_classes(owner="aprovost-usgs", ref="PRT", backup=False)'

- name: Update FloPy packages
if: runner.os == 'Windows'
shell: bash -l {0}
run: python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
# run: python -c 'import flopy; flopy.mf6.utils.generate_classes(ref="develop", backup=False)'
run: python -c 'import flopy; flopy.mf6.utils.generate_classes(owner="aprovost-usgs", ref="PRT", backup=False)'

- name: Run tests
if: runner.os != 'Windows'
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
bash
powershell
- name: Install extra Python dependencies
- name: Install Python dependencies
if: runner.os == 'Windows'
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -96,17 +96,15 @@ jobs:
- name: Run example tests
if: runner.os != 'Windows'
working-directory: ./autotest
run: |
pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
run: pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run example tests
if: runner.os == 'Windows'
shell: bash -l {0}
working-directory: ./autotest
run: |
pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
run: pytest -v -m="example" -n=auto -s --durations=0 --keep-failed=.failed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
31 changes: 12 additions & 19 deletions .github/workflows/mf6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
pip install https://github.com/modflowpy/pymake/zipball/master
pip install https://github.com/Deltares/xmipy/zipball/develop
pip install https://github.com/MODFLOW-USGS/modflowapi/zipball/develop
pip install .
pip install .[test,optional]
- name: Install gfortran
Expand All @@ -50,53 +51,45 @@ jobs:
- name: Checkout MODFLOW 6
uses: actions/checkout@v3
with:
repository: MODFLOW-USGS/modflow6
repository: aprovost-usgs/modflow6
path: modflow6
ref: PRT

- name: Update flopy MODFLOW 6 classes
working-directory: modflow6/autotest
run: |
python update_flopy.py
run: python update_flopy.py

- name: Install meson
run: |
pip3 install meson ninja
run: pip3 install meson ninja

- name: Setup modflow
working-directory: modflow6
run: |
meson setup builddir --buildtype=debugoptimized --prefix=$(pwd) --libdir=bin
run: meson setup builddir --buildtype=debugoptimized --prefix=$(pwd) --libdir=bin

- name: Build modflow
working-directory: modflow6
run: |
meson compile -C builddir
run: meson compile -C builddir

- name: Install modflow
working-directory: modflow6
run: |
meson install -C builddir
run: meson install -C builddir

- name: Get executables
working-directory: modflow6/autotest
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
pytest -v --durations=0 get_exes.py
run: pytest -v --durations=0 get_exes.py

- name: Run tests
working-directory: modflow6/autotest
run: |
pytest -v -n auto -k "test_gw" --durations=0 --cov=flopy --cov-report=xml
run: pytest -v -n auto -k "test_gw" --durations=0 --cov=flopy --cov-report=xml

- name: Print coverage report before upload
working-directory: ./modflow6/autotest
run: |
coverage report
run: coverage report

- name: Upload coverage to Codecov
if:
github.repository_owner == 'modflowpy' && (github.event_name == 'push' || github.event_name == 'pull_request')
if: github.repository_owner == 'modflowpy' && (github.event_name == 'push' || github.event_name == 'pull_request')
uses: codecov/codecov-action@v3
with:
files: ./modflow6/autotest/coverage.xml
16 changes: 15 additions & 1 deletion .github/workflows/rtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
run: python -m pip install --upgrade pip

- name: Install flopy and dependencies
run: pip install ".[test, doc, optional]"
run: |
pip install .
pip install ".[test, doc, optional]"
- name: Workaround OpenGL issue on Linux
if: runner.os == 'Linux'
Expand Down Expand Up @@ -77,6 +79,18 @@ jobs:
- name: Install MODFLOW executables
uses: modflowpy/install-modflow-action@v1

# todo restore below before merging
- name: Install MODFLOW 6 PRT build
uses: modflowpy/install-modflow-action@v1
with:
owner: aprovost-usgs
repo: modflow6

- name: Update FloPy
run: |
python -c 'from flopy.mf6.utils import generate_classes; generate_classes(owner="aprovost-usgs", ref="PRT", backup=False)'
pip install .
- name: Run tutorial and example notebooks
working-directory: autotest
run: pytest -v -n auto test_notebooks.py
Expand Down
2 changes: 1 addition & 1 deletion autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3085,7 +3085,7 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path):
delc=5000.0,
top=top,
botm=botm,
#idomain=idomain,
# idomain=idomain,
filename=f"{model_name}.dis",
)
strt = testutils.read_std_array(os.path.join(pth, "strt.txt"), "float")
Expand Down
1 change: 1 addition & 0 deletions autotest/test_binaryfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import List

import numpy as np
import pytest
Expand Down
99 changes: 99 additions & 0 deletions autotest/test_cross_section_line_representations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import numpy as np
import pytest
from modflow_devtools.markers import requires_pkg

import flopy


def structured_square_grid(side: int = 10, thick: int = 10):
"""
Creates a basic 1-layer structured grid with the given thickness and number of cells per side
Parameters
----------
side : The number of cells per side
thick : The thickness of the grid's single layer
Returns
-------
A single-layer StructuredGrid of the given size and thickness
"""

from flopy.discretization.structuredgrid import StructuredGrid

delr = np.ones(side)
delc = np.ones(side)
top = np.ones((side, side)) * thick
botm = np.ones((side, side)) * (top - thick).reshape(1, side, side)
return StructuredGrid(delr=delr, delc=delc, top=top, botm=botm)


@requires_pkg("shapely")
@pytest.mark.parametrize(
"line",
[(), [], (()), [[]], (0, 0), [0, 0], [[0, 0]]],
)
def test_cross_section_invalid_lines_raise_error(line):
grid = structured_square_grid(side=10)
with pytest.raises(ValueError):
flopy.plot.PlotCrossSection(modelgrid=grid, line={"line": line})


@requires_pkg("shapely")
@pytest.mark.parametrize(
"line",
[
# diagonal
[(0, 0), (10, 10)],
([0, 0], [10, 10]),
# horizontal
([0, 5.5], [10, 5.5]),
[(0, 5.5), (10, 5.5)],
# vertical
[(5.5, 0), (5.5, 10)],
([5.5, 0], [5.5, 10]),
# multiple segments
[(0, 0), (4, 6), (10, 10)],
([0, 0], [4, 6], [10, 10]),
],
)
def test_cross_section_valid_line_representations(line):
from shapely.geometry import LineString as SLS

from flopy.utils.geometry import LineString as FLS

grid = structured_square_grid(side=10)

fls = FLS(line)
sls = SLS(line)

# use raw, flopy.utils.geometry and shapely.geometry representations
lxc = flopy.plot.PlotCrossSection(modelgrid=grid, line={"line": line})
fxc = flopy.plot.PlotCrossSection(modelgrid=grid, line={"line": fls})
sxc = flopy.plot.PlotCrossSection(modelgrid=grid, line={"line": sls})

# make sure parsed points are identical for all line representations
assert np.allclose(lxc.pts, fxc.pts) and np.allclose(lxc.pts, sxc.pts)
assert (
set(lxc.xypts.keys()) == set(fxc.xypts.keys()) == set(sxc.xypts.keys())
)
for k in lxc.xypts.keys():
assert np.allclose(lxc.xypts[k], fxc.xypts[k]) and np.allclose(
lxc.xypts[k], sxc.xypts[k]
)


@pytest.mark.parametrize(
"line",
[
0,
[0],
[0, 0],
(0, 0),
[(0, 0)],
([0, 0]),
],
)
@requires_pkg("shapely", "geojson")
def test_cross_section_invalid_line_representations_fail(line):
grid = structured_square_grid(side=10)
with pytest.raises(ValueError):
flopy.plot.PlotCrossSection(modelgrid=grid, line={"line": line})
1 change: 0 additions & 1 deletion autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
from flopy.utils.crs import get_authority_crs
from flopy.utils.geometry import Polygon


HAS_PYPROJ = has_pkg("pyproj", strict=True)
if HAS_PYPROJ:
import pyproj
Expand Down
Loading

0 comments on commit 2b24104

Please sign in to comment.