Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

# add flopy root directory to the python path
sys.path.insert(0, os.path.abspath(".."))
from flopy import __version__, __author__
from flopy import __author__, __version__

# -- determine if running on readthedocs ------------------------------------
on_rtd = os.environ.get('READTHEDOCS') == 'True'
on_rtd = os.environ.get("READTHEDOCS") == "True"

# -- determine if this version is a release candidate
with open("../README.md", "r") as f:
Expand Down
7 changes: 5 additions & 2 deletions .docs/create_rstfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def create_tutorial_rst():
tutorial_dict = {}
for dirpath, _, filenames in os.walk(pth):
key = os.path.basename(os.path.normpath(dirpath))
files = [filename.replace(".py", "") for filename in sorted(filenames)
if filename.endswith(".py")]
files = [
filename.replace(".py", "")
for filename in sorted(filenames)
if filename.endswith(".py")
]
if len(files) > 0:
tutorial_dict[key] = files

Expand Down
17 changes: 11 additions & 6 deletions .docs/create_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def create_notebooks():
# get a list of python files
py_files = []
for dirpath, _, filenames in os.walk(pth):
py_files += [os.path.join(dirpath, filename) for filename in
sorted(filenames) if filename.endswith(".py")]
py_files += [
os.path.join(dirpath, filename)
for filename in sorted(filenames)
if filename.endswith(".py")
]
# sort the python files
py_files = sorted(py_files)

Expand Down Expand Up @@ -43,10 +46,12 @@ def create_notebooks():
os.makedirs(npth)

for filepath in py_files:
src = os.path.join(wpth,
os.path.basename(filepath).replace(".py", ".ipynb"))
dst = os.path.join(npth,
os.path.basename(filepath).replace(".py", ".ipynb"))
src = os.path.join(
wpth, os.path.basename(filepath).replace(".py", ".ipynb")
)
dst = os.path.join(
npth, os.path.basename(filepath).replace(".py", ".ipynb")
)
shutil.copyfile(src, dst)
shutil.rmtree(".working")

Expand Down
3 changes: 3 additions & 0 deletions .docs/pysrc/tutorial1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sys

import numpy as np

import flopy

# Assign name and create modflow model object
Expand Down Expand Up @@ -52,6 +54,7 @@
mf.run_model()

import matplotlib.pyplot as plt

import flopy.utils.binaryfile as bf

plt.subplot(1, 1, 1, aspect="equal")
Expand Down
3 changes: 3 additions & 0 deletions .docs/pysrc/tutorial2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import numpy as np

import flopy

# Model domain and grid definition
Expand Down Expand Up @@ -121,6 +123,7 @@

# Imports
import matplotlib.pyplot as plt

import flopy.utils.binaryfile as bf

# Create the headfile and budget file objects
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,20 @@ jobs:
python -m pip install --upgrade pip
pip install -r etc/requirements.pip.txt

- name: Run isort
run: |
echo "if isort check fails update isort using"
echo " pip install isort --upgrade"
echo "and run"
echo " isort ./flopy"
echo "and then commit the changes."
isort --check --diff ./flopy

- name: Run black
run: |
echo "if black check fails run"
echo "if black check fails update black using"
echo " pip install black --upgrade"
echo "and run"
echo " black ./flopy"
echo "and then commit the changes."
black --check --diff ./flopy
Expand All @@ -93,7 +104,6 @@ jobs:

flopyCI:
name: autotests
needs: [flopy_setup, flopy_lint]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ flopy/.idea
examples/Notebooks/data
examples/Notebooks/temp
examples/FAQ/temp
examples/Testing/.idea
examples/Testing/data
examples/scripts/data
examples/groundwater_paper/Notebooks/temp

Expand Down
15 changes: 7 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ Before you submit your Pull Request (PR) consider the following guidelines:
```

4. Create your patch, **including appropriate test cases**. See [Autotesting,md](autotest/Autotesting.md) for guidelines for constructing autotests.
5.
6. Run the [black formatter](https://github.com/psf/black) on Flopy source files from the git repository root directory using:
5. Run the [isort import sorter](https://github.com/PyCQA/isort) and [black formatter](https://github.com/psf/black) on Flopy source files from the git repository `autotest` directory using:

```shell
black ./flopy
python pull_request_prepare.py
```
Note: Pull Requests must pass black format checks run on the [GitHub actions](https://github.com/modflowpy/flopy/actions) (*linting*) before they will be accepted. The black formatter can be installed using [`pip`](https://pypi.org/project/black/) and [`conda`](https://anaconda.org/conda-forge/black).
Note: Pull Requests must pass isort import and black format checks run on the [GitHub actions](https://github.com/modflowpy/flopy/actions) (*linting*) before they will be accepted. isort can be installed using [`pip`](https://pypi.org/project/isort/) and [`conda`](https://anaconda.org/conda-forge/isort). The black formatter can also be installed using [`pip`](https://pypi.org/project/black/) and [`conda`](https://anaconda.org/conda-forge/black). If the Pull Request fails the *linting* job in the [flopy continuous integration](https://github.com/modflowpy/flopy/actions/workflows/ci.yml) workflow, make sure the latest versions of isort and black are installed.

7. Run the full FloPy test suite and ensure that all tests pass:
6. Run the full FloPy test suite and ensure that all tests pass:

```shell
cd autotest
Expand All @@ -72,7 +71,7 @@ Before you submit your Pull Request (PR) consider the following guidelines:
```
Note: the FloPy test suite requires the [pytest](https://pypi.org/project/pytest/) and [pymake](https://github.com/modflowpy/pymake) python packages. All the FloPy dependencies must also be installed for the tests to pass.

8. Commit your changes using a descriptive commit message that follows our
7. Commit your changes using a descriptive commit message that follows our
[commit message conventions](#commit). Adherence to these conventions
is necessary because release notes are automatically generated from these messages.

Expand All @@ -81,13 +80,13 @@ Before you submit your Pull Request (PR) consider the following guidelines:
```
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.

9. Push your branch to GitHub:
8. Push your branch to GitHub:

```shell
git push origin my-fix-branch
```

10. In GitHub, send a pull request to `flopy:develop`.
9. In GitHub, send a pull request to `flopy:develop`.
* If we suggest changes then:
* Make the required updates.
* Re-run the FloPy test suites, in the autotest directory, to ensure tests are still passing.
Expand Down
1 change: 1 addition & 0 deletions autotest/ci_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def save_as_artifact(self):
shutil.copytree(test_dir, dst)
return


def _get_mf6path():
"""
Get the path for the MODFLOW 6 example problems
Expand Down
21 changes: 21 additions & 0 deletions autotest/pull_request_prepare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

try:
import isort

print(f"isort version: {isort.__version__}")
except ModuleNotFoundError:
print("isort not installed\n\tInstall using pip install isort")

try:
import black

print(f"black version: {black.__version__}")
except ModuleNotFoundError:
print("black not installed\n\tInstall using pip install black")

print("running isort...")
os.system("isort -v ../flopy")

print("running black...")
os.system("black -v ../flopy")
2 changes: 1 addition & 1 deletion autotest/t020_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def analyticalWaterTableSolution(h1, h2, z, R, K, L, x):
b2 = h2 - z
h = (
np.sqrt(
b1 ** 2 - (x / L) * (b1 ** 2 - b2 ** 2) + (R * x / K) * (L - x)
b1**2 - (x / L) * (b1**2 - b2**2) + (R * x / K) * (L - x)
)
+ z
)
Expand Down
41 changes: 27 additions & 14 deletions autotest/t029_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,29 @@ def test_flowja_residuals():
def test_structured_faceflows_3d():
model_ws = f"{base_dir}_test_faceflows_3d"
test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws)
name = 'mymodel'
sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=model_ws, exe_name='mf6')
name = "mymodel"
sim = flopy.mf6.MFSimulation(
sim_name=name, sim_ws=model_ws, exe_name="mf6"
)
tdis = flopy.mf6.ModflowTdis(sim)
ims = flopy.mf6.ModflowIms(sim)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
dis = flopy.mf6.ModflowGwfdis(gwf, nlay=3, nrow=10, ncol=10, top=0, botm=[-1, -2, -3])
dis = flopy.mf6.ModflowGwfdis(
gwf, nlay=3, nrow=10, ncol=10, top=0, botm=[-1, -2, -3]
)
ic = flopy.mf6.ModflowGwfic(gwf)
npf = flopy.mf6.ModflowGwfnpf(gwf, save_specific_discharge=True)
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=[[(0, 0, 0), 1.],
[(0, 9, 9), 0.]])
budget_file = name + '.bud'
head_file = name + '.hds'
oc = flopy.mf6.ModflowGwfoc(gwf,
budget_filerecord=budget_file,
head_filerecord=head_file,
saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])
chd = flopy.mf6.ModflowGwfchd(
gwf, stress_period_data=[[(0, 0, 0), 1.0], [(0, 9, 9), 0.0]]
)
budget_file = name + ".bud"
head_file = name + ".hds"
oc = flopy.mf6.ModflowGwfoc(
gwf,
budget_filerecord=budget_file,
head_filerecord=head_file,
saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")],
)
sim.write_simulation()
sim.run_simulation()

Expand All @@ -354,9 +361,15 @@ def test_structured_faceflows_3d():
flowja,
grb_file=os.path.join(model_ws, "mymodel.dis.grb"),
)
assert frf.shape == head.shape, f"frf.shape {frf.shape} != head.shape {head.shape}"
assert fff.shape == head.shape, f"frf.shape {frf.shape} != head.shape {head.shape}"
assert flf.shape == head.shape, f"frf.shape {frf.shape} != head.shape {head.shape}"
assert (
frf.shape == head.shape
), f"frf.shape {frf.shape} != head.shape {head.shape}"
assert (
fff.shape == head.shape
), f"frf.shape {frf.shape} != head.shape {head.shape}"
assert (
flf.shape == head.shape
), f"frf.shape {frf.shape} != head.shape {head.shape}"
return


Expand Down
31 changes: 20 additions & 11 deletions autotest/t062_test_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ def get_vlist(i, j, nrow, ncol):

# simple functions to load vertices and index lists for unstructured grid
def load_verts(fname):
verts = np.genfromtxt(fname, dtype=[int, float, float],
names=['iv', 'x', 'y'])
verts['iv'] -= 1 # zero based
verts = np.genfromtxt(
fname, dtype=[int, float, float], names=["iv", "x", "y"]
)
verts["iv"] -= 1 # zero based
return verts


def load_iverts(fname):
f = open(fname, 'r')
f = open(fname, "r")
iverts = []
xc = []
yc = []
Expand Down Expand Up @@ -244,8 +245,12 @@ def test_unstructured_xyz_intersect():
ncpl = np.array(3 * [len(iverts)])
nnodes = np.sum(ncpl)

top = np.ones((nnodes), )
botm = np.ones((nnodes), )
top = np.ones(
(nnodes),
)
botm = np.ones(
(nnodes),
)

# set top and botm elevations
i0 = 0
Expand All @@ -258,11 +263,15 @@ def test_unstructured_xyz_intersect():
i1 += cpl

# create the modelgrid
mg = flopy.discretization.UnstructuredGrid(vertices=verts,
iverts=iverts,
xcenters=xc,
ycenters=yc, top=top,
botm=botm, ncpl=ncpl)
mg = flopy.discretization.UnstructuredGrid(
vertices=verts,
iverts=iverts,
xcenters=xc,
ycenters=yc,
top=top,
botm=botm,
ncpl=ncpl,
)

xc, yc, zc = mg.xyzcellcenters
zc = zc[0].reshape(mg.nlay, mg.ncpl[0])
Expand Down
11 changes: 7 additions & 4 deletions autotest/t064_test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup_class(cls):
size = 100
nlay = 10
nper = 10
nsfr = int((size ** 2) / 5)
nsfr = int((size**2) / 5)

letters = string.ascii_lowercase
prepend = "".join(random.choice(letters) for i in range(10))
Expand Down Expand Up @@ -63,7 +63,7 @@ def setup_class(cls):
m, rech={k: 0.001 - np.cos(k) * 0.001 for k in range(nper)}
)

ra = fm.ModflowWel.get_empty(size ** 2)
ra = fm.ModflowWel.get_empty(size**2)
well_spd = {}
for kper in range(nper):
ra_per = ra.copy()
Expand Down Expand Up @@ -120,15 +120,18 @@ def test_9_load_time(self):
print("loading model...")
mfp = TestModflowPerformance()
mfp.m.write_input()
target = 3
if sys.platform == "darwin":
target = 4.0
else:
target = 3.0
t0 = time.time()
m = fm.Modflow.load(
f"{mfp.modelname}.nam", model_ws=mfp.model_ws, check=False
)
t1 = time.time() - t0
assert (
t1 < target
), f"model load took {t1:.2f}s, should take {target:.1f}s"
), f"model load took {t1:.2f}s, should take {target:.2f}s"
print(f"loading the model took {t1:.2f}s")

@classmethod
Expand Down
Loading