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
46 changes: 45 additions & 1 deletion autotest/test_flopy_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from flopy.utils.flopy_io import line_parse
import os
import platform
from os import getcwd
from os.path import relpath, splitdrive
from pathlib import Path
from shutil import which

import pytest
from modflow_devtools.markers import requires_exe
from modflow_devtools.misc import set_dir

from flopy.utils.flopy_io import line_parse, relpath_safe


def test_line_parse():
Expand All @@ -7,3 +18,36 @@ def test_line_parse():
# comment handling
line = line_parse("Well-A -1 ; 2a. WELLID,NNODES")
assert line == ["Well-A", "-1"]


@requires_exe("mf6")
@pytest.mark.parametrize("scrub", [True, False])
def test_relpath_safe(function_tmpdir, scrub):
if (
platform.system() == "Windows"
and splitdrive(function_tmpdir)[0] != splitdrive(getcwd())[0]
):
assert Path(relpath_safe(function_tmpdir)) == function_tmpdir.absolute()
assert relpath_safe(which("mf6")) == str(Path(which("mf6")).absolute())
else:
assert Path(
relpath_safe(function_tmpdir, function_tmpdir.parent)
) == Path(function_tmpdir.name)
assert (
Path(relpath_safe(function_tmpdir, function_tmpdir.parent.parent))
== Path(function_tmpdir.parent.name) / function_tmpdir.name
)

assert relpath_safe(which("mf6")) == relpath(which("mf6"), getcwd())

# test user login obfuscation
with set_dir("/"):
try:
login = os.getlogin()
p = relpath_safe(Path.home(), scrub=scrub)
if login in str(Path.home()) and scrub:
assert "***" in p
assert login not in p
except OSError:
# OSError is possible in CI, e.g. 'No such device or address'
pass
39 changes: 22 additions & 17 deletions autotest/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,13 +1031,15 @@ def test_output_add_observation(function_tmpdir, example_data_path):
sfr_obs, Mf6Obs
), "remove and add observation test (Mf6Output) failed"


@requires_exe("mf6")
def test_sfr_connections(function_tmpdir, example_data_path):
'''MODFLOW just warns if any reaches are unconnected
flopy fails to load model if reach 1 is unconnected, fine with other unconnected'''
"""MODFLOW just warns if any reaches are unconnected
flopy fails to load model if reach 1 is unconnected, fine with other unconnected
"""
data_path = example_data_path / "mf6" / "test666_sfrconnections"
sim_ws = function_tmpdir
for test in ['sfr0', 'sfr1']:
for test in ["sfr0", "sfr1"]:
sim_name = "test_sfr"
model_name = "test_sfr"
tdis_name = f"{sim_name}.tdis"
Expand Down Expand Up @@ -1079,31 +1081,34 @@ def test_sfr_connections(function_tmpdir, example_data_path):
k=50.0,
)

cnfile = f'mf6_{test}_connection.txt'
pkfile = f'mf6_{test}_package.txt'
cnfile = f"mf6_{test}_connection.txt"
pkfile = f"mf6_{test}_package.txt"

with open(data_path / pkfile, 'r') as f:
with open(data_path / pkfile, "r") as f:
nreaches = len(f.readlines())
sfr = ModflowGwfsfr(model,
packagedata={'filename': str(data_path / pkfile)},
connectiondata={'filename': str(data_path / cnfile)},
nreaches=nreaches,
pname='sfr',
unit_conversion=86400
)
sfr = ModflowGwfsfr(
model,
packagedata={"filename": str(data_path / pkfile)},
connectiondata={"filename": str(data_path / cnfile)},
nreaches=nreaches,
pname="sfr",
unit_conversion=86400,
)
sim.set_all_data_external()
sim.write_simulation()
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} did not run"

#reload simulation
# reload simulation
sim2 = MFSimulation.load(sim_ws=sim_ws)
sim.set_all_data_external()
sim.write_simulation()
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} did not run after being reloaded"


assert (
success
), f"simulation {sim.name} did not run after being reloaded"


@requires_exe("mf6")
def test_array(function_tmpdir):
# get_data
Expand Down
4 changes: 1 addition & 3 deletions autotest/test_mnw.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ def test_mnw2_create_file(function_tmpdir):
mnwmax=len(wells),
mnw=wells,
itmp=list(
(np.ones(len(stress_period_data.index)) * len(wellids)).astype(
int
)
(np.ones(len(stress_period_data.index)) * len(wellids)).astype(int)
),
)

Expand Down
31 changes: 11 additions & 20 deletions examples/FAQ/load_existing_mf2005.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:43.181355Z",
"iopub.status.busy": "2022-12-15T13:28:43.180716Z",
"iopub.status.idle": "2022-12-15T13:28:44.452726Z",
"shell.execute_reply": "2022-12-15T13:28:44.447102Z"
"iopub.execute_input": "2023-02-22T02:38:54.562417Z",
"iopub.status.busy": "2023-02-22T02:38:54.562015Z",
"iopub.status.idle": "2023-02-22T02:38:55.452558Z",
"shell.execute_reply": "2023-02-22T02:38:55.451685Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.7.15 (default, Oct 18 2022, 09:36:49) \n",
"[GCC 11.2.0]\n",
"flopy version: 3.3.6\n"
"3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]\n",
"flopy version: 3.3.7\n"
]
}
],
Expand Down Expand Up @@ -52,10 +51,10 @@
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:44.502987Z",
"iopub.status.busy": "2022-12-15T13:28:44.501928Z",
"iopub.status.idle": "2022-12-15T13:28:44.523250Z",
"shell.execute_reply": "2022-12-15T13:28:44.522309Z"
"iopub.execute_input": "2023-02-22T02:38:55.487988Z",
"iopub.status.busy": "2023-02-22T02:38:55.487318Z",
"iopub.status.idle": "2023-02-22T02:38:55.506112Z",
"shell.execute_reply": "2023-02-22T02:38:55.505372Z"
}
},
"outputs": [
Expand Down Expand Up @@ -107,20 +106,12 @@
" BCF6 package load...success\n",
"loading wel package file...\n",
" loading <class 'flopy.modflow.mfwel.ModflowWel'> for kper 1\n",
" implicit itmpp in ../data/mf2005_test/bcf2ss.wel\n",
" implicit itmp_cln in ../data/mf2005_test/bcf2ss.wel\n",
" loading <class 'flopy.modflow.mfwel.ModflowWel'> for kper 2\n",
" implicit itmpp in ../data/mf2005_test/bcf2ss.wel\n",
" implicit itmp_cln in ../data/mf2005_test/bcf2ss.wel\n",
"adding Package: WEL\n",
" WEL package load...success\n",
"loading riv package file...\n",
" loading <class 'flopy.modflow.mfriv.ModflowRiv'> for kper 1\n",
" implicit itmpp in ../data/mf2005_test/bcf2ss.riv\n",
" implicit itmp_cln in ../data/mf2005_test/bcf2ss.riv\n",
" loading <class 'flopy.modflow.mfriv.ModflowRiv'> for kper 2\n",
" implicit itmpp in ../data/mf2005_test/bcf2ss.riv\n",
" implicit itmp_cln in ../data/mf2005_test/bcf2ss.riv\n",
"adding Package: RIV\n",
" RIV package load...success\n",
"loading rch package file...\n",
Expand Down Expand Up @@ -195,7 +186,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.15"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down
47 changes: 23 additions & 24 deletions examples/FAQ/load_existing_model_wAUX.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:47.284600Z",
"iopub.status.busy": "2022-12-15T13:28:47.284136Z",
"iopub.status.idle": "2022-12-15T13:28:48.584587Z",
"shell.execute_reply": "2022-12-15T13:28:48.582184Z"
"iopub.execute_input": "2023-02-22T02:38:57.989290Z",
"iopub.status.busy": "2023-02-22T02:38:57.988720Z",
"iopub.status.idle": "2023-02-22T02:38:58.902520Z",
"shell.execute_reply": "2023-02-22T02:38:58.901874Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.7.15 (default, Oct 18 2022, 09:36:49) \n",
"[GCC 11.2.0]\n",
"flopy version: 3.3.6\n"
"3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]\n",
"flopy version: 3.3.7\n"
]
}
],
Expand Down Expand Up @@ -49,10 +48,10 @@
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:48.631684Z",
"iopub.status.busy": "2022-12-15T13:28:48.630599Z",
"iopub.status.idle": "2022-12-15T13:28:48.648958Z",
"shell.execute_reply": "2022-12-15T13:28:48.648073Z"
"iopub.execute_input": "2023-02-22T02:38:58.968512Z",
"iopub.status.busy": "2023-02-22T02:38:58.967651Z",
"iopub.status.idle": "2023-02-22T02:38:58.987908Z",
"shell.execute_reply": "2023-02-22T02:38:58.986885Z"
}
},
"outputs": [],
Expand All @@ -79,10 +78,10 @@
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:48.653210Z",
"iopub.status.busy": "2022-12-15T13:28:48.652598Z",
"iopub.status.idle": "2022-12-15T13:28:48.657827Z",
"shell.execute_reply": "2022-12-15T13:28:48.656720Z"
"iopub.execute_input": "2023-02-22T02:38:58.992067Z",
"iopub.status.busy": "2023-02-22T02:38:58.991398Z",
"iopub.status.idle": "2023-02-22T02:38:58.997441Z",
"shell.execute_reply": "2023-02-22T02:38:58.996570Z"
}
},
"outputs": [],
Expand All @@ -102,10 +101,10 @@
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:48.661328Z",
"iopub.status.busy": "2022-12-15T13:28:48.660925Z",
"iopub.status.idle": "2022-12-15T13:28:48.670325Z",
"shell.execute_reply": "2022-12-15T13:28:48.669141Z"
"iopub.execute_input": "2023-02-22T02:38:59.001461Z",
"iopub.status.busy": "2023-02-22T02:38:59.000710Z",
"iopub.status.idle": "2023-02-22T02:38:59.011006Z",
"shell.execute_reply": "2023-02-22T02:38:59.010185Z"
}
},
"outputs": [
Expand Down Expand Up @@ -136,10 +135,10 @@
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-15T13:28:48.674398Z",
"iopub.status.busy": "2022-12-15T13:28:48.673839Z",
"iopub.status.idle": "2022-12-15T13:28:48.680585Z",
"shell.execute_reply": "2022-12-15T13:28:48.679578Z"
"iopub.execute_input": "2023-02-22T02:38:59.015980Z",
"iopub.status.busy": "2023-02-22T02:38:59.015391Z",
"iopub.status.idle": "2023-02-22T02:38:59.022103Z",
"shell.execute_reply": "2023-02-22T02:38:59.021231Z"
}
},
"outputs": [
Expand Down Expand Up @@ -183,7 +182,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.15"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down
Loading