diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee167c6d2a..1b3374691d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -130,7 +130,7 @@ jobs: uses: actions/cache@v2.1.0 env: # Increase this value to reset cache if environment.yml has changed - CACHE_NUMBER: 1 + CACHE_NUMBER: 2 with: path: ~/conda_pkgs_dir key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.run-type }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('etc/environment.yml') }} @@ -154,11 +154,7 @@ jobs: - name: Add packages to flopy environment using mamba or conda run: | - if [ "$RUNNER_OS" == "Windows" ]; then - conda env update --name flopy --file etc/environment.yml - else - mamba env update --name flopy --file etc/environment.yml - fi + mamba env update --name flopy --file etc/environment.yml - name: Install pymake, xmipy, and flopy run: | @@ -175,14 +171,8 @@ jobs: run: | echo "$HOME/.local/bin" >> $GITHUB_PATH - - name: Run pytest on autotest scripts on Linux and MacOS - if: matrix.run-type == 'std' && runner.os != 'Windows' - working-directory: ./autotest - run: | - pytest -v -n auto --durations=0 --cov=flopy --cov-report=xml - - - name: Run pytest on autotest scripts on Windows - if: matrix.run-type == 'std' && runner.os == 'Windows' + - name: Run pytest on autotest scripts + if: matrix.run-type == 'std' working-directory: ./autotest run: | pytest -v -n auto --durations=0 --cov=flopy --cov-report=xml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b5bd4d8c2..67dead21e4 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,31 +47,32 @@ You can file new issues by filling out our [new issue form](https://github.com/m Before you submit your Pull Request (PR) consider the following guidelines: 1. Search [GitHub](https://github.com/modflowpy/flopy/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate effort. -1. Fork the modflowpy/flopy repo. -1. Make your changes in a new git branch: +2. Fork the modflowpy/flopy repo. +3. Make your changes in a new git branch: ```shell git checkout -b my-fix-branch develop ``` -1. Create your patch, **including appropriate test cases**. -1. Run the [black formatter](https://github.com/psf/black) on Flopy source files from the git repository root directory using: +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: ```shell black ./flopy ``` 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). -1. Run the full FloPy test suite and ensure that all tests pass: +7. Run the full FloPy test suite and ensure that all tests pass: ```shell cd autotest - nosetests -v get_exes.py - nosetests -v + pytest -v ci_prepare.py + pytest -v ``` - Note: the FloPy test suite requires the [nosetests](https://pypi.org/project/nose/) and [pymake](https://github.com/modflowpy/pymake) python packages. All the FloPy dependencies must also be installed for the tests to pass. + 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. -1. Commit your changes using a descriptive commit message that follows our +8. 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. @@ -80,13 +81,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. -1. Push your branch to GitHub: +9. Push your branch to GitHub: ```shell git push origin my-fix-branch ``` -1. In GitHub, send a pull request to `flopy:develop`. +10. 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. diff --git a/autotest/Autotesting.md b/autotest/Autotesting.md new file mode 100644 index 0000000000..1332ff69f1 --- /dev/null +++ b/autotest/Autotesting.md @@ -0,0 +1,90 @@ +## Running autotests + +### Requirements +To run the autotests you will need to install `pytest` + + pip install pytest + +If you want to run the autotests you should install `pytest-xd` + + pip install pytest pytest-xd + +### Running tests +If you want to run a single autotest run the following command from the +autotest directory + + pytest -v t001_test.py + +If you want to run all of the standard autotests (tests that match +`tXXX_test_*.py`) run the following command from the autotest directory + + pytest -v + +If you want to run all of the autotests the match a pattern run the following +command from the autotest directory + + pytest -v -k "t01" + +This would run autotests 10 through 19. + + +### Running tests in parallel + +If you want to run the autotests in parallel add `-n auto` after `-v` in your +`pytest` command. For example, + + pytest -v -n auto t001_test.py + +The `auto` keyword indicates that the `pytest-xd` extension will query your +computer to determine the number of processors available. You can specify a +specific number of processors to use (for example, `-n 2` to run on two +processors). + +The space between `-n` and the number of processors can be replaced with a +`=`. For example, + + pytest -v -n=auto t001_test.py + + +## Creating an autotest + +Limit your autotest to a few tests of the same type. See `t002_test.py` for +an example of how not to create an autotest. This test includes tests for +loading data from fixed and free format text, loading binary files, using +`util2D`, and using `util3D`. Preferably all of these tests should have +been grouped into like tests and put into a separate autotest script. + +The autotests run on GitHub Actions in parallel so new autotests should be +developed so that data written by a specific test is written to a +unique folder that includes the basename for the script with the test (`t013` +for `t013_test.py`) and the test name (`t013_mytest`). This can all be done +programatically using functions and classes in `ci_framework` script. An +example of how to construct an autotest is given below + +```python +from ci_framework import baseTestDir, flopyTest + +# set the baseDir variable using the script name +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) + +def test_mytest(): + ws = f"{baseDir}_test_mytest" + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) + + ...test something + + assert something is True, "oops" + + ws = f"{baseDir}_test_mytest_another_directory" + testFramework.addTestDir(ws, create=True) + + ...test something_else + + assert something_else is True, "oops" + + return + +``` + +Pull requests with new autotests will not be accepted if tests do not follow +the example provided above. diff --git a/autotest/ci_framework.py b/autotest/ci_framework.py index 4252bc839f..1f22e37143 100644 --- a/autotest/ci_framework.py +++ b/autotest/ci_framework.py @@ -1,9 +1,11 @@ import os import sys import shutil -import time import pymake +# command line arguments to: +# 1. keep (--keep) test files +# for idx, arg in enumerate(sys.argv): if "--keep" in arg.lower(): keep = True @@ -56,6 +58,13 @@ def baseTestDir( baseDir : str base test directory to create for the autotest + Example + ------- + + >>> from ci_framework import baseTestDir + >>> baseDir = baseTestDir(__file__, relPath="temp", create=True) + >>> print(f"baseDir: {baseDir}") + """ fileName = os.path.basename(filePath) if not fileName.startswith("t"): @@ -91,9 +100,12 @@ def createTestDir(testDir, clean=False, verbose=False): boolean indicating if diagnostic information should be written to the screen - Returns + Example ------- + >>> from ci_framework import createTestDir + >>> createTestDir("temp/mydir", clean=True, verbose=True) + """ if clean: _cleanDir(testDir, verbose=verbose) @@ -104,21 +116,78 @@ def createTestDir(testDir, clean=False, verbose=False): class flopyTest(object): + """ + The flopyTest class is used to setup test directories for flopy + autotests. + + Attributes + ---------- + clean : bool + boolean indicating if an existing directory should be cleaned + create : bool + boolean indicating if the directory should be created + testDirs : str or list/tuple of strings + path to where the test directory should be located + verbose : bool + boolean indicating if diagnostic information should be written + to the screen + retain : bool + boolean indicating if the test files should be retained + + Methods + ------- + addTestDir(testDirs, clean=False, create=False) + Add a testDir or a list of testDirs to the object + + Example + ------- + + >>> from ci_framework import flopyTest + >>> def test_function(): + ... testFramework = flopyTest(verbose=True, testDirs="temp/t091_01") + ... testFramework.addTestDir("temp/t091_02", create=True) + + """ + def __init__( self, clean=False, create=False, testDirs=None, verbose=False, + retain=None, ): - self.clean = clean - self.verbose = verbose - self.createDirs = create - self.testDirs = [] + if retain is None: + retain = keep + self._clean = clean + self._verbose = verbose + self._createDirs = create + self._retain = retain + self._testDirs = [] if testDirs is not None: self.addTestDir(testDirs, clean=clean, create=create) + def __del__(self): + if not self._retain: + for testDir in self._testDirs: + _cleanDir(testDir, verbose=self._verbose) + else: + print("Retaining test files") + def addTestDir(self, testDirs, clean=False, create=False): + """ + Add a test directory to the flopyTest object. + + Parameters + ---------- + testDirs : str or list/tuple of strings + path to where the test directory should be located + clean : bool + boolean indicating if an existing directory should be cleaned + create : bool + boolean indicating if the directory should be created + + """ if isinstance(testDirs, str): testDirs = [testDirs] elif isinstance(testDirs, (int, float, bool)): @@ -127,22 +196,24 @@ def addTestDir(self, testDirs, clean=False, create=False): "list of strings, or tuple of strings." ) for testDir in testDirs: - if testDir not in self.testDirs: - self.testDirs.append(testDir) - if self.verbose: + if testDir not in self._testDirs: + self._testDirs.append(testDir) + if self._verbose: print(f"adding test directory...{testDir}") if create: - createTestDir(testDir, clean=clean, verbose=self.verbose) - - def teardown(self): - if not keep: - for testDir in self.testDirs: - _cleanDir(testDir, verbose=self.verbose) - else: - print("Retaining test files") + createTestDir(testDir, clean=clean, verbose=self._verbose) def _get_mf6path(): + """ + Get the path for the MODFLOW 6 example problems + + Returns + ------- + mf6pth : str + path to the directory containing the MODFLOW 6 example problems. + + """ parentPath = get_parent_path() if parentPath is None: parentPath = "." @@ -155,6 +226,17 @@ def download_mf6_examples(delete_existing=False): """ Download mf6 examples and return location of folder + Parameters + ---------- + delete_existing : bool + boolean flag indicating to delete the existing MODFLOW 6 example + directory (temp/mf6examples), if it exists. + + Returns + ------- + mf6pth : str + path to the directory containing the MODFLOW 6 example problems. + """ # save current directory cpth = os.getcwd() diff --git a/autotest/ci_prepare.py b/autotest/ci_prepare.py index 3837300c13..2525b4481e 100644 --- a/autotest/ci_prepare.py +++ b/autotest/ci_prepare.py @@ -156,20 +156,6 @@ def test_list_download(): list_exes() -def test_build_dirs(): - parent_path = get_parent_path() - if parent_path is None: - print("cannot build test directories") - else: - dirPath = os.path.join(parent_path, "temp") - createTestDir(dirPath, verbose=True) - - tests = ["scripts"] - for test in tests: - testDir = os.path.join(dirPath, test) - createTestDir(testDir, verbose=True) - - def test_download_mf6_examples(delete_existing=True): if run_type == "std": downloadDir = download_mf6_examples(delete_existing=delete_existing) @@ -184,5 +170,4 @@ def test_download_mf6_examples(delete_existing=True): test_update_flopy() cleanup() list_exes() - test_build_dirs() test_download_mf6_examples() diff --git a/autotest/run_notebooks.py b/autotest/run_notebooks.py index 9900225999..b85fe3e120 100644 --- a/autotest/run_notebooks.py +++ b/autotest/run_notebooks.py @@ -1,6 +1,5 @@ # Remove the temp directory and then create a fresh one import os -import shutil import pytest @@ -22,11 +21,6 @@ os.path.join(dpth, f) for f in os.listdir(dpth) if f.endswith(".ipynb") ] -# -- make working directories -ddir = os.path.join(nbdir, "data") -if not os.path.isdir(ddir): - os.makedirs(ddir, exist_ok=True) - def run_notebook(src): # run autotest on each notebook diff --git a/autotest/run_scripts.py b/autotest/run_scripts.py index 2f49ae96e3..a011e16274 100644 --- a/autotest/run_scripts.py +++ b/autotest/run_scripts.py @@ -5,6 +5,11 @@ import shutil from subprocess import Popen, PIPE +from ci_framework import get_parent_path, flopyTest + +parentPath = get_parent_path() +baseDir = os.path.join(parentPath, "temp") + # exclude files that take time on locanachine exclude = ["flopy_swi2_ex2.py", "flopy_swi2_ex5.py"] if "CI" in os.environ: @@ -35,29 +40,15 @@ print(f" {script}") -# make working directories -out_dir = os.path.join("temp", "scripts") -if not os.path.isdir(out_dir): - os.makedirs(out_dir, exist_ok=True) - +def copy_script(dstDir, src): + fileDir = os.path.dirname(src) + fileName = os.path.basename(src) -def copy_script(src): - # copy files - filedir = os.path.dirname(src) - filename = os.path.basename(src) - - # set dstpth and clean if it exists - dstpth = os.path.abspath( - os.path.join(out_dir, filename.replace(".py", "")) - ) - if not os.path.isdir(dstpth): - os.makedirs(dstpth, exist_ok=True) - - # set destination path - dst = os.path.join(out_dir, dstpth, filename) + # set destination path with the file name + dst = os.path.join(dstDir, fileName) # copy script - print(f"copying {filename} from {filedir} to {dstpth}") + print(f"copying {fileName} from {fileDir} to {dstDir}") shutil.copyfile(src, dst) return dst @@ -65,8 +56,8 @@ def copy_script(src): def run_script(script): ws = os.path.dirname(script) - file_name = os.path.basename(script) - args = ("python", file_name) + filename = os.path.basename(script) + args = ("python", filename) print(f"running...'{' '.join(args)}'") proc = Popen(args, stdout=PIPE, stderr=PIPE, cwd=ws) stdout, stderr = proc.communicate() @@ -83,8 +74,12 @@ def run_script(script): scripts, ) def test_scripts(script): + script_name = os.path.basename(script).replace(".py", "") + dstDir = os.path.join(f"{baseDir}", f"scripts_{script_name}") + testFramework = flopyTest(verbose=True, create=True, testDirs=dstDir) + # copy script - dst = copy_script(script) + dst = copy_script(dstDir, script) # run script run_script(dst) @@ -92,5 +87,4 @@ def test_scripts(script): if __name__ == "__main__": for script in scripts: - dst = copy_script(script) - run_script(dst) + test_scripts(script) diff --git a/autotest/runtests.bat b/autotest/runtests.bat index 4df8a25fdc..5afc7bc0c3 100644 --- a/autotest/runtests.bat +++ b/autotest/runtests.bat @@ -1,4 +1,4 @@ rmdir /S /Q __pycache__ -nosetests -v +pytest -v -n auto rmdir /S /Q __pycache__ pause diff --git a/autotest/t003_test.py b/autotest/t003_test.py index d7f81e1b18..7c52ce899e 100644 --- a/autotest/t003_test.py +++ b/autotest/t003_test.py @@ -2,6 +2,10 @@ import flopy import os +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) + def test_loadfreyberg(): cwd = os.getcwd() @@ -19,13 +23,11 @@ def test_loadfreyberg(): def test_loadoahu(): - cwd = os.getcwd() pth = os.path.join("..", "examples", "data", "parameters") - assert os.path.isdir(pth) - os.chdir(pth) + assert os.path.isdir(pth), f"'{pth}' does not exist" + namefile = "Oahu_01.nam" - ml = flopy.modflow.Modflow.load(namefile, verbose=True) - os.chdir(cwd) + ml = flopy.modflow.Modflow.load(namefile, verbose=True, model_ws=pth) assert isinstance(ml, flopy.modflow.Modflow) assert ml.load_fail is False @@ -33,27 +35,25 @@ def test_loadoahu(): def test_loadtwrip(): - cwd = os.getcwd() pth = os.path.join("..", "examples", "data", "parameters") - assert os.path.isdir(pth) - os.chdir(pth) + assert os.path.isdir(pth), f"'{pth}' does not exist" + namefile = "twrip.nam" - ml = flopy.modflow.Modflow.load(namefile, verbose=True) - os.chdir(cwd) + ml = flopy.modflow.Modflow.load(namefile, verbose=True, model_ws=pth) + assert isinstance(ml, flopy.modflow.Modflow) - assert ml.load_fail is False + assert not ml.load_fail return def test_loadtwrip_upw(): - cwd = os.getcwd() pth = os.path.join("..", "examples", "data", "parameters") - assert os.path.isdir(pth) - os.chdir(pth) + assert os.path.isdir(pth), f"'{pth}' does not exist" + namefile = "twrip_upw.nam" - ml = flopy.modflow.Modflow.load(namefile, verbose=True) - os.chdir(cwd) + ml = flopy.modflow.Modflow.load(namefile, verbose=True, model_ws=pth) + assert isinstance(ml, flopy.modflow.Modflow) assert ml.load_fail is False @@ -61,10 +61,11 @@ def test_loadtwrip_upw(): def test_loadoc(): - ws = os.path.join("temp", "t003") - ml = flopy.modflow.Modflow(model_ws=ws) + ml = flopy.modflow.Modflow() + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.dis") dis = flopy.modflow.ModflowDis.load(fpth, ml, check=False) + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.oc") oc = flopy.modflow.ModflowOc.load(fpth, ml, ext_unit_dict=None) @@ -72,8 +73,8 @@ def test_loadoc(): def test_loadoc_lenfail(): - ws = os.path.join("temp", "t003") - ml = flopy.modflow.Modflow(model_ws=ws) + ml = flopy.modflow.Modflow() + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.oc") with pytest.raises(OSError): oc = flopy.modflow.ModflowOc.load(fpth, ml, nper=3, nstp=1, nlay=1) @@ -82,8 +83,8 @@ def test_loadoc_lenfail(): def test_loadoc_nperfail(): - ws = os.path.join("temp", "t003") - ml = flopy.modflow.Modflow(model_ws=ws) + ml = flopy.modflow.Modflow() + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.oc") with pytest.raises(ValueError): oc = flopy.modflow.ModflowOc.load(fpth, ml, nper=0, nlay=1) @@ -92,8 +93,8 @@ def test_loadoc_nperfail(): def test_loadoc_nlayfail(): - ws = os.path.join("temp", "t003") - ml = flopy.modflow.Modflow(model_ws=ws) + ml = flopy.modflow.Modflow() + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.oc") with pytest.raises(ValueError): oc = flopy.modflow.ModflowOc.load(fpth, ml, nper=3, nlay=0) @@ -102,8 +103,8 @@ def test_loadoc_nlayfail(): def test_loadoc_nstpfail(): - ws = os.path.join("temp", "t003") - ml = flopy.modflow.Modflow(model_ws=ws) + ml = flopy.modflow.Modflow() + fpth = os.path.join("..", "examples", "data", "mf2005_test", "fhb.oc") with pytest.raises(ValueError): oc = flopy.modflow.ModflowOc.load(fpth, ml, nper=3, nlay=1) diff --git a/autotest/t004_test_utilarray.py b/autotest/t004_test_utilarray.py index 74825b5017..f7659503e1 100644 --- a/autotest/t004_test_utilarray.py +++ b/autotest/t004_test_utilarray.py @@ -10,7 +10,7 @@ from ci_framework import baseTestDir, flopyTest -baseDir = baseTestDir(__file__, create=True, relPath="temp", verbose=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_load_txt_free(): @@ -141,9 +141,12 @@ def test_load_block(): def test_load_bin(): + model_ws = f"{baseDir}_test_load_bin" + testFramework = flopyTest(testDirs=model_ws, create=True) + def temp_file(data): # writable file that is destroyed as soon as it is closed - f = TemporaryFile() + f = TemporaryFile(dir=model_ws) f.write(data) f.seek(0) return f @@ -257,8 +260,8 @@ def test_transient3d(): def test_util2d(): - model_ws = os.path.join(baseDir, f"{baseDir}_util2d") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d" + testFramework = flopyTest(testDirs=model_ws) ml = flopy.modflow.Modflow(model_ws=model_ws) u2d = Util2d(ml, (10, 10), np.float32, 10.0, "test") @@ -329,10 +332,8 @@ def test_util2d(): a7 = u2d.load_txt((10, 10), fname, u2d.dtype, "(FREE)") assert np.array_equal(u2d.array, a7) - fpTest.teardown() - -def stress_util2d(ml, nlay, nrow, ncol): +def stress_util2d(model_ws, ml, nlay, nrow, ncol): dis = flopy.modflow.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol) hk = np.ones((nlay, nrow, ncol)) vk = np.ones((nlay, nrow, ncol)) + 1.0 @@ -368,7 +369,7 @@ def stress_util2d(ml, nlay, nrow, ncol): ml.namefile, model_ws=ml.model_ws, verbose=True, forgive=False ) print("testing load") - assert ml1.load_fail == False + assert not ml1.load_fail # check that both binary and cnstnt are being respected through # out the write and load process. assert np.array_equal(ml1.lpf.vka.array, vk * 2.0) @@ -377,7 +378,7 @@ def stress_util2d(ml, nlay, nrow, ncol): assert np.array_equal(ml1.lpf.hk.array, ml.lpf.hk.array) print("change model_ws") - ml.model_ws = f"{ml._model_ws}_new_model_ws" + ml.model_ws = os.path.join(model_ws, "new") ml.write_input() if ml.external_path is not None: files = os.listdir(os.path.join(ml.model_ws, ml.external_path)) @@ -409,7 +410,7 @@ def stress_util2d_for_joe_the_file_king(ml, nlay, nrow, ncol): # save hk up one dir from model_ws fnames = [] for i, h in enumerate(hk): - fname = os.path.join(f"test_{i}.ref") + fname = os.path.join(ml._model_ws, f"test_{i}.ref") fnames.append(fname) np.savetxt(fname, h, fmt="%15.6e", delimiter="") vk[i] = i + 1.0 @@ -426,7 +427,7 @@ def stress_util2d_for_joe_the_file_king(ml, nlay, nrow, ncol): ml.namefile, model_ws=ml.model_ws, verbose=True, forgive=False ) print("testing load") - assert ml1.load_fail == False + assert not ml1.load_fail assert np.array_equal(ml1.lpf.vka.array, vk * 2.0) assert np.array_equal(ml1.lpf.hk.array, hk) assert np.array_equal(ml1.lpf.vka.array, ml.lpf.vka.array) @@ -443,44 +444,40 @@ def stress_util2d_for_joe_the_file_king(ml, nlay, nrow, ncol): def test_util2d_external_free(): - model_ws = os.path.join(baseDir, f"{baseDir}_ext_free_a") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d_external_free" + testFramework = flopyTest(testDirs=model_ws) ml = flopy.modflow.Modflow(model_ws=model_ws) - stress_util2d(ml, 1, 1, 1) - stress_util2d(ml, 10, 1, 1) - stress_util2d(ml, 1, 10, 1) - stress_util2d(ml, 1, 1, 10) - stress_util2d(ml, 10, 10, 1) - stress_util2d(ml, 1, 10, 10) - stress_util2d(ml, 10, 1, 10) - stress_util2d(ml, 10, 10, 10) - - fpTest.teardown() + stress_util2d(model_ws, ml, 1, 1, 1) + stress_util2d(model_ws, ml, 10, 1, 1) + stress_util2d(model_ws, ml, 1, 10, 1) + stress_util2d(model_ws, ml, 1, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 1) + stress_util2d(model_ws, ml, 1, 10, 10) + stress_util2d(model_ws, ml, 10, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 10) def test_util2d_external_free_path(): - model_ws = os.path.join(baseDir, f"{baseDir}_ext_free") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d_external_free_path" + testFramework = flopyTest(testDirs=model_ws) ext_path = "ref" ml = flopy.modflow.Modflow(model_ws=model_ws, external_path=ext_path) - stress_util2d(ml, 1, 1, 1) - stress_util2d(ml, 10, 1, 1) - stress_util2d(ml, 1, 10, 1) - stress_util2d(ml, 1, 1, 10) - stress_util2d(ml, 10, 10, 1) - stress_util2d(ml, 1, 10, 10) - stress_util2d(ml, 10, 1, 10) - stress_util2d(ml, 10, 10, 10) - - fpTest.teardown() + stress_util2d(model_ws, ml, 1, 1, 1) + stress_util2d(model_ws, ml, 10, 1, 1) + stress_util2d(model_ws, ml, 1, 10, 1) + stress_util2d(model_ws, ml, 1, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 1) + stress_util2d(model_ws, ml, 1, 10, 10) + stress_util2d(model_ws, ml, 10, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 10) def test_util2d_external_free_path_a(): - model_ws = os.path.join(baseDir, f"{baseDir}_ext_free_a") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d_external_free_path_a" + testFramework = flopyTest(testDirs=model_ws) ext_path = "ref" ml = flopy.modflow.Modflow(model_ws=model_ws, external_path=ext_path) @@ -494,50 +491,47 @@ def test_util2d_external_free_path_a(): stress_util2d_for_joe_the_file_king(ml, 10, 1, 10) stress_util2d_for_joe_the_file_king(ml, 10, 10, 10) - fpTest.teardown() - def test_util2d_external_fixed(): - model_ws = os.path.join(baseDir, f"{baseDir}_ext_fixed") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d_external_fixed" + testFramework = flopyTest(testDirs=model_ws) ml = flopy.modflow.Modflow(model_ws=model_ws) ml.array_free_format = False - stress_util2d(ml, 1, 1, 1) - stress_util2d(ml, 10, 1, 1) - stress_util2d(ml, 1, 10, 1) - stress_util2d(ml, 1, 1, 10) - stress_util2d(ml, 10, 10, 1) - stress_util2d(ml, 1, 10, 10) - stress_util2d(ml, 10, 1, 10) - stress_util2d(ml, 10, 10, 10) - - fpTest.teardown() + stress_util2d(model_ws, ml, 1, 1, 1) + stress_util2d(model_ws, ml, 10, 1, 1) + stress_util2d(model_ws, ml, 1, 10, 1) + stress_util2d(model_ws, ml, 1, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 1) + stress_util2d(model_ws, ml, 1, 10, 10) + stress_util2d(model_ws, ml, 10, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 10) def test_util2d_external_fixed_path(): - model_ws = os.path.join(baseDir, f"{baseDir}_ext_fixed_path") - fpTest = flopyTest(testDirs=model_ws) + model_ws = f"{baseDir}_test_util2d_external_fixed_path" + testFramework = flopyTest(testDirs=model_ws) ext_path = "ref" ml = flopy.modflow.Modflow(model_ws=model_ws, external_path=ext_path) ml.array_free_format = False - stress_util2d(ml, 1, 1, 1) - stress_util2d(ml, 10, 1, 1) - stress_util2d(ml, 1, 10, 1) - stress_util2d(ml, 1, 1, 10) - stress_util2d(ml, 10, 10, 1) - stress_util2d(ml, 1, 10, 10) - stress_util2d(ml, 10, 1, 10) - stress_util2d(ml, 10, 10, 10) - - fpTest.teardown() + stress_util2d(model_ws, ml, 1, 1, 1) + stress_util2d(model_ws, ml, 10, 1, 1) + stress_util2d(model_ws, ml, 1, 10, 1) + stress_util2d(model_ws, ml, 1, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 1) + stress_util2d(model_ws, ml, 1, 10, 10) + stress_util2d(model_ws, ml, 10, 1, 10) + stress_util2d(model_ws, ml, 10, 10, 10) def test_util3d(): - ml = flopy.modflow.Modflow() + model_ws = f"{baseDir}_test_util3d" + testFramework = flopyTest(testDirs=model_ws) + + ml = flopy.modflow.Modflow(model_ws=model_ws) u3d = Util3d(ml, (10, 10, 10), np.float32, 10.0, "test") a1 = u3d.array a2 = np.ones((10, 10, 10), dtype=np.float32) * 10.0 @@ -557,7 +551,10 @@ def test_util3d(): def test_arrayformat(): - ml = flopy.modflow.Modflow(model_ws=baseDir) + model_ws = f"{baseDir}_test_arrayformat" + testFramework = flopyTest(testDirs=model_ws) + + ml = flopy.modflow.Modflow(model_ws=model_ws) u2d = Util2d(ml, (15, 2), np.float32, np.ones((15, 2)), "test") fmt_fort = u2d.format.fortran @@ -612,7 +609,10 @@ def test_arrayformat(): def test_new_get_file_entry(): - ml = flopy.modflow.Modflow(model_ws=baseDir) + model_ws = f"{baseDir}_test_new_get_file_entry" + testFramework = flopyTest(testDirs=model_ws) + + ml = flopy.modflow.Modflow(model_ws=model_ws) u2d = Util2d(ml, (5, 2), np.float32, np.ones((5, 2)), "test", locat=99) print(u2d.get_file_entry(how="internal")) print(u2d.get_file_entry(how="constant")) @@ -634,8 +634,8 @@ def test_new_get_file_entry(): def test_append_mflist(): - ws = f"{baseDir}_mflist_append" - fpTest = flopyTest(verbose=True, testDirs=ws) + ws = f"{baseDir}_test_append_mflist" + testFramework = flopyTest(verbose=True, testDirs=ws) ml = flopy.modflow.Modflow(model_ws=ws) dis = flopy.modflow.ModflowDis(ml, 10, 10, 10, 10) @@ -651,11 +651,12 @@ def test_append_mflist(): ) ml.write_input() - fpTest.teardown() - def test_mflist(): - ml = flopy.modflow.Modflow(model_ws=baseDir) + model_ws = f"{baseDir}_test_mflist" + testFramework = flopyTest(testDirs=model_ws, create=True) + + ml = flopy.modflow.Modflow(model_ws=model_ws) dis = flopy.modflow.ModflowDis(ml, 10, 10, 10, 10) sp_data = { 0: [[1, 1, 1, 1.0], [1, 1, 2, 2.0], [1, 1, 3, 3.0]], @@ -804,7 +805,10 @@ def test_how(): import numpy as np import flopy - ml = flopy.modflow.Modflow(model_ws=baseDir) + model_ws = f"{baseDir}_test_how" + testFramework = flopyTest(testDirs=model_ws) + + ml = flopy.modflow.Modflow(model_ws=model_ws) ml.array_free_format = False dis = flopy.modflow.ModflowDis(ml, nlay=2, nrow=10, ncol=10) @@ -833,12 +837,25 @@ def test_mflist_fromfile(): import pandas as pd import flopy + model_ws = f"{baseDir}_test_mflist_fromfile" + testFramework = flopyTest(testDirs=model_ws, create=True) + wel_data = pd.DataFrame( [(0, 1, 2, -50.0), (0, 5, 5, -50.0)], columns=["k", "i", "j", "flux"] ) - wel_data.to_csv("wel_000.dat", index=False, sep=" ", header=False) + wpth = os.path.join(model_ws, "wel_000.dat") + wel_data.to_csv( + wpth, + index=False, + sep=" ", + header=False, + ) - nwt_model = flopy.modflow.Modflow("nwt_testmodel", verbose=True) + nwt_model = flopy.modflow.Modflow( + "nwt_testmodel", + verbose=True, + model_ws=model_ws, + ) dis = flopy.modflow.ModflowDis( nwt_model, nlay=1, @@ -849,9 +866,7 @@ def test_mflist_fromfile(): top=100.0, botm=50.0, ) - wel = flopy.modflow.ModflowWel( - nwt_model, stress_period_data={0: "wel_000.dat"} - ) + wel = flopy.modflow.ModflowWel(nwt_model, stress_period_data={0: wpth}) flx_array = wel.stress_period_data.array["flux"][0] for k, i, j, flx in zip(wel_data.k, wel_data.i, wel_data.j, wel_data.flux): assert flx_array[k, i, j] == flx diff --git a/autotest/t005_test.py b/autotest/t005_test.py index d376e39beb..af1883dd22 100644 --- a/autotest/t005_test.py +++ b/autotest/t005_test.py @@ -10,7 +10,7 @@ def test_modflow_unstructured(): import flopy import numpy as np - fpTest = flopyTest(testDirs=cpth) + testFramework = flopyTest(testDirs=cpth) mf = flopy.mfusg.MfUsg(structured=False, model_ws=cpth) assert isinstance(mf, flopy.mfusg.MfUsg) @@ -54,8 +54,6 @@ def test_modflow_unstructured(): ) assert ghb2.stress_period_data[0] == ghb.stress_period_data[0] - fpTest.teardown() - return diff --git a/autotest/t006_test.py b/autotest/t006_test.py index 9e83b2530f..9303e21536 100644 --- a/autotest/t006_test.py +++ b/autotest/t006_test.py @@ -52,7 +52,7 @@ def test_formattedfile_reference(): def test_mflist_reference(): - fpTest = flopyTest(testDirs=cpth) + testFramework = flopyTest(testDirs=cpth) # make the model ml = flopy.modflow.Modflow() @@ -110,8 +110,6 @@ def test_mflist_reference(): shp = shapefile.Reader(test) assert shp.numRecords == nrow * ncol - fpTest.teardown() - def test_cbc_ts(): fpth = os.path.join( diff --git a/autotest/t007_test.py b/autotest/t007_test.py index 30a4f3478f..442521b8f2 100644 --- a/autotest/t007_test.py +++ b/autotest/t007_test.py @@ -44,14 +44,12 @@ def remove_shp(shpname): def export_mf6_netcdf(ws, path): print(f"in export_mf6_netcdf: {path}") - fpTest = flopyTest(create=True, testDirs=ws) + testFramework = flopyTest(create=True, testDirs=ws) sim = flopy.mf6.modflow.mfsimulation.MFSimulation.load(sim_ws=path) for name, model in sim.get_model_itr(): export_netcdf(ws, model) - fpTest.teardown() - def export_mf2005_netcdf(ws, namfile): print(f"in export_mf2005_netcdf: {namfile}") @@ -81,7 +79,7 @@ def export_netcdf(ws, m): import pyproj except: return - fpTest = flopyTest(create=True, testDirs=ws) + testFramework = flopyTest(create=True, testDirs=ws) fnc = m.export(os.path.join(ws, f"{m.name}.nc")) fnc.write() @@ -101,8 +99,6 @@ def export_netcdf(ws, m): nc.close() - fpTest.teardown() - return @@ -166,7 +162,7 @@ def export_shapefile_modelgrid_override(namfile): name = namfile.replace(".nam", "") ws_out = f"{baseDir}_{name}_shapefile_modelgrid_override" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) fnc_name = os.path.join(ws_out, f"{m.name}.shp") @@ -185,8 +181,6 @@ def export_shapefile_modelgrid_override(namfile): msg = f"shapefile import fail for {fnc_name}:{e!s}" raise Exception(msg) - fpTest.teardown() - def test_output_helper_shapefile_export(): if import_shapefile() is None: @@ -202,7 +196,7 @@ def test_output_helper_shapefile_export(): cbc = flopy.utils.CellBudgetFile(os.path.join(ws, "freyberg.cbc")) ws_out = f"{baseDir}_helper_shapefile" - fpTest = flopyTest(verbose=True, create=True, testDirs=ws_out) + testFramework = flopyTest(verbose=True, create=True, testDirs=ws_out) flopy.export.utils.output_helper( os.path.join(ws_out, "test.shp"), @@ -212,8 +206,6 @@ def test_output_helper_shapefile_export(): kper=10, ) - fpTest.teardown() - def test_freyberg_export(): if import_shapefile() is None: @@ -231,7 +223,7 @@ def test_freyberg_export(): name = namfile.replace(".nam", "") ws_out = f"{baseDir}_{name}_shapefile_freyberg" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) # test export at model, package and object levels m.export(f"{ws_out}/model.shp") @@ -306,8 +298,6 @@ def test_freyberg_export(): assert prjtxt == wkt remove_shp(outshp) - fpTest.teardown() - def test_export_output(): @@ -324,7 +314,7 @@ def test_export_output(): hds = flopy.utils.HeadFile(hds_pth) ws = f"{baseDir}_freyberg_export_output_netcdf" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) out_pth = os.path.join(ws, "freyberg.out.nc") nc = flopy.export.utils.output_helper( @@ -339,8 +329,6 @@ def test_export_output(): # close the netcdf file nc.nc.close() - fpTest.teardown() - def test_write_shapefile(): sf = import_shapefile() @@ -352,7 +340,7 @@ def test_write_shapefile(): from flopy.export.shapefile_utils import write_grid_shapefile ws_out = f"{baseDir}_shapefile_write" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) sg = StructuredGrid( delr=np.ones(10) * 1.1, @@ -392,8 +380,6 @@ def test_write_shapefile(): except: pass - fpTest.teardown() - def test_shapefile_polygon_closed(): shapefile = import_shapefile() @@ -418,7 +404,7 @@ def test_shapefile_polygon_closed(): ) ws_out = f"{baseDir}_shapefile_polygon_closed" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) shp_file = os.path.join(ws_out, "test_polygon.shp") m.dis.export(shp_file) @@ -430,8 +416,6 @@ def test_shapefile_polygon_closed(): shp.close() - fpTest.teardown() - def test_export_array(): from flopy.export import utils @@ -443,7 +427,7 @@ def test_export_array(): pass ws_out = f"{baseDir}_export_array" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) namfile = "freyberg.nam" model_ws = "../examples/data/freyberg_multilayer_transient/" @@ -513,13 +497,11 @@ def test_export_array(): # assert np.abs(src.bounds[0] - m.modelgrid.extent[0]) < 1e-6 # assert np.abs(src.bounds[1] - m.modelgrid.extent[1]) < 1e-6 - fpTest.teardown() - def test_mbase_modelgrid(): ws = f"{baseDir}_mbase_modelgrid" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) ml = flopy.modflow.Modflow( modelname="test", xll=500.0, rotation=12.5, start_datetime="1/1/2016" @@ -544,13 +526,11 @@ def test_mbase_modelgrid(): assert ml1.start_datetime == ml.start_datetime assert ml1.modelgrid.proj4 is None - fpTest.teardown() - def test_mt_modelgrid(): ws = f"{baseDir}_mt_modelgrid" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) ml = flopy.modflow.Modflow( modelname="test", @@ -644,13 +624,11 @@ def test_mt_modelgrid(): assert np.array_equal(mt.modelgrid.idomain, ml.modelgrid.idomain) assert np.array_equal(swt.modelgrid.idomain, ml.modelgrid.idomain) - fpTest.teardown() - def test_free_format_flag(): ws_out = f"{baseDir}_free_format_flag" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) Lx = 100.0 Ly = 100.0 @@ -694,12 +672,10 @@ def test_free_format_flag(): bas.ifrefm = True assert ms1.free_format_input == ms1.bas6.ifrefm - fpTest.teardown() - def test_sr(): ws = f"{baseDir}_test_sr" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) m = flopy.modflow.Modflow( "test", @@ -724,8 +700,6 @@ def test_sr(): if not np.allclose(mm.dis.top.array, mm.modelgrid.top): raise AssertionError("modelgrid failed dynamic update test") - fpTest.teardown() - def test_dis_sr(): @@ -818,7 +792,7 @@ def test_mg(): from flopy.utils import geometry ws = f"{baseDir}_test_modelgrid" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) Lx = 100.0 Ly = 100.0 @@ -900,8 +874,6 @@ def test_mg(): assert ms1.start_datetime == ms.start_datetime assert ms1.modelgrid.lenuni == ms.modelgrid.lenuni - fpTest.teardown() - def test_epsgs(): import flopy.export.shapefile_utils as shp @@ -966,7 +938,7 @@ def test_dynamic_xll_yll(): def test_namfile_readwrite(): ws = f"{baseDir}__namfile_readwrite" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) nlay, nrow, ncol = 1, 30, 5 delr, delc = 250, 500 @@ -1018,12 +990,10 @@ def test_namfile_readwrite(): assert ml.modelgrid.yoffset == ml.modelgrid._yul_to_yll(3353277) assert ml.modelgrid.angrot == 15.0 - fpTest.teardown() - def test_read_usgs_model_reference(): model_ws = f"{baseDir}_usgs_model_reference" - fpTest = flopyTest(verbose=True, testDirs=model_ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) nlay, nrow, ncol = 1, 30, 5 delr, delc = 250, 500 @@ -1095,8 +1065,6 @@ def test_read_usgs_model_reference(): os.remove(os.path.join(f)) assert True - fpTest.teardown() - def test_rotation(): m = flopy.modflow.Modflow(rotation=20.0) @@ -1547,7 +1515,7 @@ def test_netcdf_classmethods(): namfile = "freyberg.nam" name = namfile.replace(".nam", "") ws = f"{baseDir}_{name}_netcdf_classmethods" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) model_ws = os.path.join( "..", "examples", "data", "freyberg_multilayer_transient" @@ -1568,8 +1536,6 @@ def test_netcdf_classmethods(): f.nc.close() new_f.nc.close() - fpTest.teardown() - def test_wkt_parse(): """Test parsing of Coordinate Reference System parameters @@ -1613,7 +1579,7 @@ def test_shapefile_ibound(): return ws_out = f"{baseDir}_shapefile_ibound" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) shape_name = os.path.join(ws_out, "test.shp") namfile = "freyberg.nam" @@ -1635,8 +1601,6 @@ def test_shapefile_ibound(): assert type(shp.record(0)[ib_idx]) == int, txt shp.close() - fpTest.teardown() - @pytest.mark.parametrize( "namfile", @@ -1645,9 +1609,9 @@ def test_shapefile_ibound(): def test_shapefile(namfile): name = namfile.replace(".nam", "") ws = f"{baseDir}_{name}_shapefile" - fpTest = flopyTest(create=True, testDirs=ws) + testFramework = flopyTest(create=True, testDirs=ws) export_shapefile(ws, namfile) - fpTest.teardown() + return @@ -1694,7 +1658,7 @@ def test_export_array2(): from flopy.export.utils import export_array ws_out = f"{baseDir}_shapefile_export_array2" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) nrow = 7 ncol = 11 @@ -1727,8 +1691,6 @@ def test_export_array2(): export_array(modelgrid, filename, a, epsg=epsg) assert os.path.isfile(filename), "did not create array shapefile" - fpTest.teardown() - def test_export_array_contours(): if import_shapefile() is None: @@ -1737,7 +1699,7 @@ def test_export_array_contours(): from flopy.export.utils import export_array_contours ws_out = f"{baseDir}_shapefile_array_contours" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) nrow = 7 ncol = 11 @@ -1770,8 +1732,6 @@ def test_export_array_contours(): export_array_contours(modelgrid, filename, a, epsg=epsg) assert os.path.isfile(filename), "did not create contour shapefile" - fpTest.teardown() - def test_export_contourf(): try: @@ -1784,7 +1744,7 @@ def test_export_contourf(): from flopy.export.utils import export_contourf ws_out = f"{baseDir}_shapefile_export_contourf" - fpTest = flopyTest(verbose=True, testDirs=ws_out, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) filename = os.path.join(ws_out, "myfilledcontours.shp") a = np.random.random((10, 10)) @@ -1793,8 +1753,6 @@ def test_export_contourf(): assert os.path.isfile(filename), "did not create contourf shapefile" plt.close() - fpTest.teardown() - def main(): # test_shapefile() diff --git a/autotest/t008_test.py b/autotest/t008_test.py index 29d3b37d95..2e9b2607c1 100644 --- a/autotest/t008_test.py +++ b/autotest/t008_test.py @@ -109,7 +109,7 @@ def load_nwt_pack(nwtfile): + "_" + os.path.basename(nwtfile).replace(".nam", "_nwtpack") ) - fpTest = flopyTest(testDirs=new_ws, verbose=True) + testFramework = flopyTest(testDirs=new_ws, verbose=True) ws = os.path.dirname(nwtfile) ml = flopy.modflow.Modflow(model_ws=ws, version="mfnwt") @@ -144,8 +144,6 @@ def load_nwt_pack(nwtfile): ) assert nwt2[l] == nwt[l], msg - fpTest.teardown() - def load_nwt_model(nfile): new_ws = ( @@ -153,7 +151,7 @@ def load_nwt_model(nfile): + "_" + os.path.basename(nfile).replace(".nam", "") ) - fpTest = flopyTest(testDirs=new_ws, verbose=True) + testFramework = flopyTest(testDirs=new_ws, verbose=True) f = os.path.basename(nfile) model_ws = os.path.dirname(nfile) @@ -184,8 +182,6 @@ def load_nwt_model(nfile): ) assert p[l] == p2[l], msg - fpTest.teardown() - if __name__ == "__main__": for namfile in namfiles: diff --git a/autotest/t015_test.py b/autotest/t015_test.py index 16fa2351cd..96fcd7e0c2 100644 --- a/autotest/t015_test.py +++ b/autotest/t015_test.py @@ -14,10 +14,9 @@ except: pymake = None -tpth = os.path.abspath(os.path.join("temp", "t015")) -# make the directory if it does not exist -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) mfexe = "mf2005" v = flopy.which(mfexe) @@ -42,6 +41,9 @@ def test_str_issue1164(): + model_ws = f"{baseDir}_test_str_issue1164" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + m = flopy.modflow.Modflow.load( str_items[0]["mfnam"], exe_name=mfexe, @@ -50,8 +52,7 @@ def test_str_issue1164(): check=False, ) - ws = os.path.join(tpth, "issue-1164") - m.change_model_ws(ws) + m.change_model_ws(model_ws) # adjust stress period data spd0 = m.str.stress_period_data[0] @@ -64,7 +65,7 @@ def test_str_issue1164(): assert success, "could not run base model" # get the budget - lst_pth = os.path.join(ws, str_items[0]["lstfile"]) + lst_pth = os.path.join(model_ws, str_items[0]["lstfile"]) base_wb = flopy.utils.MfListBudget(lst_pth).get_dataframes()[0] # set the model to free format @@ -82,7 +83,10 @@ def test_str_issue1164(): assert revised_wb.equals(base_wb), "water budgets do not match" -def test_str_free(): +def test_str_fixed_free(): + model_ws = f"{baseDir}_test_str_fixed" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + m = flopy.modflow.Modflow.load( str_items[0]["mfnam"], exe_name=mfexe, @@ -90,8 +94,7 @@ def test_str_free(): verbose=False, check=False, ) - ws = os.path.join(tpth, "fixed") - m.change_model_ws(ws) + m.change_model_ws(model_ws) # get pointer to str package str = m.str @@ -153,7 +156,7 @@ def test_str_free(): m2 = flopy.modflow.Modflow.load( str_items[0]["mfnam"], exe_name=mfexe, - model_ws=ws, + model_ws=model_ws, verbose=False, check=False, ) @@ -163,8 +166,10 @@ def test_str_free(): msg = "could not load the fixed format model with aux variables" assert m2 is not None, msg - ws = os.path.join(tpth, "free") - m.change_model_ws(ws) + model_ws2 = f"{baseDir}_test_str_free" + testFramework.addTestDir(model_ws2) + + m.change_model_ws(model_ws2) m.set_ifrefm() m.write_input() if run: @@ -179,7 +184,7 @@ def test_str_free(): m2 = flopy.modflow.Modflow.load( str_items[0]["mfnam"], exe_name=mfexe, - model_ws=ws, + model_ws=model_ws2, verbose=False, check=False, ) @@ -192,8 +197,8 @@ def test_str_free(): # compare the fixed and free format head files if run: if pymake is not None: - fn1 = os.path.join(tpth, "fixed", "str.nam") - fn2 = os.path.join(ws, "str.nam") + fn1 = os.path.join(model_ws, "str.nam") + fn2 = os.path.join(model_ws2, "str.nam") success = pymake.compare_heads(fn1, fn2, verbose=True) msg = "fixed and free format input output head files are different" assert success, msg @@ -210,5 +215,5 @@ def test_str_plot(): if __name__ == "__main__": test_str_issue1164() - test_str_free() + test_str_fixed_free() test_str_plot() diff --git a/autotest/t016_test.py b/autotest/t016_test.py index 3b2c2999d0..60db26b246 100644 --- a/autotest/t016_test.py +++ b/autotest/t016_test.py @@ -2,11 +2,9 @@ import flopy import numpy as np +from ci_framework import baseTestDir, flopyTest -tpth = os.path.abspath(os.path.join("temp", "t016")) -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) exe_name = "mfusg" v = flopy.which(exe_name) @@ -17,6 +15,8 @@ def test_usg_disu_load(): + model_ws = f"{baseDir}_test_usg_disu_load" + testFramework = flopyTest(verbose=True, testDirs=model_ws) pthusgtest = os.path.join( "..", "examples", "data", "mfusg_test", "01A_nestedgrid_nognc" @@ -32,7 +32,6 @@ def test_usg_disu_load(): assert isinstance(disu, flopy.mfusg.MfUsgDisU) # Change where model files are written - model_ws = tpth m.model_ws = model_ws # Write the disu file @@ -59,6 +58,8 @@ def test_usg_disu_load(): def test_usg_sms_load(): + model_ws = f"{baseDir}_test_usg_sms_load" + testFramework = flopyTest(verbose=True, testDirs=model_ws) pthusgtest = os.path.join( "..", "examples", "data", "mfusg_test", "01A_nestedgrid_nognc" @@ -74,7 +75,6 @@ def test_usg_sms_load(): assert isinstance(sms, flopy.mfusg.MfUsgSms) # Change where model files are written - model_ws = tpth m.model_ws = model_ws # Write the sms file @@ -96,10 +96,13 @@ def test_usg_sms_load(): def test_usg_model(): + model_ws = f"{baseDir}_test_usg_model" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + mf = flopy.mfusg.MfUsg( version="mfusg", structured=True, - model_ws=tpth, + model_ws=model_ws, modelname="simple", exe_name=v, ) @@ -132,24 +135,35 @@ def test_usg_model(): sms.write_file() if run: success, buff = mf.run_model() - assert success + assert success, f"{mf.name} did not run" + + return def test_usg_load_01B(): print( - "testing 1-layer unstructured mfusg model loading: 01A_nestedgrid_nognc.nam" + "testing 1-layer unstructured mfusg model " + "loading: 01A_nestedgrid_nognc.nam" ) + + model_ws = f"{baseDir}_test_usg_load_01B" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + pthusgtest = os.path.join( "..", "examples", "data", "mfusg_test", "01A_nestedgrid_nognc" ) - fname = os.path.join(pthusgtest, "flow.nam") + fname = os.path.abspath(os.path.join(pthusgtest, "flow.nam")) assert os.path.isfile(fname), f"nam file not found {fname}" # Create the model - m = flopy.mfusg.MfUsg(modelname="usgload_1b", verbose=True) + m = flopy.mfusg.MfUsg( + modelname="usgload_1b", + verbose=True, + model_ws=model_ws, + ) # Load the model, with checking - m = m.load(fname, check=True) + m = m.load(fname, check=True, model_ws=model_ws) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -166,15 +180,19 @@ def test_usg_load_01B(): def test_usg_load_45usg(): print("testing 3-layer unstructured mfusg model loading: 45usg.nam") + + model_ws = f"{baseDir}_test_usg_load_45usg" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + pthusgtest = os.path.join("..", "examples", "data", "mfusg_test", "45usg") - fname = os.path.join(pthusgtest, "45usg.nam") + fname = os.path.abspath(os.path.join(pthusgtest, "45usg.nam")) assert os.path.isfile(fname), f"nam file not found {fname}" # Create the model - m = flopy.mfusg.MfUsg(modelname="45usg", verbose=True) + m = flopy.mfusg.MfUsg(modelname="45usg", verbose=True, model_ws=model_ws) # Load the model, with checking. - m = m.load(fname, check=True) + m = m.load(fname, check=True, model_ws=model_ws) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -196,78 +214,107 @@ def test_usg_load_45usg(): def test_usg_rch_evt_models01(): # this test has RCH nrchop == 1, and EVT nevtop == 1 print( - "testing unstructured mfusg RCH nrchop == 1, and EVT nevtop == 1: \ -usg_rch_evt.nam" + "testing unstructured mfusg RCH nrchop == 1, and " + "EVT nevtop == 1: usg_rch_evt.nam" ) + + new_ws = f"{baseDir}_test_usg_rch_evt_models01" + testFramework = flopyTest(verbose=True, testDirs=new_ws) + model_ws = os.path.join( "..", "examples", "data", "mfusg_test", "rch_evt_tests" ) nam = "usg_rch_evt.nam" m = flopy.mfusg.MfUsg.load(nam, model_ws=model_ws, exe_name=v) m.riv.check() - m.model_ws = tpth + + m.model_ws = new_ws m.write_input() if run: success, buff = m.run_model() assert success + return + def test_usg_rch_evt_models02(): # this test has RCH nrchop == 2, and EVT nevtop == 2 print( - "testing unstructured mfusg RCH nrchop == 2, and EVT nevtop == 2: \ -usg_rch_evt_nrchop2.nam" + "testing unstructured mfusg RCH nrchop == 2, " + "and EVT nevtop == 2: usg_rch_evt_nrchop2.nam" ) + + new_ws = f"{baseDir}_test_usg_rch_evt_models02" + testFramework = flopyTest(verbose=True, testDirs=new_ws) + model_ws = os.path.join( "..", "examples", "data", "mfusg_test", "rch_evt_tests" ) nam = "usg_rch_evt_nrchop2.nam" m = flopy.mfusg.MfUsg.load(nam, model_ws=model_ws, exe_name=v) - m.model_ws = tpth + + m.model_ws = new_ws m.write_input() if run: success, buff = m.run_model() assert success + return + def test_usg_rch_evt_models02a(): # this test has RCH nrchop == 2, and EVT nevtop == 2 print( - "testing unstructured mfusg RCH nrchop == 2, and EVT nevtop == 2,\ - but with fewer irch nodes: than in nodelay[0] usg_rch_evt_nrchop2.nam" + "testing unstructured mfusg RCH nrchop == 2, " + "and EVT nevtop == 2, but with fewer irch nodes: " + "than in nodelay[0] usg_rch_evt_nrchop2.nam" ) + + new_ws = f"{baseDir}_test_usg_rch_evt_models02a" + testFramework = flopyTest(verbose=True, testDirs=new_ws) + model_ws = os.path.join( "..", "examples", "data", "mfusg_test", "rch_evt_tests" ) nam = "usg_rch_evt_nrchop2a.nam" m = flopy.mfusg.MfUsg.load(nam, model_ws=model_ws, exe_name=v) - m.model_ws = tpth + + m.model_ws = new_ws m.write_input() if run: success, buff = m.run_model() assert success + return + def test_usg_ss_to_tr(): # Test switching steady model to transient # https://github.com/modflowpy/flopy/issues/1187 + + new_ws = f"{baseDir}_test_usg_ss_to_tr" + testFramework = flopyTest(verbose=True, testDirs=new_ws) + model_ws = os.path.join( "..", "examples", "data", "mfusg_test", "01A_nestedgrid_nognc" ) nam = "flow.nam" m = flopy.mfusg.MfUsg.load(nam, model_ws=model_ws, exe_name=v) - m.model_ws = tpth + + m.model_ws = new_ws m.disu.steady = [False] m.write_input() if run: success, buff = m.run_model() assert success - m = flopy.mfusg.MfUsg.load(nam, model_ws=tpth, exe_name=v) + m = flopy.mfusg.MfUsg.load(nam, model_ws=new_ws, exe_name=v) if run: success, buff = m.run_model() assert success + return + if __name__ == "__main__": test_usg_disu_load() diff --git a/autotest/t050_test.py b/autotest/t050_test.py index 2520c9966c..cf76f38d31 100644 --- a/autotest/t050_test.py +++ b/autotest/t050_test.py @@ -28,7 +28,7 @@ def test_vtk_export_array2d(): return ws = f"{baseDir}_array_2d_test" - fpTest = flopyTest(verbose=True, testDirs=ws) + testFramework = flopyTest(verbose=True, testDirs=ws) # test mf 2005 freyberg mpath = os.path.join( @@ -53,8 +53,6 @@ def test_vtk_export_array2d(): nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 17615 - fpTest.teardown() - def test_vtk_export_array3d(): try: @@ -63,7 +61,7 @@ def test_vtk_export_array3d(): return ws = f"{baseDir}_array_3d_test" - fpTest = flopyTest(verbose=True, testDirs=ws) + testFramework = flopyTest(verbose=True, testDirs=ws) # test mf 2005 freyberg mpath = os.path.join( @@ -105,8 +103,6 @@ def test_vtk_export_array3d(): filetocheck = os.path.join(ws, "hk_points_bin.vtk") assert os.path.exists(filetocheck) - fpTest.teardown() - def test_vtk_transient_array_2d(): try: @@ -114,7 +110,7 @@ def test_vtk_transient_array_2d(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # test mf 2005 freyberg mpath = os.path.join( @@ -128,7 +124,7 @@ def test_vtk_transient_array_2d(): load_only=["dis", "bas6", "rch"], ) ws = f"{baseDir}_transient_2d_test" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) kpers = [0, 1, 1096] @@ -143,7 +139,7 @@ def test_vtk_transient_array_2d(): # with binary ws = f"{baseDir}_transient_2d_test_bin" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) m.rch.rech.export(ws, fmt="vtk", binary=True, kpers=kpers) filetocheck = os.path.join(ws, "rech_000001.vtk") @@ -151,8 +147,6 @@ def test_vtk_transient_array_2d(): filetocheck = os.path.join(ws, "rech_001096.vtk") assert os.path.exists(filetocheck) - fpTest.teardown() - def test_vtk_export_packages(): try: @@ -160,7 +154,7 @@ def test_vtk_export_packages(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # test mf 2005 freyberg mpath = os.path.join( @@ -176,7 +170,7 @@ def test_vtk_export_packages(): # dis export and check ws = f"{baseDir}_DIS" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) # todo: pakbase.export() for vtk!!!! m.dis.export(ws, fmt="vtk", xml=True, binary=False) filetocheck = os.path.join(ws, "DIS.vtk") @@ -187,7 +181,7 @@ def test_vtk_export_packages(): # upw with point scalar output ws = f"{baseDir}_UPW" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) m.upw.export(ws, fmt="vtk", xml=True, binary=False, point_scalars=True) filetocheck = os.path.join(ws, "UPW.vtk") nlines1 = count_lines_in_file(filetocheck) @@ -195,7 +189,7 @@ def test_vtk_export_packages(): # bas with smoothing on ws = f"{baseDir}_BAS_SMOOTH" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) m.bas6.export(ws, fmt="vtk", binary=False, smooth=True) filetocheck = os.path.join(ws, "BAS6.vtk") nlines2 = count_lines_in_file(filetocheck) @@ -203,7 +197,7 @@ def test_vtk_export_packages(): # transient package drain ws = f"{baseDir}_DRN" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) kpers = [0, 1, 1096] m.drn.export(ws, fmt="vtk", binary=False, xml=True, kpers=kpers, pvd=True) filetocheck = os.path.join(ws, "DRN_000001.vtu") @@ -215,20 +209,18 @@ def test_vtk_export_packages(): # dis with binary ws = f"{baseDir}_DIS_BINARY" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) m.dis.export(ws, fmt="vtk", binary=True) filetocheck = os.path.join(ws, "DIS.vtk") assert os.path.exists(filetocheck) # upw with point scalars and binary ws = f"{baseDir}_UPW_BINARY" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) m.upw.export(ws, fmt="vtk", point_scalars=True, binary=True) filetocheck = os.path.join(ws, "UPW.vtk") assert os.path.exists(filetocheck) - fpTest.teardown() - def test_vtk_mf6(): try: @@ -236,7 +228,7 @@ def test_vtk_mf6(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # test mf6 mf6expth = os.path.join("..", "examples", "data", "mf6") @@ -257,7 +249,7 @@ def test_vtk_mf6(): print(mname) m = loaded_sim.get_model(mname) ws = f"{baseDir}_{m.name}" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) m.export(ws, fmt="vtk", binary=False) # check one @@ -269,8 +261,6 @@ def test_vtk_mf6(): nlines = count_lines_in_file(filetocheck) assert nlines == 9537 - fpTest.teardown() - def test_vtk_binary_head_export(): try: @@ -280,7 +270,7 @@ def test_vtk_binary_head_export(): # test mf 2005 freyberg from flopy.utils import HeadFile - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) mpth = os.path.join( "..", "examples", "data", "freyberg_multilayer_transient" @@ -295,7 +285,7 @@ def test_vtk_binary_head_export(): # export and check ws = f"{baseDir}_heads_test" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) vtkobj = Vtk(m, pvd=True, xml=True) vtkobj.add_heads( @@ -309,7 +299,7 @@ def test_vtk_binary_head_export(): # with point scalars ws = f"{baseDir}_heads_test_1" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) vtkobj = Vtk(m, pvd=True, xml=True, point_scalars=True) vtkobj.add_heads( @@ -323,7 +313,7 @@ def test_vtk_binary_head_export(): # with smoothing ws = f"{baseDir}_heads_test_2" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) vtkobj = Vtk(m, pvd=True, xml=True, smooth=True) vtkobj.add_heads( @@ -335,8 +325,6 @@ def test_vtk_binary_head_export(): nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 34 - fpTest.teardown() - def test_vtk_cbc(): try: @@ -344,7 +332,7 @@ def test_vtk_cbc(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # test mf 2005 freyberg from flopy.utils import CellBudgetFile @@ -362,7 +350,7 @@ def test_vtk_cbc(): # export and check with point scalar ws = f"{baseDir}_freyberg_CBC" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) vtkobj = Vtk(m, binary=False, xml=True, pvd=True, point_scalars=True) vtkobj.add_cell_budget(cbc, kstpkper=[(0, 0), (0, 1), (0, 2)]) @@ -374,7 +362,7 @@ def test_vtk_cbc(): # with point scalars and binary ws = f"{baseDir}_freyberg_CBC_binary" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) vtkobj = Vtk(m, xml=True, pvd=True, point_scalars=True) vtkobj.add_cell_budget(cbc, kstpkper=[(0, 0), (0, 1), (0, 2)]) @@ -382,8 +370,6 @@ def test_vtk_cbc(): filetocheck = os.path.join(ws, filenametocheck) assert os.path.exists(filetocheck) - fpTest.teardown() - def test_vtk_vector(): try: @@ -394,7 +380,7 @@ def test_vtk_vector(): from flopy.utils import postprocessing as pp from flopy.utils import HeadFile, CellBudgetFile - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # test mf 2005 freyberg mpth = os.path.join( @@ -417,7 +403,7 @@ def test_vtk_vector(): # export and check with point scalar ws = f"{baseDir}_vector_0" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) vtkobj = Vtk(m, xml=True, binary=False, point_scalars=True) vtkobj.add_vector(q, "discharge") @@ -429,7 +415,7 @@ def test_vtk_vector(): # with point scalars and binary ws = f"{baseDir}_vector_0_binary" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) vtkobj = Vtk(m, point_scalars=True) vtkobj.add_vector(q, "discharge") @@ -443,7 +429,7 @@ def test_vtk_vector(): q = pp.get_specific_discharge(vectors, m, head) ws = f"{baseDir}_vector_1" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) filenametocheck = "discharge_verts.vtu" vtkobj = Vtk(m, xml=True, binary=False) @@ -455,7 +441,7 @@ def test_vtk_vector(): assert nlines2 == 27645, f"nlines != 10598 ({nlines2})" ws = f"{baseDir}_vector_1_binary" - fpTest.addTestDir(ws, create=True) + testFramework.addTestDir(ws, create=True) # with values directly given at vertices and binary vtkobj = Vtk(m, xml=True, binary=False) @@ -467,8 +453,6 @@ def test_vtk_vector(): filetocheck ), f"file (1) does not exist: {filetocheck}" - fpTest.teardown() - def test_vtk_unstructured(): try: @@ -477,7 +461,7 @@ def test_vtk_unstructured(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) def load_verts(fname): verts = np.genfromtxt( @@ -541,7 +525,7 @@ def load_iverts(fname): ) ws = f"{baseDir}_unstructured" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) outfile = os.path.join(ws, "disu_grid.vtu") vtkobj = Vtk( @@ -566,8 +550,6 @@ def load_iverts(fname): if not np.allclose(np.ravel(top), top2): raise AssertionError("Field data not properly written") - fpTest.teardown() - def test_vtk_vertex(): try: @@ -576,7 +558,7 @@ def test_vtk_vertex(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # disv test workspace = os.path.join( @@ -587,7 +569,7 @@ def test_vtk_vertex(): gwf = sim.get_model("gwf_1") ws = f"{baseDir}_vertex" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) outfile = os.path.join(ws, "disv.vtk") vtkobj = Vtk(model=gwf, binary=True, smooth=False) @@ -612,8 +594,6 @@ def test_vtk_vertex(): if not np.allclose(np.ravel(hk), hk2, equal_nan=True): raise AssertionError("Field data not properly written") - fpTest.teardown() - def test_vtk_pathline(): try: @@ -622,7 +602,7 @@ def test_vtk_pathline(): except ImportError: return - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) # pathline test for vtk ws = os.path.join("..", "examples", "data", "freyberg") @@ -631,7 +611,7 @@ def test_vtk_pathline(): ) ws = f"{baseDir}_pathline" - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) ml.change_model_ws(new_pth=ws) ml.write_input() @@ -696,8 +676,6 @@ def test_vtk_pathline(): "number of particles are incorrect for modpath VTK" ) - fpTest.teardown() - if __name__ == "__main__": test_vtk_export_array2d() diff --git a/autotest/t064_test_performance.py b/autotest/t064_test_performance.py index 694f7b8393..8a56b6c9cc 100644 --- a/autotest/t064_test_performance.py +++ b/autotest/t064_test_performance.py @@ -4,9 +4,14 @@ import os import sys import shutil +import random +import string import time import numpy as np import flopy.modflow as fm +from ci_framework import baseTestDir + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) class TestModflowPerformance: @@ -24,8 +29,11 @@ def setup_class(cls): nper = 10 nsfr = int((size ** 2) / 5) + letters = string.ascii_lowercase + prepend = "".join(random.choice(letters) for i in range(10)) + cls.modelname = "junk" - cls.model_ws = "temp/t064" + cls.model_ws = f"{baseDir}_{prepend}" external_path = "external/" if not os.path.isdir(cls.model_ws): @@ -109,6 +117,7 @@ def test_9_load_time(self): """test model load time""" print("loading model...") mfp = TestModflowPerformance() + mfp.m.write_input() target = 3 t0 = time.time() m = fm.Modflow.load( @@ -122,5 +131,5 @@ def test_9_load_time(self): @classmethod def teardown_class(cls): - # cleanup + shutil.rmtree(cls.model_ws) diff --git a/autotest/t067_test_ulstrd.py b/autotest/t067_test_ulstrd.py index 454a9d8353..0f8eab251a 100644 --- a/autotest/t067_test_ulstrd.py +++ b/autotest/t067_test_ulstrd.py @@ -1,17 +1,17 @@ import os import numpy as np import flopy +from ci_framework import baseTestDir, flopyTest -tpth = os.path.join("temp", "t067") -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_ulstrd(): + model_ws = f"{baseDir}_test_ulstrd" + testFramework = flopyTest(verbose=True, testDirs=model_ws) # Create an original model and then manually modify to use # advanced list reader capabilities - ws = tpth nlay = 1 nrow = 10 ncol = 10 @@ -40,7 +40,9 @@ def test_ulstrd(): welspd = {0: welra} m = flopy.modflow.Modflow( - modelname="original", model_ws=ws, exe_name="mf2005" + modelname="original", + model_ws=model_ws, + exe_name="mf2005", ) dis = flopy.modflow.ModflowDis( m, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper @@ -57,7 +59,7 @@ def test_ulstrd(): m.write_input() # rewrite ghb - fname = os.path.join(ws, "original.ghb") + fname = os.path.join(model_ws, "original.ghb") with open(fname, "w") as f: f.write(f"{ghbra.shape[0]} 0\n") for kper in range(nper): @@ -66,14 +68,14 @@ def test_ulstrd(): # write ghb list sfacghb = 5 - fname = os.path.join(ws, "original.ghb.dat") + fname = os.path.join(model_ws, "original.ghb.dat") with open(fname, "w") as f: f.write(f"sfac {sfacghb}\n") for k, i, j, stage, cond in ghbra: f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite drn - fname = os.path.join(ws, "original.drn") + fname = os.path.join(model_ws, "original.drn") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -82,7 +84,7 @@ def test_ulstrd(): # write drn list sfacdrn = 1.5 - fname = os.path.join(ws, "original.drn.dat") + fname = os.path.join(model_ws, "original.drn.dat") with open(fname, "w") as f: for kper in range(nper): f.write(f"sfac {sfacdrn}\n") @@ -90,7 +92,7 @@ def test_ulstrd(): f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite wel - fname = os.path.join(ws, "original.wel") + fname = os.path.join(model_ws, "original.wel") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -110,7 +112,7 @@ def test_ulstrd(): welra = np.recarray(2, dtype=weldt) welra[0] = (1, 2, 2, -5.0) welra[1] = (1, nrow - 2, ncol - 2, -10.0) - fname = os.path.join(ws, "original.wel.bin") + fname = os.path.join(model_ws, "original.wel.bin") with open(fname, "wb") as f: welra.tofile(f) welra.tofile(f) @@ -123,7 +125,7 @@ def test_ulstrd(): # the m2 model will load all of these external files, possibly using sfac # and just create regular list input files for wel, drn, and ghb fname = "original.nam" - m2 = flopy.modflow.Modflow.load(fname, model_ws=ws, verbose=False) + m2 = flopy.modflow.Modflow.load(fname, model_ws=model_ws, verbose=False) m2.name = "new" m2.write_input() diff --git a/autotest/t068_test_ssm.py b/autotest/t068_test_ssm.py index 75d3b5fba3..02ef5295ee 100644 --- a/autotest/t068_test_ssm.py +++ b/autotest/t068_test_ssm.py @@ -5,6 +5,9 @@ import os import flopy import numpy as np +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) mf_exe_name = "mf2005" mt_exe_name = "mt3dms" @@ -16,6 +19,8 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(): + model_ws = f"{baseDir}_test_mt3d_ssm_with_nodata_in_1st_sp" + testFramework = flopyTest(verbose=True, testDirs=model_ws) nlay, nrow, ncol = 3, 5, 5 perlen = np.zeros((10), dtype=float) + 10 @@ -27,10 +32,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(): top = 0.0 # creating MODFLOW model - - model_ws = os.path.join(".", "temp", "t068a") modelname = "model_mf" - mf = flopy.modflow.Modflow( modelname, model_ws=model_ws, exe_name=mf_exe_name ) @@ -113,7 +115,9 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(): ) assert success, "MT3D did not run" - model_ws2 = os.path.join(".", "temp", "t068b") + model_ws2 = f"{baseDir}_test_mt3d_ssm_with_nodata_in_1st_sp_b" + testFramework.addTestDir(model_ws2) + mf2 = flopy.modflow.Modflow.load( "model_mf.nam", model_ws=model_ws, exe_name="mf2005" ) @@ -147,7 +151,10 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(): def test_none_spdtype(): # ensure that -1 and None work as valid list entries in the # stress period dictionary - model_ws = os.path.join(".", "temp", "t068c") + + model_ws = f"{baseDir}_test_none_spdtyp" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + mf = flopy.modflow.Modflow(model_ws=model_ws, exe_name=mf_exe_name) dis = flopy.modflow.ModflowDis(mf, nper=2) bas = flopy.modflow.ModflowBas(mf) @@ -165,6 +172,8 @@ def test_none_spdtype(): def test_ssm_readwrite(): + model_ws = f"{baseDir}_test_ssm_readwrite" + testFramework = flopyTest(verbose=True, testDirs=model_ws) # Instantiate MODFLOW model mf = flopy.modflow.Modflow() @@ -189,19 +198,11 @@ def test_ssm_readwrite(): # (file comes from: https://github.com/modflowpy/flopy/issues/743) ssm = flopy.mt3d.Mt3dSsm.load(fl, mt) - # Change to dedicated work directory - cwd = os.getcwd() - if not os.path.isdir(os.path.join("temp", "t068_ssm_write")): - os.makedirs(os.path.join("temp", "t068_ssm_write"), exist_ok=True) - - os.chdir(os.path.join("temp", "t068_ssm_write")) + mt.change_model_ws(model_ws) # Ensure file is writeable ssm.write_file() - # Return to starting directory - os.chdir(cwd) - if __name__ == "__main__": test_mt3d_ssm_with_nodata_in_1st_sp() diff --git a/autotest/t069_test_vtkexportmodel.py b/autotest/t069_test_vtkexportmodel.py index 0ccae6dab4..c2fc612c1f 100644 --- a/autotest/t069_test_vtkexportmodel.py +++ b/autotest/t069_test_vtkexportmodel.py @@ -2,7 +2,6 @@ Test vtk export_model function without packages_names definition """ -import os import flopy from flopy.export import vtk from ci_framework import ( @@ -15,7 +14,7 @@ def test_vtk_export_model_without_packages_names(): baseDir = baseTestDir(__file__, relPath="temp", verbose=True) - fpTest = flopyTest(verbose=True, testDirs=baseDir) + testFramework = flopyTest(verbose=True, testDirs=baseDir) name = "mymodel" sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=baseDir, exe_name="mf6") @@ -35,8 +34,6 @@ def test_vtk_export_model_without_packages_names(): # If the function executes without error then test was successful assert True - fpTest.teardown() - if __name__ == "__main__": test_vtk_export_model_without_packages_names() diff --git a/autotest/t070_test_quasi3layers.py b/autotest/t070_test_quasi3layers.py index 3fa8bfc001..135f4be040 100644 --- a/autotest/t070_test_quasi3layers.py +++ b/autotest/t070_test_quasi3layers.py @@ -11,6 +11,9 @@ import numpy as np import flopy import matplotlib.pyplot as plt +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_plotting_with_quasi3d_layers(): @@ -21,9 +24,12 @@ def test_plotting_with_quasi3d_layers(): runTest = False if runTest: + model_ws = f"{baseDir}_test_mfusg" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + modelname = "model_mf" - model_ws = os.path.join(".", "temp", "t070") exe_name = "mf2005" + mf = flopy.modflow.Modflow( modelname, model_ws=model_ws, exe_name=exe_name ) @@ -107,6 +113,7 @@ def test_plotting_with_quasi3d_layers(): mv.plot_ibound() mv.plot_bc("wel") mv.plot_vector(frf, fff) + plt.savefig(os.path.join(model_ws, "plt01.png")) plt.close() # plot a cross-section @@ -120,6 +127,7 @@ def test_plotting_with_quasi3d_layers(): cs.plot_ibound() cs.plot_bc("wel") cs.plot_vector(frf, fff, flf, head=head) + plt.savefig(os.path.join(model_ws, "plt02.png")) plt.close() diff --git a/autotest/t071_test_nwt_ag.py b/autotest/t071_test_nwt_ag.py index ac31a9ffce..46b957014b 100644 --- a/autotest/t071_test_nwt_ag.py +++ b/autotest/t071_test_nwt_ag.py @@ -1,14 +1,11 @@ import os import flopy -import platform -import shutil import numpy as np - +from ci_framework import baseTestDir, flopyTest mpth = os.path.join("..", "examples", "data", "ag_test") -opth = os.path.join("temp", "t071") -if not os.path.isdir(opth): - os.makedirs(opth, exist_ok=True) + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_empty_ag_package(): @@ -20,6 +17,9 @@ def test_empty_ag_package(): def test_load_write_agwater(): + model_ws = f"{baseDir}_test_load_write_agwater" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + agfile = "Agwater1.ag" ml = flopy.modflow.Modflow("Agwater1", version="mfnwt") ag1 = flopy.modflow.ModflowAg.load( @@ -35,12 +35,16 @@ def test_load_write_agwater(): if not loaded: raise AssertionError("ModflowAg package not loaded") - ml.change_model_ws(opth) + ml.change_model_ws(model_ws) ag1.write_file() - ml2 = flopy.modflow.Modflow("Agwater1", version="mfnwt", model_ws=opth) + ml2 = flopy.modflow.Modflow( + "Agwater1", + version="mfnwt", + model_ws=model_ws, + ) ag2 = flopy.modflow.ModflowAg.load( - os.path.join(opth, agfile), ml2, nper=49 + os.path.join(model_ws, agfile), ml2, nper=49 ) if repr(ag1) != repr(ag2): @@ -48,6 +52,9 @@ def test_load_write_agwater(): def test_load_write_agwater_uzf(): + model_ws = f"{baseDir}_test_load_write_agwater_uzf" + testFramework = flopyTest(verbose=True, testDirs=model_ws) + uzffile = "Agwater1.uzf" ml = flopy.modflow.Modflow("Agwater1", version="mfnwt") dis = flopy.modflow.ModflowDis(ml, nlay=1, nrow=15, ncol=10, nper=49) @@ -62,12 +69,16 @@ def test_load_write_agwater_uzf(): if not loaded: raise AssertionError("ModflowUzf1 package not loaded") - ml.change_model_ws(opth) + ml.change_model_ws(model_ws) uzf1.write_file() - ml2 = flopy.modflow.Modflow("Agwater1", version="mfnwt", model_ws=opth) + ml2 = flopy.modflow.Modflow( + "Agwater1", + version="mfnwt", + model_ws=model_ws, + ) dis2 = flopy.modflow.ModflowDis(ml2, nlay=1, nrow=15, ncol=10, nper=49) - uzf2 = flopy.modflow.ModflowUzf1.load(os.path.join(opth, uzffile), ml2) + uzf2 = flopy.modflow.ModflowUzf1.load(os.path.join(model_ws, uzffile), ml2) if not np.allclose(uzf1.air_entry.array, uzf2.air_entry.array): raise AssertionError("Air entry pressure array comparison failed") diff --git a/autotest/t072_test_spedis.py b/autotest/t072_test_spedis.py index a76f14f739..51e1d40e08 100644 --- a/autotest/t072_test_spedis.py +++ b/autotest/t072_test_spedis.py @@ -16,13 +16,17 @@ import os import numpy as np import flopy.utils.binaryfile as bf +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) # model names, file names and locations -modelname_mf2005 = "t070_mf2005" -modelname_mf6 = "t070_mf6" -postproc_test_ws = os.path.join(".", "temp", "t072") -modelws_mf2005 = os.path.join(postproc_test_ws, modelname_mf2005) -modelws_mf6 = os.path.join(postproc_test_ws, modelname_mf6) +modelname_mf2005 = f"mf2005" +modelname_mf6 = f"mf6" + +modelws_mf2005 = f"{baseDir}_{modelname_mf2005}" +modelws_mf6 = f"{baseDir}_{modelname_mf6}" + cbcfile_mf2005 = os.path.join(modelws_mf2005, f"{modelname_mf2005}.cbc") cbcfile_mf6 = os.path.join(modelws_mf6, f"{modelname_mf6}.cbc") hdsfile_mf2005 = os.path.join(modelws_mf2005, f"{modelname_mf2005}.hds") @@ -102,11 +106,6 @@ def build_model_mf2005(): - - # create folders - if not os.path.isdir(modelws_mf2005): - os.makedirs(modelws_mf2005, exist_ok=True) - # create modflow model mf = flopy.modflow.Modflow( modelname_mf2005, model_ws=modelws_mf2005, exe_name="mf2005" @@ -180,10 +179,6 @@ def build_model_mf2005(): def build_model_mf6(): - - if not os.path.isdir(modelws_mf6): - os.makedirs(modelws_mf6, exist_ok=True) - # create simulation simname = modelname_mf6 sim = flopy.mf6.MFSimulation( @@ -357,6 +352,8 @@ def local_balance_check(Qx_ext, Qy_ext, Qz_ext, hdsfile=None, model=None): def test_extended_budget_default(): + testFramework = flopyTest(verbose=True, testDirs=modelws_mf2005) + # build and run MODFLOW 2005 model build_model_mf2005() @@ -371,10 +368,15 @@ def test_extended_budget_default(): # overall check overall = np.sum(Qx_ext) + np.sum(Qy_ext) + np.sum(Qz_ext) assert np.allclose(overall, -1122.4931640625) + + # call other evaluations + specific_discharge_default() + specific_discharge_comprehensive() + return -def test_extended_budget_comprehensive(): +def extended_budget_comprehensive(): # load and postprocess mf = flopy.modflow.Modflow.load(namfile_mf2005, check=False) Qx_ext, Qy_ext, Qz_ext = flopy.utils.postprocessing.get_extended_budget( @@ -396,7 +398,7 @@ def test_extended_budget_comprehensive(): return -def test_specific_discharge_default(): +def specific_discharge_default(): # load and postprocess mf = flopy.modflow.Modflow.load(namfile_mf2005, check=False) cbc = bf.CellBudgetFile(cbcfile_mf2005) @@ -410,7 +412,7 @@ def test_specific_discharge_default(): return -def test_specific_discharge_comprehensive(): +def specific_discharge_comprehensive(): import matplotlib.pyplot as plt from matplotlib.quiver import Quiver @@ -501,6 +503,8 @@ def test_specific_discharge_mf6(): import matplotlib.pyplot as plt from matplotlib.quiver import Quiver + testFramework = flopyTest(verbose=True, testDirs=modelws_mf6) + # build and run MODFLOW 6 model build_model_mf6() @@ -572,11 +576,12 @@ def test_specific_discharge_mf6(): # close figure plt.close() + return if __name__ == "__main__": - test_extended_budget_default() + extended_budget_default() test_extended_budget_comprehensive() test_specific_discharge_default() test_specific_discharge_comprehensive() diff --git a/autotest/t075_test_ugrid.py b/autotest/t075_test_ugrid.py index 03e0297d2f..12d2881957 100644 --- a/autotest/t075_test_ugrid.py +++ b/autotest/t075_test_ugrid.py @@ -8,10 +8,9 @@ from flopy.discretization import UnstructuredGrid, VertexGrid from flopy.utils.triangle import Triangle from flopy.utils.voronoi import VoronoiGrid +from ci_framework import baseTestDir, flopyTest -tpth = os.path.join("temp", "t075") -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_unstructured_grid_shell(): @@ -209,6 +208,9 @@ def load_iverts(fname): def test_triangle_unstructured_grid(): + model_ws = f"{baseDir}_test_triangle_unstructured_grid" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + maximum_area = 30000.0 extent = (214270.0, 221720.0, 4366610.0, 4373510.0) domainpoly = [ @@ -217,7 +219,11 @@ def test_triangle_unstructured_grid(): (extent[1], extent[3]), (extent[0], extent[3]), ] - tri = Triangle(maximum_area=maximum_area, angle=30, model_ws=tpth) + tri = Triangle( + maximum_area=maximum_area, + angle=30, + model_ws=model_ws, + ) tri.add_polygon(domainpoly) tri.build(verbose=False) verts = [[iv, x, y] for iv, (x, y) in enumerate(tri.verts)] @@ -233,16 +239,20 @@ def test_triangle_unstructured_grid(): ) assert len(g.grid_lines) == 8190 assert g.nnodes == g.ncpl == 2730 + return def test_voronoi_vertex_grid(): + model_ws = f"{baseDir}_test_voronoi_vertex_grid" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + xmin = 0.0 xmax = 2.0 ymin = 0.0 ymax = 1.0 area_max = 0.05 - tri = Triangle(maximum_area=area_max, angle=30, model_ws=tpth) + tri = Triangle(maximum_area=area_max, angle=30, model_ws=model_ws) poly = np.array(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax))) tri.add_polygon(poly) tri.build(verbose=False) @@ -260,10 +270,13 @@ def test_voronoi_vertex_grid(): assert gridprops["nvert"] == 127 assert len(gridprops["vertices"]) == 127 assert len(gridprops["cell2d"]) == 43 + return def test_voronoi_grid0(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid0" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor0" answer_ncpl = 3804 @@ -288,7 +301,7 @@ def test_voronoi_grid0(plot=False): [1831.381546, 6335.543757], ] area_max = 100.0 ** 2 - tri = Triangle(maximum_area=area_max, angle=30, model_ws=tpth) + tri = Triangle(maximum_area=area_max, angle=30, model_ws=model_ws) poly = np.array(domain) tri.add_polygon(poly) tri.build(verbose=False) @@ -309,12 +322,14 @@ def test_voronoi_grid0(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return def test_voronoi_grid1(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid1" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor1" answer_ncpl = 1679 @@ -323,7 +338,7 @@ def test_voronoi_grid1(plot=False): ymin = 0.0 ymax = 1.0 area_max = 0.001 - tri = Triangle(maximum_area=area_max, angle=30, model_ws=tpth) + tri = Triangle(maximum_area=area_max, angle=30, model_ws=model_ws) poly = np.array(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax))) tri.add_polygon(poly) tri.build(verbose=False) @@ -343,12 +358,14 @@ def test_voronoi_grid1(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return def test_voronoi_grid2(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid2" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor2" answer_ncpl = 538 @@ -357,7 +374,7 @@ def test_voronoi_grid2(plot=False): x = radius * np.cos(theta) y = radius * np.sin(theta) circle_poly = [(x, y) for x, y in zip(x, y)] - tri = Triangle(maximum_area=50, angle=30, model_ws=tpth) + tri = Triangle(maximum_area=50, angle=30, model_ws=model_ws) tri.add_polygon(circle_poly) tri.build(verbose=False) @@ -376,12 +393,14 @@ def test_voronoi_grid2(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return def test_voronoi_grid3(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid3" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor3" answer_ncpl = 300 @@ -398,7 +417,7 @@ def test_voronoi_grid3(plot=False): y = radius * np.sin(theta) + 25.0 inner_circle_poly = [(x, y) for x, y in zip(x, y)] - tri = Triangle(maximum_area=100, angle=30, model_ws=tpth) + tri = Triangle(maximum_area=100, angle=30, model_ws=model_ws) tri.add_polygon(circle_poly) tri.add_polygon(inner_circle_poly) tri.add_hole((25, 25)) @@ -419,19 +438,21 @@ def test_voronoi_grid3(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return def test_voronoi_grid4(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid4" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor4" answer_ncpl = 410 active_domain = [(0, 0), (100, 0), (100, 100), (0, 100)] area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(60, 60), (80, 60), (80, 80), (60, 80)] - tri = Triangle(angle=30, model_ws=tpth) + tri = Triangle(angle=30, model_ws=model_ws) tri.add_polygon(active_domain) tri.add_polygon(area1) tri.add_polygon(area2) @@ -455,12 +476,14 @@ def test_voronoi_grid4(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return def test_voronoi_grid5(plot=False): + model_ws = f"{baseDir}_test_voronoi_grid5" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) name = "vor5" answer_ncpl = 1067 @@ -468,7 +491,7 @@ def test_voronoi_grid5(plot=False): area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(50, 50), (90, 50), (90, 90), (50, 90)] - tri = Triangle(angle=30, model_ws=tpth) + tri = Triangle(angle=30, model_ws=model_ws) # requirement that active_domain is first polygon to be added tri.add_polygon(active_domain) @@ -519,7 +542,7 @@ def test_voronoi_grid5(plot=False): ax = fig.add_subplot() ax.set_aspect("equal") voronoi_grid.plot(ax=ax) - plt.savefig(os.path.join(tpth, f"{name}.png")) + plt.savefig(os.path.join(model_ws, f"{name}.png")) return diff --git a/autotest/t078_test_lake_connections.py b/autotest/t078_test_lake_connections.py index 77d369cf26..cb86485ba1 100644 --- a/autotest/t078_test_lake_connections.py +++ b/autotest/t078_test_lake_connections.py @@ -1,14 +1,12 @@ import os import numpy as np import flopy +from ci_framework import baseTestDir, flopyTest pth = os.path.join("..", "examples", "data", "mf6-freyberg") name = "freyberg" -tpth = os.path.join("temp", "t078") -# make the directory if it does not exist -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def __export_ascii_grid(modelgrid, file_path, v, nodata=0.0): @@ -125,14 +123,16 @@ def __get_lake_connection_data( def test_base_run(): + model_ws = f"{baseDir}_test_base_run" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + sim = flopy.mf6.MFSimulation().load( sim_name=name, sim_ws=pth, exe_name="mf6", verbosity_level=0, ) - ws = os.path.join(tpth, "freyberg") - sim.set_sim_path(ws) + sim.set_sim_path(model_ws) # remove the well package gwf = sim.get_model("freyberg") @@ -147,20 +147,20 @@ def test_base_run(): bot = gwf.dis.botm.array.squeeze() __export_ascii_grid( gwf.modelgrid, - os.path.join(ws, "bot.asc"), + os.path.join(pth, "bot.asc"), bot, ) top = gwf.output.head().get_data().squeeze() + 2.0 top = np.where(gwf.dis.idomain.array.squeeze() < 1.0, 0.0, top) __export_ascii_grid( gwf.modelgrid, - os.path.join(ws, "top.asc"), + os.path.join(pth, "top.asc"), top, ) k11 = gwf.npf.k.array.squeeze() __export_ascii_grid( gwf.modelgrid, - os.path.join(ws, "k11.asc"), + os.path.join(pth, "k11.asc"), k11, ) @@ -168,18 +168,23 @@ def test_base_run(): def test_lake(): - ws = os.path.join(tpth, "freyberg") - top = flopy.utils.Raster.load(os.path.join(ws, "top.asc")) - bot = flopy.utils.Raster.load(os.path.join(ws, "bot.asc")) - k11 = flopy.utils.Raster.load(os.path.join(ws, "k11.asc")) + model_ws = f"{baseDir}_test_lake" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + + top = flopy.utils.Raster.load(os.path.join(pth, "top.asc")) + bot = flopy.utils.Raster.load(os.path.join(pth, "bot.asc")) + k11 = flopy.utils.Raster.load(os.path.join(pth, "k11.asc")) sim = flopy.mf6.MFSimulation().load( sim_name=name, - sim_ws=ws, + sim_ws=pth, exe_name="mf6", verbosity_level=0, ) + # change the workspace + sim.set_sim_path(model_ws) + # get groundwater flow model gwf = sim.get_model("freyberg") @@ -289,6 +294,9 @@ def test_lake(): def test_embedded_lak_ex01(): + model_ws = f"{baseDir}_test_embedded_lak_ex01" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + nper = 1 nlay, nrow, ncol = 5, 17, 17 shape3d = (nlay, nrow, ncol) @@ -379,11 +387,10 @@ def test_embedded_lak_ex01(): chd_spd = {0: chd_spd} name = "lak_ex01" - ws = os.path.join(tpth, "lak_ex01") sim = flopy.mf6.MFSimulation( sim_name=name, exe_name="mf6", - sim_ws=ws, + sim_ws=model_ws, ) tdis = flopy.mf6.ModflowTdis( sim, @@ -491,6 +498,8 @@ def test_embedded_lak_ex01(): assert success, f"could not run {sim.name}" + return + def test_embedded_lak_prudic(): lakebed_leakance = 1.0 # Lakebed leakance ($ft^{-1}$) diff --git a/autotest/t079_test_cbc_full3D.py b/autotest/t079_test_cbc_full3D.py index 45893f3c86..a6ad07e93a 100644 --- a/autotest/t079_test_cbc_full3D.py +++ b/autotest/t079_test_cbc_full3D.py @@ -1,11 +1,12 @@ import os import sys -import shutil import pytest import numpy as np import flopy +from ci_framework import baseTestDir, flopyTest + ex_pths = ( os.path.join("..", "examples", "data", "freyberg"), os.path.join("..", "examples", "data", "mf6-freyberg"), @@ -15,19 +16,16 @@ ismf6_lst = ["mf6" in pth for pth in ex_pths] names = [os.path.basename(pth) for pth in ex_pths] -tpth = os.path.join("temp", "t079") -# make the directory if it does not exist -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - mf6_exe = "mf6" mf2005_exe = "mf2005" if sys.platform == "win32": mf6_exe += ".exe" mf2005_exe += ".exe" +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) -def load_mf2005(name, ws_in): + +def load_mf2005(name, ws_in, ws_out): name_file = f"{name}.nam" ml = flopy.modflow.Modflow.load( name_file, @@ -37,7 +35,7 @@ def load_mf2005(name, ws_in): ) # change work space - ws_out = os.path.join(tpth, name) + # ws_out = os.path.join(baseDir, name) ml.change_model_ws(ws_out) # save all budget data to a cell-by cell file @@ -48,7 +46,7 @@ def load_mf2005(name, ws_in): return ml -def load_mf6(name, ws_in): +def load_mf6(name, ws_in, ws_out): sim = flopy.mf6.MFSimulation.load( sim_name=name, exe_name=mf6_exe, @@ -56,7 +54,6 @@ def load_mf6(name, ws_in): ) # change work space - ws_out = os.path.join(tpth, name) sim.set_sim_path(ws_out) # get the groundwater flow model(s) and redefine the output control @@ -128,15 +125,11 @@ def cbc_eval(cbcobj, nnodes, shape3d, modelgrid): return -def clean_run(name): - ws = os.path.join(tpth, name) - if os.path.isdir(ws): - shutil.rmtree(ws) - - def mf6_eval(name, ws_in): + ws_out = f"{baseDir}_{name}" + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) - sim = load_mf6(name, ws_in) + sim = load_mf6(name, ws_in, ws_out) # write the simulation sim.write_simulation() @@ -155,14 +148,14 @@ def mf6_eval(name, ws_in): # evaluate the full3D option cbc_eval(cbc, nnodes, shape3d, gwf.modelgrid) - # clean the run - clean_run(name) - return def mf2005_eval(name, ws_in): - ml = load_mf2005(name, ws_in) + ws_out = f"{baseDir}_{name}" + testFramework = flopyTest(verbose=True, testDirs=ws_out, create=True) + + ml = load_mf2005(name, ws_in, ws_out) # write the model ml.write_input() @@ -174,14 +167,13 @@ def mf2005_eval(name, ws_in): nnodes, shape3d = ml.modelgrid.nnodes, ml.modelgrid.shape # get the cell by cell object - fpth = os.path.join(tpth, name, f"{name}.cbc") + fpth = os.path.join(ws_out, f"{name}.cbc") cbc = flopy.utils.CellBudgetFile(fpth) # evaluate the full3D option cbc_eval(cbc, nnodes, shape3d, ml.modelgrid) - # clean the run - clean_run(name) + return @pytest.mark.parametrize( diff --git a/autotest/t080_test.py b/autotest/t080_test.py index 8b700cd52e..2e9fcf3410 100644 --- a/autotest/t080_test.py +++ b/autotest/t080_test.py @@ -3,10 +3,7 @@ """ import os -import sys import platform -import shutil -import numpy as np try: from shapely.geometry import Polygon @@ -17,6 +14,7 @@ import flopy from flopy.utils.gridgen import Gridgen +from ci_framework import baseTestDir, flopyTest # Set gridgen executable gridgen_exe = "gridgen" @@ -31,18 +29,13 @@ mfusg_exe = flopy.which(mfusg_exe) # set up the example folder -test_number = "t080" -tpth = os.path.join("temp", test_number) -if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_mfusg(): - # set up a gridgen workspace - gridgen_ws = os.path.join(tpth, f"gridgen_{test_number}") - if not os.path.isdir(gridgen_ws): - os.makedirs(gridgen_ws, exist_ok=True) + gridgen_ws = f"{baseDir}_test_mfusg" + testFramework = flopyTest(verbose=True, testDirs=gridgen_ws) name = "dummy" nlay = 3 @@ -83,11 +76,10 @@ def test_mfusg(): gridprops = g.get_gridprops_disu5() # create the mfusg modoel - ws = os.path.join(tpth, "gridgen_mfusg") name = "mymodel" m = flopy.mfusg.MfUsg( modelname=name, - model_ws=ws, + model_ws=gridgen_ws, exe_name=mfusg_exe, structured=False, ) @@ -110,7 +102,7 @@ def test_mfusg(): m.run_model() # head is returned as a list of head arrays for each layer - head_file = os.path.join(ws, f"{name}.hds") + head_file = os.path.join(gridgen_ws, f"{name}.hds") head = flopy.utils.HeadUFile(head_file).get_data() # test if single node idx works @@ -130,6 +122,9 @@ def test_mfusg(): "Error head from 'get_ts' != head from 'get_data'" ) + # + # + return diff --git a/autotest/t501_test.py b/autotest/t501_test.py index 978f7e37d8..e2b5cd45c1 100644 --- a/autotest/t501_test.py +++ b/autotest/t501_test.py @@ -7,7 +7,7 @@ def test_mf6(): baseDir = baseTestDir(__file__, relPath="temp", verbose=True) - fpTest = flopyTest(verbose=True, testDirs=baseDir) + testFramework = flopyTest(verbose=True, testDirs=baseDir) sim = flopy.mf6.MFSimulation(sim_ws=baseDir) assert isinstance(sim, flopy.mf6.MFSimulation) @@ -130,8 +130,6 @@ def test_mf6(): fname = os.path.join(baseDir, f"sim.{ext}") assert os.path.isfile(fname), f"{fname} not found" - fpTest.teardown() - return diff --git a/autotest/t502_test.py b/autotest/t502_test.py index c2d9f5373d..d11aed6a41 100644 --- a/autotest/t502_test.py +++ b/autotest/t502_test.py @@ -12,7 +12,7 @@ def test_create_and_run_model(): - fpTest = flopyTest(verbose=True, testDirs=baseDir) + testFramework = flopyTest(verbose=True, testDirs=baseDir) # names sim_name = "testsim" @@ -144,8 +144,6 @@ def test_create_and_run_model(): # head = sim.simulation_data.mfdata[(model_name, 'HDS', 'HEAD')] # print('HEAD: ', head) - fpTest.teardown() - return diff --git a/autotest/t503_test.py b/autotest/t503_test.py index a388b6929c..c4f5e7092e 100644 --- a/autotest/t503_test.py +++ b/autotest/t503_test.py @@ -74,12 +74,12 @@ def runmodel(exdir): + "_" + os.path.basename(exdir) ) - fpTest = flopyTest(verbose=True) + testFramework = flopyTest(verbose=True) simulations = simulation_subdirs(exdir) for src in simulations: ws = copy_folder(baseDir, src) - fpTest.addTestDir(ws) + testFramework.addTestDir(ws) f = os.path.basename(os.path.normpath(ws)) print("\n\n") print(f"**** RUNNING TEST: {f} ****") @@ -101,7 +101,7 @@ def runmodel(exdir): # set the comparison directory ws2 = f"{ws}-RERUN" - fpTest.addTestDir(ws2) + testFramework.addTestDir(ws2) sim.simulation_data.mfpath.set_sim_path(ws2) # remove the comparison directory if it exists @@ -129,9 +129,7 @@ def runmodel(exdir): ) assert success, f"comparision for {ws} failed" - fpTest.addTestDir(baseDir) - - fpTest.teardown() + testFramework.addTestDir(baseDir) # for running tests with pytest diff --git a/autotest/t504_test.py b/autotest/t504_test.py index b370673c32..af0419f1ed 100644 --- a/autotest/t504_test.py +++ b/autotest/t504_test.py @@ -40,8 +40,8 @@ def test001a_tharmonic(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -162,8 +162,6 @@ def test001a_tharmonic(): ] assert array_util.array_comp(budget_frf_valid, budget_frf) - fpTest.teardown() - return @@ -175,8 +173,8 @@ def test003_gwfs_disv(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -265,8 +263,6 @@ def test003_gwfs_disv(): ] assert array_util.array_comp(budget_fjf_valid, budget_frf) - fpTest.teardown() - return @@ -278,8 +274,8 @@ def test005_advgw_tidal(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -338,8 +334,6 @@ def test005_advgw_tidal(): outfile=outfile, ) - fpTest.teardown() - def test006_gwf3(): # init paths @@ -349,8 +343,8 @@ def test006_gwf3(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -463,7 +457,7 @@ def test006_gwf3(): # confirm that files did move save_folder = f"{run_folder}_save02" - fpTest.addTestDir(save_folder, create=True) + testFramework.addTestDir(save_folder, create=True) sim.set_sim_path(save_folder) @@ -535,8 +529,6 @@ def test006_gwf3(): # clean up sim.delete_output_files() - fpTest.teardown() - return @@ -548,8 +540,8 @@ def test006_gwf3(): # pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) # run_folder = f"{baseDir}_{test_ex_name}" # save_folder = f"{run_folder}_save" -# fpTest = flopyTest(verbose=True) -# fpTest.addTestDir([run_folder, save_folder], create=True) +# testFramework = flopyTest(verbose=True) +# testFramework.addTestDir([run_folder, save_folder], create=True) # # expected_output_folder = os.path.join(pth, "expected_output") # expected_head_file_a = os.path.join( @@ -618,7 +610,7 @@ def test006_gwf3(): # ) # assert success # -# fpTest.teardown() +# # # return @@ -632,8 +624,8 @@ def test006_2models_mvr(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -812,8 +804,6 @@ def test006_2models_mvr(): success, buff = sim.run_simulation() assert success, f"simulation {sim.name} did not run" - fpTest.teardown() - return @@ -825,8 +815,8 @@ def test001e_uzf_3lay(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) # load simulation sim = MFSimulation.load(model_name, "mf6", exe_name, pth, verify_data=True) @@ -889,8 +879,6 @@ def test001e_uzf_3lay(): eval_cbc_precision() eval_replace_ims_package() - fpTest.teardown() - def test045_lake2tr(): # init paths @@ -900,8 +888,8 @@ def test045_lake2tr(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -963,8 +951,6 @@ def test045_lake2tr(): htol=10.0, ) - fpTest.teardown() - def test036_twrihfb(): # init paths @@ -974,8 +960,8 @@ def test036_twrihfb(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -1050,8 +1036,6 @@ def test036_twrihfb(): files2=head_new, ) - fpTest.teardown() - def test027_timeseriestest(): # init paths @@ -1061,8 +1045,8 @@ def test027_timeseriestest(): pth = os.path.join("..", "examples", "data", "mf6", test_ex_name) run_folder = f"{baseDir}_{test_ex_name}" save_folder = f"{run_folder}_save" - fpTest = flopyTest(verbose=True) - fpTest.addTestDir([run_folder, save_folder], create=True) + testFramework = flopyTest(verbose=True) + testFramework.addTestDir([run_folder, save_folder], create=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_a = os.path.join( @@ -1132,8 +1116,6 @@ def test027_timeseriestest(): htol=10.0, ) - fpTest.teardown() - def eval_cbc_precision(): pth = os.path.join( @@ -1172,7 +1154,7 @@ def test_mf6_output(): sim = flopy.mf6.MFSimulation.load(sim_ws=sim_ws, exe_name=exe_name) ws = f"{baseDir}_{ex_name}_mf6_output" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) sim.set_sim_path(ws) sim.write_simulation() @@ -1239,8 +1221,6 @@ def test_mf6_output(): if ml.dis.output.methods() is not None: raise AssertionError() - fpTest.teardown() - def test_mf6_output_add_observation(): model_name = "lakeex2a" @@ -1266,7 +1246,7 @@ def test_mf6_output_add_observation(): ) ws = f"{baseDir}_test045_lake2tr_obs" - fpTest = flopyTest(verbose=True, testDirs=ws, create=True) + testFramework = flopyTest(verbose=True, testDirs=ws, create=True) sim.set_sim_path(ws) sim.write_simulation() @@ -1280,8 +1260,6 @@ def test_mf6_output_add_observation(): if not isinstance(sfr_obs, flopy.utils.Mf6Obs): raise TypeError("remove and add observation test (Mf6Output) failed") - fpTest.teardown() - if __name__ == "__main__": test001a_tharmonic() diff --git a/autotest/t505_test.py b/autotest/t505_test.py index 0351cdd6a7..917fd3eaab 100644 --- a/autotest/t505_test.py +++ b/autotest/t505_test.py @@ -35,6 +35,7 @@ from flopy.mf6.utils import testutils from flopy.mf6.mfbase import MFDataException from flopy.mf6.mfbase import ExtFileAction +from ci_framework import baseTestDir, flopyTest try: import shapefile @@ -56,10 +57,7 @@ if v is None: run = False -cpth = os.path.join("temp", "t505") -# make the directory if it does not exist -if not os.path.isdir(cpth): - os.makedirs(cpth, exist_ok=True) +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def get_gwf_model(sim, gwfname, gwfpath, modelshape, chdspd=None, welspd=None): @@ -194,9 +192,8 @@ def test_multi_model(): test_ex_name = "test_multi_model" model_names = ["gwf_model_1", "gwf_model_2", "gwt_model_1", "gwt_model_2"] - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) # temporal discretization nper = 1 @@ -208,7 +205,6 @@ def test_multi_model(): tdis_rc.append((perlen[i], nstp[i], tsmult[i])) # build MODFLOW 6 files - ws = dir sim = flopy.mf6.MFSimulation( sim_name=test_ex_name, version="mf6", exe_name="mf6", sim_ws=run_folder ) @@ -361,12 +357,12 @@ def test_np001(): test_ex_name = "np001" model_name = "np001_mod" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "np001_mod.hds") @@ -696,18 +692,20 @@ def test_np001(): sim.run_simulation() # get expected results - budget_file = os.path.join(os.getcwd(), expected_cbc_file) - budget_obj = bf.CellBudgetFile(budget_file, precision="double") + budget_obj = bf.CellBudgetFile(expected_cbc_file, precision="double") budget_frf_valid = np.array( budget_obj.get_data(text="RIV", full3D=False) ) # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "np001_mod.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # budget_frf = sim.simulation_data.mfdata[(model_name, "CBC", "RIV")] budget_frf = model.output.budget().get_data(text="RIV", full3D=False) @@ -732,18 +730,20 @@ def test_np001(): sim.run_simulation() # get expected results - budget_file = os.path.join(os.getcwd(), expected_cbc_file) - budget_obj = bf.CellBudgetFile(budget_file, precision="double") + budget_obj = bf.CellBudgetFile(expected_cbc_file, precision="double") budget_frf_valid = np.array( budget_obj.get_data(text="RIV", full3D=False) ) # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder_new, "np001_mod.hds") outfile = os.path.join(run_folder_new, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # budget_frf = sim.simulation_data.mfdata[(model_name, "CBC", "RIV")] @@ -918,13 +918,14 @@ def test_np002(): test_ex_name = "np002" model_name = "np002_mod" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - pth_for_mf = os.path.join("..", "..", "..", pth) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) + # pth_for_mf = os.path.join("..", "..", "..", pth) + pth_for_mf = os.path.join("..", "..", pth) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "np002_mod.hds") @@ -1093,11 +1094,14 @@ def test_np002(): k = npf_package.k.array # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "np002_mod.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # verify external text file was written correctly @@ -1181,12 +1185,12 @@ def test021_twri(): test_ex_name = "test021_twri" model_name = "twri" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "twri.hds") @@ -1377,11 +1381,14 @@ def test021_twri(): assert drn_spd[0][1][3] == "name_2" # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "twri.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # clean up @@ -1395,12 +1402,12 @@ def test005_advgw_tidal(): test_ex_name = "test005_advgw_tidal" model_name = "AdvGW_tidal" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join( @@ -1928,11 +1935,14 @@ def test005_advgw_tidal(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "AdvGW_tidal.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # test rename all @@ -2011,12 +2021,12 @@ def test004_bcfss(): test_ex_name = "test004_bcfss" model_name = "bcf2ss" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "bcf2ss.hds") @@ -2146,11 +2156,14 @@ def test004_bcfss(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "bcf2ss.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # clean up @@ -2164,12 +2177,12 @@ def test035_fhb(): test_ex_name = "test035_fhb" model_name = "fhb2015" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join( @@ -2291,11 +2304,14 @@ def test035_fhb(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "fhb2015_fhb.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # clean up @@ -2309,12 +2325,12 @@ def test006_gwf3_disv(): test_ex_name = "test006_gwf3_disv" model_name = "flow" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "flow.hds") @@ -2572,11 +2588,14 @@ def test006_gwf3_disv(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "flow.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # export to netcdf - temporarily disabled @@ -2597,12 +2616,12 @@ def test006_2models_gnc(): model_name_1 = "model1" model_name_2 = "model2" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file_1 = os.path.join(expected_output_folder, "model1.hds") @@ -2888,19 +2907,25 @@ def test006_2models_gnc(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file_1) head_new = os.path.join(run_folder, "model1.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file_1, + files2=head_new, + outfile=outfile, ) # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file_2) head_new = os.path.join(run_folder, "model2.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file_2, + files2=head_new, + outfile=outfile, ) # test external file paths @@ -2941,12 +2966,12 @@ def test050_circle_island(): test_ex_name = "test050_circle_island" model_name = "ci" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "ci.output.hds") @@ -3025,11 +3050,14 @@ def test050_circle_island(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "ci.output.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) # clean up @@ -3043,12 +3071,12 @@ def test028_sfr(): test_ex_name = "test028_sfr" model_name = "test1tr" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "test1tr.hds") @@ -3292,13 +3320,12 @@ def test028_sfr(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "test1tr.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( None, None, - files1=head_file, + files1=expected_head_file, files2=head_new, outfile=outfile, htol=10.0, @@ -3315,18 +3342,17 @@ def test_transport(): test_ex_name = "test_transport" name = "mst03" + run_folder = f"{baseDir}_{test_ex_name}" + testFramework = flopyTest(verbose=True, testDirs=run_folder, create=True) + pth = os.path.join( "..", "examples", "data", "mf6", "create_tests", test_ex_name ) - run_folder = os.path.join(cpth, test_ex_name) - if not os.path.isdir(run_folder): - os.makedirs(run_folder, exist_ok=True) expected_output_folder = os.path.join(pth, "expected_output") expected_head_file = os.path.join(expected_output_folder, "gwf_mst03.hds") expected_conc_file = os.path.join(expected_output_folder, "gwt_mst03.unc") - ws = os.path.join("temp", "t505", test_ex_name) laytyp = [1] ss = [1.0e-10] sy = [0.1] @@ -3353,7 +3379,10 @@ def test_transport(): # build MODFLOW 6 files sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, + version="mf6", + exe_name="mf6", + sim_ws=run_folder, ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -3528,16 +3557,22 @@ def test_transport(): sim.run_simulation() # compare output to expected results - head_file = os.path.join(os.getcwd(), expected_head_file) head_new = os.path.join(run_folder, "gwf_mst03.hds") outfile = os.path.join(run_folder, "head_compare.dat") assert pymake.compare_heads( - None, None, files1=head_file, files2=head_new, outfile=outfile + None, + None, + files1=expected_head_file, + files2=head_new, + outfile=outfile, ) - conc_file = os.path.join(os.getcwd(), expected_conc_file) conc_new = os.path.join(run_folder, "gwt_mst03.ucn") assert pymake.compare_concs( - None, None, files1=conc_file, files2=conc_new, outfile=outfile + None, + None, + files1=expected_conc_file, + files2=conc_new, + outfile=outfile, ) # clean up diff --git a/autotest/t506_test.py b/autotest/t506_test.py index a6559c294e..623b1c46ec 100644 --- a/autotest/t506_test.py +++ b/autotest/t506_test.py @@ -27,6 +27,8 @@ matplotlib = None plt = None +from ci_framework import baseTestDir, flopyTest + # Set gridgen executable gridgen_exe = "gridgen" if platform.system() in "Windows": @@ -45,8 +47,7 @@ mfusg_exe += ".exe" mfusg_exe = flopy.which(mfusg_exe) -# set up the example folder -tpth = os.path.join("temp", "t506") +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) VERBOSITY_LEVEL = 0 @@ -63,14 +64,9 @@ def test_mf6disv(): print("Unable to run test_mf6disv(). shapely is not available.") return - # set up example directory - if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - # set up a gridgen workspace - gridgen_ws = os.path.join(tpth, "mf6disv") - if not os.path.isdir(gridgen_ws): - os.makedirs(gridgen_ws, exist_ok=True) + gridgen_ws = f"{baseDir}_mf6disv" + testFramework = flopyTest(verbose=True, testDirs=gridgen_ws, create=True) name = "dummy" nlay = 3 @@ -187,14 +183,9 @@ def test_mf6disv(): def test_mf6disu(): - # set up example directory - if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - # set up a gridgen workspace - gridgen_ws = os.path.join(tpth, "mf6disu") - if not os.path.isdir(gridgen_ws): - os.makedirs(gridgen_ws, exist_ok=True) + gridgen_ws = f"{baseDir}_mf6disu" + testFramework = flopyTest(verbose=True, testDirs=gridgen_ws, create=True) name = "dummy" nlay = 3 @@ -346,14 +337,9 @@ def test_mf6disu(): def test_mfusg(): - # set up example directory - if not os.path.isdir(tpth): - os.makedirs(tpth, exist_ok=True) - # set up a gridgen workspace - gridgen_ws = os.path.join(tpth, "mfusg") - if not os.path.isdir(gridgen_ws): - os.makedirs(gridgen_ws, exist_ok=True) + gridgen_ws = f"{baseDir}_mfusg" + testFramework = flopyTest(verbose=True, testDirs=gridgen_ws, create=True) name = "dummy" nlay = 3 diff --git a/autotest/t550_test.py b/autotest/t550_test.py index 2994f96144..5fffd8d2ea 100644 --- a/autotest/t550_test.py +++ b/autotest/t550_test.py @@ -1,4 +1,4 @@ -import os, math +import math import numpy as np import flopy @@ -15,12 +15,15 @@ except ImportError: shapefile = None -tmpdir = "temp/t550/" -if not os.path.isdir(tmpdir): - os.makedirs(tmpdir, exist_ok=True) +from ci_framework import baseTestDir, flopyTest + +baseDir = baseTestDir(__file__, relPath="temp", verbose=True) def test_mf6_grid_shp_export(): + model_ws = f"{baseDir}_test_mf6_grid_shp_export" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + nlay = 2 nrow = 10 ncol = 10 @@ -32,7 +35,11 @@ def test_mf6_grid_shp_export(): perioddata = [[perlen, nstp, tsmult]] * 2 botm = np.zeros((2, 10, 10)) - m = fm.Modflow("junk", version="mfnwt", model_ws=tmpdir) + m = fm.Modflow( + "junk", + version="mfnwt", + model_ws=model_ws, + ) dis = fm.ModflowDis( m, nlay=nlay, @@ -72,7 +79,10 @@ def test_mf6_grid_shp_export(): # mf6 version of same model mf6name = "junk6" sim = fp6.MFSimulation( - sim_name=mf6name, version="mf6", exe_name="mf6", sim_ws=tmpdir + sim_name=mf6name, + version="mf6", + exe_name="mf6", + sim_ws=model_ws, ) tdis = flopy.mf6.modflow.mftdis.ModflowTdis( sim, pname="tdis", time_units="DAYS", nper=nper, perioddata=perioddata @@ -101,9 +111,9 @@ def cellid(k, i, j, nrow, ncol): riv6 = fp6.ModflowGwfriv(gwf, stress_period_data=spd6) rch6 = fp6.ModflowGwfrcha(gwf, recharge=rech) if shapefile: - # rch6.export('{}/mf6.shp'.format(tmpdir)) - m.export(f"{tmpdir}/mfnwt.shp") - gwf.export(f"{tmpdir}/mf6.shp") + # rch6.export('{}/mf6.shp'.format(baseDir)) + m.export(f"{model_ws}/mfnwt.shp") + gwf.export(f"{model_ws}/mf6.shp") riv6spdarrays = dict(riv6.stress_period_data.masked_4D_arrays_itr()) rivspdarrays = dict(riv.stress_period_data.masked_4D_arrays_itr()) @@ -117,8 +127,8 @@ def cellid(k, i, j, nrow, ncol): return # skip remainder # check that the two shapefiles are the same - ra = shp2recarray(f"{tmpdir}/mfnwt.shp") - ra6 = shp2recarray(f"{tmpdir}/mf6.shp") + ra = shp2recarray(f"{model_ws}/mfnwt.shp") + ra6 = shp2recarray(f"{model_ws}/mf6.shp") # check first and last exported cells assert ra.geometry[0] == ra6.geometry[0] @@ -144,6 +154,9 @@ def cellid(k, i, j, nrow, ncol): def test_huge_shapefile(): + model_ws = f"{baseDir}_test_huge_shapefile" + testFramework = flopyTest(verbose=True, testDirs=model_ws, create=True) + nlay = 2 nrow = 200 ncol = 200 @@ -155,7 +168,7 @@ def test_huge_shapefile(): perioddata = [[perlen, nstp, tsmult]] * 2 botm = np.zeros((nlay, nrow, ncol)) - m = fm.Modflow("junk", version="mfnwt", model_ws=tmpdir) + m = fm.Modflow("junk", version="mfnwt", model_ws=model_ws) dis = fm.ModflowDis( m, nlay=nlay, @@ -169,7 +182,7 @@ def test_huge_shapefile(): botm=botm, ) if shapefile: - m.export(f"{tmpdir}/huge.shp") + m.export(f"{model_ws}/huge.shp") if __name__ == "__main__": diff --git a/autotest/t600_pyinstaller_test.py b/autotest/t600_pyinstaller_test.py index 019abe7a00..d4cab08eea 100644 --- a/autotest/t600_pyinstaller_test.py +++ b/autotest/t600_pyinstaller_test.py @@ -10,7 +10,10 @@ def test_flopy_runs_without_dfn_folder(): - """Test to ensure that flopy can load a modflow 6 simulation without dfn files being present.""" + """ + Test to ensure that flopy can load a modflow 6 simulation without dfn + files being present. + """ exists = dfn_path.exists() if exists: if rename_path.exists(): diff --git a/examples/data/mf6-freyberg/bot.asc b/examples/data/mf6-freyberg/bot.asc new file mode 100644 index 0000000000..b75ea2c75d --- /dev/null +++ b/examples/data/mf6-freyberg/bot.asc @@ -0,0 +1,46 @@ +NCOLS 20 +NROWS 40 +XLLCENTER 125.0 +YLLCENTER 125.0 +CELLSIZE 250.0 +NODATA_VALUE 0.0 +17.0080 18.5070 18.6720 15.9300 13.9610 14.4620 8.0190 10.6000 8.8847 7.2274 6.2511 6.0061 7.1143 6.9039 6.2443 6.9450 6.9855 5.0310 4.0061 6.6584 +19.1260 17.3450 18.2340 13.6600 13.2620 13.9220 10.6760 9.9167 11.0250 6.4094 4.8782 5.0843 6.5321 5.1773 5.7181 4.3329 5.8867 6.4356 5.2941 6.0503 +17.4800 18.8600 18.2960 12.9860 13.7380 14.4010 9.2020 11.2080 8.3499 8.5742 5.9810 6.5199 6.2453 5.0066 7.1720 7.1635 4.5908 5.1325 5.0524 6.8011 +17.9700 18.8970 19.3130 14.8620 13.3210 15.7680 11.4660 8.7568 12.3280 7.0550 3.0590 2.8243 2.2451 2.9858 3.1909 2.2319 7.7850 4.9555 6.3389 6.4755 +18.9110 18.0450 16.9950 14.8810 15.2120 13.7540 8.6911 14.6350 10.0450 4.7893 3.1688 2.9762 2.5813 2.9683 2.3507 2.7028 3.5056 6.3335 4.7777 5.4066 +15.9990 18.1780 16.6350 13.7390 13.6020 14.8050 15.1840 12.8150 14.2630 10.6730 3.4014 3.3428 2.9257 3.0238 3.2361 2.6949 2.6232 3.0085 6.0561 6.5184 +15.9270 13.2420 15.2060 11.2130 14.4560 11.6310 15.1340 12.8350 14.0040 8.9364 3.4679 3.3814 2.9236 3.4947 3.5715 3.3131 3.9369 2.7150 4.5148 5.8774 +19.6000 14.5430 14.0330 13.1860 15.3440 14.8300 14.5940 15.5070 14.8880 8.8195 3.4633 3.3105 4.0456 2.8153 2.8529 3.1951 2.6150 4.2689 3.4225 6.7451 +18.4760 13.4330 12.3470 15.7410 0.0000 0.0000 0.0000 12.8750 8.8273 5.1087 4.1368 3.2677 2.8839 3.3258 3.4857 3.2112 3.0806 2.5045 3.5168 5.3489 +19.6650 13.1170 15.5280 14.1310 0.0000 0.0000 0.0000 0.0000 10.3920 6.3652 3.0670 2.6610 3.0942 2.4251 3.5019 2.4368 3.3456 2.5427 3.8515 2.8273 +17.5130 14.7590 13.0830 15.5170 0.0000 0.0000 0.0000 0.0000 10.5510 5.4486 3.1347 3.3698 3.0613 3.0557 3.0613 2.7351 3.0226 2.8656 2.8963 3.6134 +12.2810 13.4760 14.6040 14.4960 0.0000 0.0000 0.0000 0.0000 9.7126 5.2610 2.5406 4.1927 3.0722 3.1407 2.6258 3.2426 3.5334 2.8549 2.5826 3.2925 +14.1420 11.9620 13.8960 12.9130 0.0000 0.0000 0.0000 0.0000 8.6031 5.6522 1.7532 1.6521 1.4932 1.7338 1.6462 1.8513 3.2896 2.6617 3.7838 3.4377 +14.9600 13.6690 11.6990 10.4230 0.0000 0.0000 0.0000 0.0000 9.4056 5.6336 1.6262 1.6896 1.2846 1.5438 1.8402 1.5956 3.7104 3.1993 3.2448 2.7462 +12.8520 13.6610 10.5730 9.0339 0.0000 0.0000 0.0000 0.0000 9.2656 6.6003 1.0748 1.7295 1.4544 1.5198 1.1214 1.6756 4.3909 2.4590 2.0083 3.4206 +14.4030 15.2130 10.4090 9.0355 0.0000 0.0000 0.0000 0.0000 10.1110 3.6992 1.4232 1.7499 1.6581 1.5920 1.6104 1.2725 4.1903 2.9122 3.1891 3.6998 +13.1910 9.3046 9.2241 10.1770 0.0000 0.0000 0.0000 0.0000 8.0262 6.2127 1.3763 1.2943 1.4516 1.3079 1.1092 1.3149 2.9437 3.6516 3.2169 3.2411 +13.7570 9.6697 6.9156 10.0920 0.0000 0.0000 0.0000 0.0000 10.8030 6.4464 1.3273 1.5796 1.1219 1.2769 1.5814 1.4652 1.6370 2.8829 2.4030 2.3025 +13.6310 11.0510 6.0632 11.0890 0.0000 0.0000 0.0000 0.0000 9.6777 6.2188 1.7076 1.1244 1.2750 1.5545 1.4465 1.6284 1.5016 2.5399 1.7712 4.0115 +14.2690 10.1430 3.9943 10.6450 0.0000 0.0000 0.0000 0.0000 10.3600 5.3413 1.1137 1.3405 1.4209 1.5649 2.2000 1.4498 1.5241 2.9436 3.1003 2.8790 +12.2440 9.7607 7.8784 9.5028 0.0000 0.0000 0.0000 0.0000 8.7173 3.9539 1.8367 1.3385 0.9366 1.3960 1.7390 1.5907 1.5251 2.9159 3.8223 2.6267 +14.7180 10.6950 4.7303 8.2807 0.0000 0.0000 10.1120 12.1560 5.9685 6.0099 1.1577 1.6447 1.8229 1.3292 1.3365 1.8093 1.3093 1.6470 2.4618 3.1563 +12.0240 9.3289 5.4725 8.6354 8.4379 0.0000 10.1350 11.9270 5.9917 6.0854 1.2831 1.8849 1.1641 2.0084 1.3688 1.3880 1.2512 1.4895 1.6991 2.9707 +13.8030 8.9535 7.1000 9.3852 11.0120 11.4100 10.4510 4.7665 7.0223 5.0816 1.4899 1.3294 1.6026 1.1729 1.4137 1.7779 1.0661 1.4885 2.9373 3.1760 +14.2650 9.0847 5.2856 12.8130 11.1070 5.2416 5.7991 5.6034 6.7668 1.7813 0.6455 0.3463 0.3346 0.6104 0.2987 0.7599 2.2484 1.4189 2.8623 2.6629 +14.8720 10.0490 10.5790 7.2766 6.5425 4.1703 6.1618 4.0361 3.4598 2.7051 0.4494 0.6372 0.5442 0.5619 0.4726 0.2460 1.1445 1.5841 3.8255 3.5807 +13.4100 10.7420 9.4348 10.0490 6.5546 5.9833 4.5127 4.5002 2.7058 3.4134 0.3049 0.5416 0.4243 0.4677 0.3848 0.4794 1.7216 1.6441 1.3825 3.4871 +13.7350 12.1270 9.4241 10.3060 7.1944 6.8039 5.4021 3.4308 2.7098 1.9810 0.8697 0.3391 0.4952 0.1862 0.2103 0.3799 1.3946 1.5522 1.5273 2.7037 +15.0170 10.8970 10.4990 10.8340 6.6445 6.4540 5.4257 2.4875 2.6592 1.8435 0.1829 0.0424 0.7852 0.4404 0.6896 0.8463 1.4611 1.3011 1.6247 3.5610 +14.1110 9.8787 8.0351 5.3384 6.2775 5.2240 5.5896 5.5891 2.6451 1.7568 0.9157 0.5693 0.2344 0.4442 0.0139 0.6347 0.4316 1.4960 1.7119 3.4404 +11.2960 9.6566 7.7356 11.0200 4.5768 7.2037 7.3885 5.2052 2.7217 1.3624 0.3339 0.6942 0.6532 0.5919 0.4125 0.4952 0.7150 1.0985 1.6975 2.1805 +12.5940 9.9103 10.7690 4.5977 5.6607 6.2810 5.7616 2.4491 3.4721 2.0608 0.6855 0.2534 0.9144 0.5435 0.5695 0.7501 0.2378 1.2186 1.1072 3.1487 +0.0000 8.8675 10.9370 5.9463 6.7191 6.5623 5.4118 3.4439 2.3840 1.9104 0.5075 0.6844 0.1888 0.4654 0.7109 0.3407 0.1594 1.4753 1.0008 2.4790 +0.0000 0.0000 10.9510 6.1613 6.3923 6.7709 2.9707 3.0016 3.1640 0.9274 0.1631 0.6601 0.2656 0.3331 0.6923 0.4834 0.6389 1.3737 1.6797 1.4661 +0.0000 0.0000 0.0000 7.3548 5.1731 4.9708 5.2845 6.2087 3.1052 1.3327 0.8008 0.3992 0.4791 0.1835 0.5879 0.7434 0.8502 1.9328 1.8556 2.0022 +0.0000 0.0000 0.0000 0.0000 4.2779 4.8438 5.5892 5.0886 3.2245 1.6683 0.6847 0.4031 0.5131 0.5307 0.2503 0.6330 0.6843 1.4369 1.6174 0.0000 +0.0000 0.0000 0.0000 0.0000 5.8926 6.2475 7.1632 3.0387 2.2536 1.6464 0.3108 -0.2027 0.5490 1.0779 0.0649 0.4217 0.3124 1.7811 1.4466 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 6.5855 4.7402 1.7855 2.9122 1.6155 0.7083 0.4167 0.5610 0.4744 0.3715 0.3287 0.4958 1.4285 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 5.1503 5.8960 2.3450 2.7254 1.4189 0.1220 0.4666 0.4944 0.1662 0.6749 0.6819 -0.0017 0.0000 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 6.9138 4.5808 2.5275 2.6038 1.4444 0.5365 0.2253 0.5896 0.6079 0.5060 0.0000 0.0000 0.0000 0.0000 0.0000 diff --git a/examples/data/mf6-freyberg/k11.asc b/examples/data/mf6-freyberg/k11.asc new file mode 100644 index 0000000000..8b420be238 --- /dev/null +++ b/examples/data/mf6-freyberg/k11.asc @@ -0,0 +1,46 @@ +NCOLS 20 +NROWS 40 +XLLCENTER 125.0 +YLLCENTER 125.0 +CELLSIZE 250.0 +NODATA_VALUE 0.0 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0000 0.0001 0.0001 0.0000 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0001 0.0000 0.0000 0.0001 0.0001 0.0001 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 +0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 +0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 +0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0001 0.0000 0.0001 0.0001 0.0001 +0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0001 0.0001 +0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0000 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 diff --git a/examples/data/mf6-freyberg/top.asc b/examples/data/mf6-freyberg/top.asc new file mode 100644 index 0000000000..88df5a6465 --- /dev/null +++ b/examples/data/mf6-freyberg/top.asc @@ -0,0 +1,46 @@ +NCOLS 20 +NROWS 40 +XLLCENTER 125.0 +YLLCENTER 125.0 +CELLSIZE 250.0 +NODATA_VALUE 0.0 +29.4679 29.3600 29.1207 28.7733 28.3558 27.8516 27.3152 26.7655 26.1675 25.5486 24.8736 24.1798 23.4365 22.7141 22.1149 22.1470 22.2310 22.2998 22.3471 22.3773 +29.5029 29.3950 29.1446 28.7874 28.3939 27.8814 27.3224 26.7606 26.1446 25.4844 24.7976 24.1068 23.3536 22.5951 21.9000 22.0329 22.1629 22.2556 22.3107 22.3437 +29.5738 29.4568 29.1984 28.8373 28.4479 27.9157 27.3338 26.7506 26.1032 25.3932 24.6655 23.9529 23.1777 22.4397 21.6809 21.8856 22.0528 22.1669 22.2369 22.2740 +29.7045 29.5724 29.2934 28.9273 28.5252 27.9810 27.3502 26.7212 25.9896 25.1989 24.4620 23.7537 23.0169 22.2623 21.4552 21.6955 21.9037 22.0502 22.1297 22.1728 +29.8819 29.7316 29.4482 29.0771 28.6211 28.0552 27.4233 26.6563 25.7905 24.9973 24.2675 23.5746 22.8236 22.0470 21.2302 21.5043 21.7287 21.8988 22.0003 22.0512 +30.0788 29.9485 29.6576 29.2858 28.7766 28.1521 27.4024 26.5463 25.6514 24.7510 24.0156 23.3403 22.6100 21.8612 21.0109 21.3184 21.5678 21.7398 21.8566 21.9109 +30.2641 30.1705 29.9203 29.5417 28.9317 28.2193 27.3942 26.3753 25.3572 24.4552 23.7657 23.0810 22.3951 21.6610 20.7755 21.1341 21.4006 21.5900 21.7048 21.7604 +30.5107 30.4112 30.2023 29.8453 29.0824 28.2607 27.3774 25.9974 24.8591 24.0666 23.4406 22.7927 22.1525 21.4281 20.5501 20.9486 21.2278 21.4253 21.5439 21.5994 +30.7800 30.7091 30.5733 30.4328 0.0000 0.0000 0.0000 25.0109 24.2038 23.6604 23.1053 22.5167 21.9320 21.2510 20.3447 20.8197 21.0807 21.2604 21.3789 21.4291 +31.0329 30.9776 30.9035 30.8350 0.0000 0.0000 0.0000 0.0000 23.4821 23.1805 22.7487 22.2580 21.7166 21.1913 21.0118 20.8229 20.9389 21.0974 21.2095 21.2696 +31.2446 31.2033 31.1606 31.1229 0.0000 0.0000 0.0000 0.0000 22.9586 22.7533 22.4125 21.9376 21.3633 20.7169 19.8926 20.4219 20.6966 20.8928 21.0196 21.0855 +31.3672 31.3554 31.3313 31.3140 0.0000 0.0000 0.0000 0.0000 22.5463 22.3859 22.0665 21.6027 21.0384 20.3764 19.6331 20.1118 20.4594 20.6681 20.8196 20.8831 +31.4337 31.4299 31.4199 31.4066 0.0000 0.0000 0.0000 0.0000 22.2517 22.0961 21.7662 21.3110 20.7737 20.1257 19.4149 19.8425 20.2104 20.4493 20.6032 20.6804 +31.4501 31.4481 31.4361 31.4216 0.0000 0.0000 0.0000 0.0000 22.0316 21.8654 21.5529 21.1145 20.5486 19.8959 19.1865 19.6302 20.0002 20.2474 20.3916 20.4588 +31.4080 31.4057 31.3910 31.3808 0.0000 0.0000 0.0000 0.0000 21.8666 21.6985 21.3734 20.9137 20.3751 19.7240 18.9509 19.4155 19.8013 20.0578 20.2036 20.2638 +31.3078 31.3001 31.2898 31.2863 0.0000 0.0000 0.0000 0.0000 21.7590 21.5881 21.2396 20.7450 20.1957 19.5283 18.7299 19.2056 19.5952 19.8605 20.0106 20.0765 +31.1550 31.1443 31.1332 31.1349 0.0000 0.0000 0.0000 0.0000 21.7209 21.5357 21.1495 20.6274 20.0445 19.3413 18.5002 18.9823 19.3844 19.6647 19.8198 19.8856 +30.9618 30.9485 30.9268 30.9284 0.0000 0.0000 0.0000 0.0000 21.7732 21.5589 21.1632 20.5733 19.8953 19.1521 18.2727 18.7665 19.1675 19.4586 19.6273 19.7070 +30.7104 30.6924 30.6693 30.6540 0.0000 0.0000 0.0000 0.0000 21.9347 21.6925 21.2561 20.5865 19.7724 18.9557 18.0532 18.5620 18.9777 19.2763 19.4496 19.5280 +30.4064 30.3893 30.3541 30.3128 0.0000 0.0000 0.0000 0.0000 22.1960 21.9168 21.4040 20.6362 19.7100 18.7932 17.8231 18.3672 18.7876 19.0935 19.2814 19.3566 +30.0740 30.0374 29.9706 29.9179 0.0000 0.0000 0.0000 0.0000 22.6094 22.2139 21.5983 20.7588 19.6721 18.5920 17.5945 18.1640 18.6037 18.9099 19.1047 19.1931 +29.7033 29.6378 29.5474 29.4558 0.0000 0.0000 24.4701 24.0144 23.2386 22.5898 21.8280 20.8401 19.6118 18.4498 17.3660 17.9593 18.4391 18.7453 18.9319 19.0289 +29.3103 29.2280 29.0875 28.8364 28.3314 0.0000 24.7932 24.3044 23.5913 22.8861 21.9998 20.9296 19.5816 18.2895 17.1477 17.7552 18.2569 18.6048 18.7897 18.8824 +28.9468 28.8426 28.6508 28.3193 27.6730 26.5872 25.4529 24.6704 23.8975 23.1000 22.1186 20.9567 19.5528 18.1638 16.9189 17.5871 18.1062 18.4429 18.6478 18.7446 +28.6005 28.4909 28.2850 27.9009 27.2529 26.4791 25.6899 24.9284 24.0725 23.1880 22.1955 20.9565 19.4865 18.0044 16.6920 17.3869 17.9612 18.3042 18.5158 18.6142 +28.2770 28.1750 27.9555 27.5577 27.0176 26.4167 25.7344 25.0141 24.2137 23.3078 22.1882 20.8180 19.3577 17.8950 16.4772 17.2243 17.8237 18.1775 18.3985 18.5022 +27.9916 27.8798 27.6697 27.3405 26.8805 26.3494 25.7719 25.0419 24.2356 23.4149 22.0457 20.5413 19.3147 17.8586 16.2375 17.0741 17.7004 18.0803 18.3046 18.4042 +27.7348 27.6162 27.4340 27.1352 26.7672 26.3594 25.7994 24.9772 24.0951 23.1671 21.8350 20.4809 19.2232 17.7493 16.0085 16.9109 17.5897 17.9922 18.2116 18.3159 +27.4867 27.3801 27.2089 26.9490 26.6685 26.3594 25.9177 24.9173 23.7655 22.9540 21.6870 20.2960 19.0952 17.5830 15.7857 16.7455 17.5035 17.9127 18.1326 18.2280 +27.2659 27.1733 26.9982 26.7738 26.5477 26.3239 25.7956 24.7884 23.6624 22.6306 21.3745 20.0279 18.8725 17.4217 15.5584 16.5602 17.3754 17.8078 18.0255 18.1201 +27.0992 26.9894 26.7944 26.5460 26.3146 26.0418 25.5067 24.4936 23.4583 22.4206 21.1382 19.8711 18.6805 17.3357 15.3213 16.3865 17.1958 17.6652 17.8731 17.9495 +26.9855 26.7856 26.5277 26.2267 25.9753 25.6768 25.0787 24.1456 23.3126 22.2451 21.0996 19.7447 18.4381 17.1423 15.0914 16.1166 16.8945 17.3769 17.6306 17.7026 +0.0000 26.5581 26.2421 25.8987 25.5629 25.1570 24.5664 24.1068 23.2378 21.9430 21.0280 19.7403 18.0513 16.4333 14.8729 15.6985 16.5013 17.0384 17.3343 17.4400 +0.0000 0.0000 25.9003 25.5183 25.1175 24.6674 24.1454 23.6011 22.7846 21.9279 20.9036 19.5506 17.6990 16.0786 14.6397 15.5185 16.2272 16.7720 17.0695 17.2266 +0.0000 0.0000 0.0000 25.0825 24.5310 24.0663 23.5984 23.1007 22.4714 21.6958 20.5893 19.0353 17.2143 15.8583 14.4106 15.3139 15.9899 16.5181 16.8330 17.0850 +0.0000 0.0000 0.0000 0.0000 23.7381 23.3648 22.9378 22.4520 21.9098 21.1388 19.9832 18.6560 17.0354 15.5765 14.1908 15.1187 15.7983 16.2660 16.5142 0.0000 +0.0000 0.0000 0.0000 0.0000 23.2295 22.5662 22.0596 21.5957 21.1462 20.4836 19.4587 18.3429 16.9059 15.3844 13.9596 14.9805 15.6024 16.0389 16.3466 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 21.2474 20.9537 20.6163 20.3183 19.7002 18.7647 17.8460 16.6769 15.2479 13.7210 14.8247 15.3862 15.8014 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 20.0273 19.8268 19.5266 19.3028 18.5765 17.9346 17.1333 16.1436 14.9701 13.5055 14.6651 15.1257 0.0000 0.0000 0.0000 +0.0000 0.0000 0.0000 0.0000 0.0000 18.9000 18.4000 18.1000 17.6000 17.1000 17.1000 16.0000 15.0000 14.5000 14.0000 0.0000 0.0000 0.0000 0.0000 0.0000 diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 542a079371..8654e8d874 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -1738,11 +1738,13 @@ def line_intersect_grid(ptsin, xgrid, ygrid): cells.append(cell) cell_vertex_ix.append(cvert_ix) - # find interesection vertices + # find intersection vertices numa = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3) numb = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3) denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1) - ua = numa / denom + ua = np.zeros(denom.shape, dtype=denom.dtype) + idx = np.where(denom != 0.0) + ua[idx] = numa[idx] / denom[idx] # ub = numb / denom del numa del numb