diff --git a/.docs/Notebooks/array_output_tutorial.py b/.docs/Notebooks/array_output_tutorial.py index ba35fa49e..641cf66c4 100644 --- a/.docs/Notebooks/array_output_tutorial.py +++ b/.docs/Notebooks/array_output_tutorial.py @@ -29,12 +29,15 @@ # + pycharm={"name": "#%%\n"} import os import sys +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy @@ -44,8 +47,40 @@ exe_name = "mf2005" mfexe = exe_name +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +sim_name = "freyberg" + +file_names = { + "freyberg.bas": "63266024019fef07306b8b639c6c67d5e4b22f73e42dcaa9db18b5e0f692c097", + "freyberg.dis": "62d0163bf36c7ee9f7ee3683263e08a0abcdedf267beedce6dd181600380b0a2", + "freyberg.githds": "abe92497b55e6f6c73306e81399209e1cada34cf794a7867d776cfd18303673b", + "freyberg.gitlist": "aef02c664344a288264d5f21e08a748150e43bb721a16b0e3f423e6e3e293056", + "freyberg.lpf": "06500bff979424f58e5e4fbd07a7bdeb0c78f31bd08640196044b6ccefa7a1fe", + "freyberg.nam": "e66321007bb603ef55ed2ba41f4035ba6891da704a4cbd3967f0c66ef1532c8f", + "freyberg.oc": "532905839ccbfce01184980c230b6305812610b537520bf5a4abbcd3bd703ef4", + "freyberg.pcg": "0d1686fac4680219fffdb56909296c5031029974171e25d4304e70fa96ebfc38", + "freyberg.rch": "37a1e113a7ec16b61417d1fa9710dd111a595de738a367bd34fd4a359c480906", + "freyberg.riv": "7492a1d5eb23d6812ec7c8227d0ad4d1e1b35631a765c71182b71e3bd6a6d31d", + "freyberg.wel": "00aa55f59797c02f0be5318a523b36b168fc6651f238f34e8b0938c04292d3e7", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + # Set the paths -loadpth = os.path.join("..", "..", "examples", "data", "freyberg") +loadpth = data_path / sim_name temp_dir = TemporaryDirectory() modelpth = temp_dir.name diff --git a/.docs/Notebooks/export_tutorial.py b/.docs/Notebooks/export_tutorial.py index cf830e04d..7c1b29a2a 100644 --- a/.docs/Notebooks/export_tutorial.py +++ b/.docs/Notebooks/export_tutorial.py @@ -20,8 +20,12 @@ # + import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git +import pooch + import flopy print(sys.version) @@ -30,8 +34,42 @@ # Load our old friend...the Freyberg model +sim_name = "freyberg_multilayer_transient" + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = { + "freyberg.bas": None, + "freyberg.cbc": None, + "freyberg.ddn": None, + "freyberg.dis": None, + "freyberg.drn": None, + "freyberg.hds": None, + "freyberg.list": None, + "freyberg.nam": None, + "freyberg.nwt": None, + "freyberg.oc": None, + "freyberg.rch": None, + "freyberg.upw": None, + "freyberg.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + nam_file = "freyberg.nam" -model_ws = os.path.join("..", "..", "examples", "data", "freyberg_multilayer_transient") +model_ws = data_path / sim_name ml = flopy.modflow.Modflow.load(nam_file, model_ws=model_ws, check=False) # We can see the ``Modelgrid`` instance has generic entries, as does ``start_datetime`` diff --git a/.docs/Notebooks/export_vtk_tutorial.py b/.docs/Notebooks/export_vtk_tutorial.py index e701e69cb..2719da25d 100644 --- a/.docs/Notebooks/export_vtk_tutorial.py +++ b/.docs/Notebooks/export_vtk_tutorial.py @@ -33,7 +33,9 @@ from pprint import pformat from tempfile import TemporaryDirectory +import git import numpy as np +import pooch import flopy from flopy.export import vtk @@ -42,11 +44,39 @@ print(f"flopy version: {flopy.__version__}") # - +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +sim_name = "freyberg_multilayer_transient" +file_names = { + "freyberg.bas": None, + "freyberg.cbc": None, + "freyberg.ddn": None, + "freyberg.dis": None, + "freyberg.drn": None, + "freyberg.hds": None, + "freyberg.list": None, + "freyberg.nam": None, + "freyberg.nwt": None, + "freyberg.oc": None, + "freyberg.rch": None, + "freyberg.upw": None, + "freyberg.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + # load model for examples nam_file = "freyberg.nam" -model_ws = Path( - os.path.join("..", "..", "examples", "data", "freyberg_multilayer_transient") -) +model_ws = data_path / sim_name ml = flopy.modflow.Modflow.load(nam_file, model_ws=model_ws, check=False) # Create a temporary workspace. diff --git a/.docs/Notebooks/feat_working_stack_examples.py b/.docs/Notebooks/feat_working_stack_examples.py index bf11f6afe..f4dd1a904 100644 --- a/.docs/Notebooks/feat_working_stack_examples.py +++ b/.docs/Notebooks/feat_working_stack_examples.py @@ -23,17 +23,14 @@ from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd - -# + +import pooch from IPython.display import clear_output, display -proj_root = Path.cwd().parent.parent - -# run installed version of flopy or add local path import flopy print(sys.version) @@ -41,15 +38,53 @@ print(f"matplotlib version: {mpl.__version__}") print(f"pandas version: {pd.__version__}") print(f"flopy version: {flopy.__version__}") -# - +# First create a temporary workspace. + +sim_name = "freyberg_multilayer_transient" +temp_dir = TemporaryDirectory() +workspace = Path(temp_dir.name) + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +# Download files if needed. + +file_names = { + "freyberg.bas": "781585c140d40a27bce9369baee262c621bcf969de82361ad8d6b4d8c253ee02", + "freyberg.cbc": "d4e18e968cabde8470fcb7cb8a1c4cc57fcd643bd63b23e7751460bfdb651ea4", + "freyberg.ddn": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "freyberg.dis": "1ef61a467a219c036e58902ce11297e06b4eeb5f2f9d2ea40245b421a248a471", + "freyberg.drn": "93c22ab27d599938a8c2fc5b420ec03e5251b11b050d6ae1cb23ce2aa1b77997", + "freyberg.hds": "0b3e911ef35f625d2d046e05a20bc1300341b41028220c5b25ace6f5a267ceef", + "freyberg.list": "14ec36c22b48d253d6b82c44f36c5bad4f0785b3a3384b386f6b69c4ee2e31bf", + "freyberg.nam": "9e3747ce6d6229caec55a9357285a96cb4608dae11d90dd165a23e0bb394a2bd", + "freyberg.nwt": "d66c5cc255d050a0f871639af4af0cef8d48fa59c1c64217de65fc6e7fd78cb1", + "freyberg.oc": "faefd462d11b9a21c4579420b2156fb616ca642bc1e66fc5eb5e1b9046449e43", + "freyberg.rch": "93a12742a2d37961d53df0405e39cbecf0e6f14d45b5ca8cbba84a2d90828258", + "freyberg.upw": "80838be7af2f97c92965bad1d121c252b69d9c66e4885c5f3f49a6e99582deac", + "freyberg.wel": "dd322655eadff3f618f0835c9277af30720197bd48328aae2d6772f26eef2686", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + +# - # ### Model Inputs -# first lets load an existing model -model_ws = proj_root / "examples" / "data" / "freyberg_multilayer_transient" ml = flopy.modflow.Modflow.load( "freyberg.nam", - model_ws=model_ws, + model_ws=data_path / sim_name, verbose=False, check=False, exe_name="mfnwt", @@ -66,11 +101,6 @@ ml.drn.plot(key="cond") ml.drn.plot(key="elev") -# First create a temporary workspace. - -# create a temporary workspace -temp_dir = TemporaryDirectory() -workspace = Path(temp_dir.name) # Write a shapefile of the DIS package. @@ -96,7 +126,7 @@ # # First, let's look at the list file. The list file summarizes the model's results. -mfl = flopy.utils.MfListBudget(model_ws / "freyberg.list") +mfl = flopy.utils.MfListBudget(workspace / "freyberg.list") df_flux, df_vol = mfl.get_dataframes(start_datetime="10-21-2015") df_flux @@ -116,7 +146,7 @@ # Now let's look at the simulated head. # if you pass the model instance, then the plots will be offset and rotated -h = flopy.utils.HeadFile(model_ws / "freyberg.hds", model=ml) +h = flopy.utils.HeadFile(workspace / "freyberg.hds", model=ml) h.times h.plot(totim=900, contour=True, grid=True, colorbar=True, figsize=(10, 10)) diff --git a/.docs/Notebooks/groundwater2023_watershed_example.py b/.docs/Notebooks/groundwater2023_watershed_example.py index 3b9c804dc..b25da41e6 100644 --- a/.docs/Notebooks/groundwater2023_watershed_example.py +++ b/.docs/Notebooks/groundwater2023_watershed_example.py @@ -25,10 +25,12 @@ import pathlib as pl import sys +import git import matplotlib as mpl import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import numpy as np +import pooch import shapely import yaml from shapely.geometry import LineString, Polygon @@ -106,10 +108,25 @@ def set_idomain(grid, boundary): grid.idomain = idomain -geometries = yaml.safe_load( - open(pl.Path("../../examples/data/groundwater2023/geometries.yml")) +# Check if we are in the repository and define the data path. + +try: + root = pl.Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else pl.Path.cwd() +folder_name = "groundwater2023" +fname = "geometries.yml" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/{fname}", + fname=fname, + path=data_path / folder_name, + known_hash=None, ) +geometries = yaml.safe_load(open(data_path / folder_name / fname)) + # basic figure size figwidth = 180 # 90 # mm figwidth = figwidth / 10 / 2.54 # inches @@ -161,7 +178,13 @@ def set_idomain(grid, boundary): os.mkdir(temp_path) # Load the fine topography that will be sampled -ascii_file = pl.Path("../../examples/data/geospatial/fine_topo.asc") +fname = "fine_topo.asc" +ascii_file = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/geospatial/{fname}", + fname=fname, + path=data_path / "geospatial", + known_hash=None, +) fine_topo = flopy.utils.Raster.load(ascii_file) # Define the problem size and extents diff --git a/.docs/Notebooks/groundwater_paper_uspb_example.py b/.docs/Notebooks/groundwater_paper_uspb_example.py index ac3af280e..367939b8a 100644 --- a/.docs/Notebooks/groundwater_paper_uspb_example.py +++ b/.docs/Notebooks/groundwater_paper_uspb_example.py @@ -22,11 +22,14 @@ # + import os import sys +from pathlib import Path from pprint import pformat +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import scipy.ndimage import flopy @@ -41,9 +44,23 @@ if not os.path.exists(ws): os.makedirs(ws) -fn = os.path.join( - "..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_01.dat" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / ".docs" / "groundwater_paper" if root else Path.cwd() + +fname = "USPB_capture_fraction_04_01.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/.docs/groundwater_paper/uspb/results/{fname}", + fname=fname, + path=data_path / "uspb" / "results", + known_hash=None, ) +fn = data_path / "uspb" / "results" / fname cf = np.loadtxt(fn) print(cf.shape) @@ -53,7 +70,7 @@ c = plt.imshow(cf2, cmap="jet") plt.colorbar(c) -wsl = os.path.join("..", "groundwater_paper", "uspb", "flopy") +wsl = data_path / "uspb" / "flopy" ml = flopy.modflow.Modflow.load("DG.nam", model_ws=wsl, verbose=False) nlay, nrow, ncol = ml.nlay, ml.dis.nrow, ml.dis.ncol @@ -191,9 +208,14 @@ plt.savefig(os.path.join(ws, "uspb_heads.png"), dpi=300) # - -fn = os.path.join( - "..", "groundwater_paper", "uspb", "results", "USPB_capture_fraction_04_10.dat" +fname = "USPB_capture_fraction_04_10.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/.docs/groundwater_paper/uspb/results/{fname}", + fname=fname, + path=data_path / "uspb" / "results", + known_hash=None, ) +fn = data_path / "uspb" / "results" / fname cf = np.loadtxt(fn) cf2 = scipy.ndimage.zoom(cf, 4, order=0) diff --git a/.docs/Notebooks/load_swr_binary_data_example.py b/.docs/Notebooks/load_swr_binary_data_example.py index d7313d121..e21689e34 100644 --- a/.docs/Notebooks/load_swr_binary_data_example.py +++ b/.docs/Notebooks/load_swr_binary_data_example.py @@ -20,10 +20,13 @@ import os import sys +from pathlib import Path +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch # + from IPython.display import Image @@ -35,9 +38,37 @@ print(f"matplotlib version: {mpl.__version__}") print(f"flopy version: {flopy.__version__}") +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +folder_name = "swr_test" + # + # Set the paths -datapth = os.path.join("..", "..", "examples", "data", "swr_test") +datapth = data_path / folder_name + +file_names = [ + "SWR004.dis.ref", + "SWR004.flow", + "SWR004.obs", + "SWR004.stg", + "SWR004.str", + "SWR004.vel", + "swr005.qaq", + "swr005.str", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/{fname}", + fname=fname, + path=datapth, + known_hash=None, + ) # SWR Process binary files files = ("SWR004.obs", "SWR004.vel", "SWR004.str", "SWR004.stg", "SWR004.flow") diff --git a/.docs/Notebooks/mf6_complex_model_example.py b/.docs/Notebooks/mf6_complex_model_example.py index 15d280600..d5c10c05b 100644 --- a/.docs/Notebooks/mf6_complex_model_example.py +++ b/.docs/Notebooks/mf6_complex_model_example.py @@ -21,15 +21,18 @@ # ### Setup the Notebook Environment import os +import sys # + -import sys +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy @@ -39,13 +42,63 @@ print(f"flopy version: {flopy.__version__}") # - + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +sim_name = "test005_advgw_tidal" +file_names = [ + "AdvGW_tidal.dis", + "AdvGW_tidal.evt", + "AdvGW_tidal.ghb", + "AdvGW_tidal.ghb.obs", + "AdvGW_tidal.head.cont.opncls", + "AdvGW_tidal.ic", + "AdvGW_tidal.nam", + "AdvGW_tidal.npf", + "AdvGW_tidal.obs", + "AdvGW_tidal.oc", + "AdvGW_tidal.riv", + "AdvGW_tidal.riv.obs", + "AdvGW_tidal.riv.single.opncls", + "AdvGW_tidal.sto", + "AdvGW_tidal.wel", + "AdvGW_tidal_1.rch", + "AdvGW_tidal_2.rch", + "AdvGW_tidal_3.rch", + "advgw_tidal.dis.grb", + "mfsim.nam", + "model.ims", + "recharge_rates.ts", + "recharge_rates_1.ts", + "recharge_rates_2.ts", + "recharge_rates_3.ts", + "river_stages.ts", + "simulation.tdis", + "tides.ts", + "tides.txt", + "well_rates.ts", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf6/{sim_name}/{fname}", + fname=fname, + path=data_path / "mf6" / sim_name, + known_hash=None, + ) + # For this example, we will set up a temporary workspace. # Model input files and output files will reside here. temp_dir = TemporaryDirectory() model_name = "advgw_tidal" workspace = os.path.join(temp_dir.name, model_name) -data_pth = os.path.join("..", "..", "examples", "data", "mf6", "test005_advgw_tidal") +data_pth = data_path / "mf6" / sim_name assert os.path.isdir(data_pth) # + diff --git a/.docs/Notebooks/mf6_mnw2_tutorial01.py b/.docs/Notebooks/mf6_mnw2_tutorial01.py index 3703512e1..f81d6ddbc 100644 --- a/.docs/Notebooks/mf6_mnw2_tutorial01.py +++ b/.docs/Notebooks/mf6_mnw2_tutorial01.py @@ -17,13 +17,16 @@ # # Working with the Multi-node Well (MNW2) Package import os +import sys # + -import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import numpy as np import pandas as pd +import pooch import flopy @@ -33,6 +36,15 @@ print(f"flopy version: {flopy.__version__}") # - +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # ### Make an MNW2 package from scratch # + @@ -181,7 +193,30 @@ # ### Load some example MNW2 packages -path = os.path.join("..", "..", "examples", "data", "mnw2_examples") +folder_name = "mnw2_examples" + +file_names = { + "BadRiver_cal.mnw2": None, + "MNW2-Fig28.bas": None, + "MNW2-Fig28.dis": None, + "MNW2-Fig28.lpf": None, + "MNW2-Fig28.mnw2": None, + "MNW2-Fig28.mnwi": None, + "MNW2-Fig28.nam": None, + "MNW2-Fig28.oc": None, + "MNW2-Fig28.pcg": None, + "MNW2-Fig28.rch": None, + "MNW2-Fig28.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/{fname}", + fname=fname, + path=data_path / folder_name, + known_hash=fhash, + ) + +path = data_path / folder_name m = flopy.modflow.Modflow("MNW2-Fig28", model_ws=model_ws) dis = flopy.modflow.ModflowDis.load(os.path.join(path, "MNW2-Fig28.dis"), m) @@ -198,7 +233,7 @@ pd.DataFrame(mnw2.mnw["well-a"].stress_period_data) -path = os.path.join("..", "..", "examples", "data", "mnw2_examples") +path = data_path / "mnw2_examples" m = flopy.modflow.Modflow("br", model_ws=model_ws) mnw2 = flopy.modflow.ModflowMnw2.load(os.path.join(path, "BadRiver_cal.mnw2"), m) diff --git a/.docs/Notebooks/mf6_output_tutorial01.py b/.docs/Notebooks/mf6_output_tutorial01.py index 4044c1689..368cddba3 100644 --- a/.docs/Notebooks/mf6_output_tutorial01.py +++ b/.docs/Notebooks/mf6_output_tutorial01.py @@ -20,31 +20,68 @@ # by using the built in `.output` attribute on any MODFLOW 6 model or # package object -import os from pathlib import Path +from shutil import copytree from tempfile import TemporaryDirectory +import git import numpy as np +import pooch -# ## Package import import flopy -# ## Load a simple demonstration model +# ## Loading a model + +# Start by creating a temporary workspace and defining some names. exe_name = "mf6" -project_root_path = Path.cwd().parent.parent -ws = os.path.abspath(os.path.dirname("")) -sim_ws = str(project_root_path / "examples" / "data" / "mf6" / "test001e_UZF_3lay") +sim_name = "test001e_UZF_3lay" +temp_dir = TemporaryDirectory() +sim_ws = Path(temp_dir.name) + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +# Download files if needed. + +files = { + "chd_spd.txt": "4d87f60022832372981caa2bd162681d5c4b8b3fcf8bc7f5de533c96ad1ed03c", + "mfsim.nam": "2f7889dedb9e7befb45251f08f015bd5531a4952f4141295ebad9e550be365fd", + "simulation.tdis": "d466787698c88b7f229cf244f2c9f226a87628c0a5748819e4e34fd4edc48d4c", + "test001e_UZF_3lay.chd": "96a00121e7004b152a03d0759bf4abfd70f8a1ea21cbce6b9441f18ce4d89b45", + "test001e_UZF_3lay.dis": "d2f879dcba84ec4be8883d6e29ea9197dd0e67c4058fdde7b9e1de737d1e0639", + "test001e_UZF_3lay.ic": "6e434a9d42ffe1b126b26890476f6893e9ab526f3a4ee96e63d443fd9008e1df", + "test001e_UZF_3lay.ims": "c4ef9ebe359def38f0e9ed810b61af0aae9a437c57d54b1db00b8dda20e5b67d", + "test001e_UZF_3lay.nam": "078ea7b0a774546a93c2cedfb98dc686395332ece7df6493653b072d43b4b834", + "test001e_UZF_3lay.npf": "89181af1fd91fe59ea931aae02fe64f855f27c705ee9200c8a9c23831aa7bace", + "test001e_UZF_3lay.obs": "b9857f604c0594a466255f040bd5a47a1687a69ae3be749488bd8736ead7d106", + "test001e_UZF_3lay.oc": "5eb327ead17588a1faa8b5c7dd37844f7a63d98351ef8bb41df1162c87a94d02", + "test001e_UZF_3lay.sto": "8d808d0c2ae4edc114455db3f1766446f9f9d6d3775c46a70369a57509bff811", + "test001e_UZF_3lay.uzf": "97624f1102abef4985bb40f432523df76bd94e069ac8a4aa17455d0d5b8f146e", + "test001e_UZF_3lay_obs.hed": "78c67035fc6f0c5c1d6090c1ce1e50dcab75b361e4ed44dc951f11fd3915a388", +} + +for fname, fhash in files.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf6/{sim_name}/{fname}", + fname=fname, + path=data_path / "mf6" / sim_name, + known_hash=fhash, + ) # load the model sim = flopy.mf6.MFSimulation.load( - sim_ws=sim_ws, + sim_ws=data_path / "mf6" / sim_name, exe_name=exe_name, verbosity_level=0, ) # change the simulation path, rewrite the files, and run the model -temp_dir = TemporaryDirectory() -sim_ws = temp_dir.name sim.set_sim_path(sim_ws) sim.write_simulation(silent=True) sim.run_simulation(silent=True) diff --git a/.docs/Notebooks/mf6_parallel_model_splitting_example.py b/.docs/Notebooks/mf6_parallel_model_splitting_example.py index 7895f6bcf..4c97d4a49 100644 --- a/.docs/Notebooks/mf6_parallel_model_splitting_example.py +++ b/.docs/Notebooks/mf6_parallel_model_splitting_example.py @@ -22,10 +22,13 @@ import sys from pathlib import Path +from shutil import copy, copytree from tempfile import TemporaryDirectory +import git import matplotlib.pyplot as plt import numpy as np +import pooch import yaml import flopy @@ -33,12 +36,9 @@ from flopy.plot import styles from flopy.utils.geometry import LineString, Polygon -geometries = yaml.safe_load( - open(Path("../../examples/data/groundwater2023/geometries.yml")) -) +# Define a few utility functions. -# define a few utility functions def string2geom(geostring, conversion=None): if conversion is None: multiplier = 1.0 @@ -56,24 +56,72 @@ def string2geom(geostring, conversion=None): return res -# ## Example 1: splitting a simple structured grid model -# -# This example shows the basics of using the `Mf6Splitter()` class and applies the method to the Freyberg (1988) model. - -simulation_ws = Path("../../examples/data/mf6-freyberg") -sim = flopy.mf6.MFSimulation.load(sim_ws=simulation_ws) - -# Create a temporary directory for this example and run the Freyberg (1988) model. +# Create a temporary directory for this example. temp_dir = TemporaryDirectory() workspace = Path(temp_dir.name) -# +# Check if we are in the repository and define the data path. -sim.set_sim_path(workspace) -sim.write_simulation() -success, buff = sim.run_simulation(silent=True) -assert success +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +# Download and load geometries. + +geometries_fname = "geometries.yml" +geometries_fpath = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/groundwater2023/{geometries_fname}", + fname=geometries_fname, + path=workspace, + known_hash="4fb491f9dbd09ef04d6d067458e9866ac79d96448f70910e78c552131a12b6be", +) +geometries = yaml.safe_load(open(geometries_fpath)) + +# Download the Freyberg 1988 model. + +sim_name = "mf6-freyberg" +file_names = { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + +copytree(data_path / sim_name, workspace / sim_name) + +# Load the simulation, switch the workspace, and run the simulation. + +sim = flopy.mf6.MFSimulation.load(sim_ws=data_path / sim_name) +sim.set_sim_path(workspace / sim_name) +success, buff = sim.run_simulation(silent=True, report=True) +assert success, buff # Visualize the head results and boundary conditions from this model. @@ -234,7 +282,15 @@ def string2geom(geostring, conversion=None): # # Load an ASCII raster file -ascii_file = Path("../../examples/data/geospatial/fine_topo.asc") +ascii_file_name = "fine_topo.asc" +ascii_file = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/geospatial/{ascii_file_name}", + fname=ascii_file_name, + path=data_path / "geospatial", + known_hash=None, +) + +copy(data_path / "geospatial" / ascii_file_name, workspace / ascii_file_name) fine_topo = flopy.utils.Raster.load(ascii_file) fine_topo.plot() @@ -657,7 +713,7 @@ def string2geom(geostring, conversion=None): new_sim = mfsplit.split_model(split_array) temp_dir = TemporaryDirectory() -workspace = Path("temp") +workspace = Path(temp_dir.name) new_ws = workspace / "opt_split_models" new_sim.set_sim_path(new_ws) diff --git a/.docs/Notebooks/mf6_sfr_tutorial01.py b/.docs/Notebooks/mf6_sfr_tutorial01.py index 69d65bc40..774b17218 100644 --- a/.docs/Notebooks/mf6_sfr_tutorial01.py +++ b/.docs/Notebooks/mf6_sfr_tutorial01.py @@ -17,9 +17,13 @@ # # SFR2 package loading and querying import os +import sys # + -import sys +from pathlib import Path + +import git +import pooch import flopy @@ -31,17 +35,34 @@ m = flopy.modflow.Modflow() -# Read the SFR2 file -f = os.path.join( - "..", "..", "examples", "data", "mf2005_test", "testsfr2_tab_ICALC2.sfr" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +# Retrieve the SFR2 file +sim_name = "mf2005_test" +fname = "testsfr2_tab_ICALC2.sfr" +fpath = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=None, ) -stuff = open(f).readlines() + +# Read the SFR2 file + +stuff = open(fpath).readlines() stuff # Load the SFR2 file -sfr = flopy.modflow.ModflowSfr2.load(f, m, nper=50) +sfr = flopy.modflow.ModflowSfr2.load(fpath, m, nper=50) sfr.segment_data.keys() diff --git a/.docs/Notebooks/mf6_support_example.py b/.docs/Notebooks/mf6_support_example.py index 6f8cd97d8..52f5ca746 100644 --- a/.docs/Notebooks/mf6_support_example.py +++ b/.docs/Notebooks/mf6_support_example.py @@ -54,8 +54,20 @@ from shutil import copyfile from tempfile import TemporaryDirectory +import git +import pooch + proj_root = Path.cwd().parent.parent +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + import flopy # temporary directory @@ -244,9 +256,14 @@ model, pname="ic", strt=strt, filename=f"{model_name}.ic" ) # move external file data into model folder -icv_data_path = os.path.join( - "..", "..", "examples", "data", "mf6", "notebooks", "iconvert.txt" +fname = "iconvert.txt" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf6/notebooks/{fname}", + fname=fname, + path=data_path / "mf6" / "notebooks", + known_hash=None, ) +icv_data_path = data_path / "mf6" / "notebooks" / fname copyfile(icv_data_path, os.path.join(sim_path, "iconvert.txt")) # create storage package sto_package = flopy.mf6.ModflowGwfsto( diff --git a/.docs/Notebooks/mf_error_tutorial01.py b/.docs/Notebooks/mf_error_tutorial01.py index 367b5775f..57a28922a 100644 --- a/.docs/Notebooks/mf_error_tutorial01.py +++ b/.docs/Notebooks/mf_error_tutorial01.py @@ -19,17 +19,47 @@ # + import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git +import pooch + import flopy print(sys.version) print(f"flopy version: {flopy.__version__}") # - +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = [ + "bcf2ss.ba6", + "bcf2ss.bc6", + "bcf2ss.dis", + "bcf2ss.nam", + "bcf2ss.oc", + "bcf2ss.pcg", + "bcf2ss.rch", + "bcf2ss.riv", + "bcf2ss.wel", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf2005_test/{fname}", + fname=fname, + path=data_path / "mf2005_test", + known_hash=None, + ) + # #### Set the working directory -path = os.path.join("..", "..", "examples", "data", "mf2005_test") +path = data_path / "mf2005_test" # #### Load example dataset and change the model work space diff --git a/.docs/Notebooks/mf_load_tutorial.py b/.docs/Notebooks/mf_load_tutorial.py index 91db0b0db..4ea9077c2 100644 --- a/.docs/Notebooks/mf_load_tutorial.py +++ b/.docs/Notebooks/mf_load_tutorial.py @@ -23,6 +23,10 @@ # + import os import sys +from pathlib import Path + +import git +import pooch import flopy @@ -30,6 +34,14 @@ print(f"flopy version: {flopy.__version__}") # - +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + + # ## The `load()` method # # To load a MODFLOW 2005 model, use the `Modflow.load()` method. The method's first argument is the path or name of the model namefile. Other parameters include: @@ -38,7 +50,25 @@ # - `verbose`: whether to write diagnostic information useful for troubleshooting # - `check`: whether to check for model configuration errors -model_ws = os.path.join("..", "..", "examples", "data", "mf2005_test") +file_names = [ + "bcf2ss.ba6", + "bcf2ss.bc6", + "bcf2ss.dis", + "bcf2ss.nam", + "bcf2ss.oc", + "bcf2ss.pcg", + "bcf2ss.rch", + "bcf2ss.riv", + "bcf2ss.wel", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf2005_test/{fname}", + fname=fname, + path=data_path / "mf2005_test", + known_hash=None, + ) +model_ws = data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( "bcf2ss.nam", model_ws=model_ws, @@ -51,7 +81,31 @@ # # Below we load a model containig auxiliary variables, then access them. -model_ws = os.path.join("..", "..", "examples", "data", "mp6") +file_names = [ + "EXAMPLE.BA6", + "EXAMPLE.BUD", + "EXAMPLE.DIS", + "EXAMPLE.DIS.metadata", + "EXAMPLE.HED", + "EXAMPLE.LPF", + "EXAMPLE.LST", + "EXAMPLE.MPBAS", + "EXAMPLE.OC", + "EXAMPLE.PCG", + "EXAMPLE.RCH", + "EXAMPLE.RIV", + "EXAMPLE.WEL", + "EXAMPLE.mpnam", + "EXAMPLE.nam", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=None, + ) +model_ws = data_path / "mp6" ml = flopy.modflow.Modflow.load( "EXAMPLE.nam", model_ws=model_ws, diff --git a/.docs/Notebooks/mfusg_conduit_examples.py b/.docs/Notebooks/mfusg_conduit_examples.py index d8e86a928..4d5042382 100644 --- a/.docs/Notebooks/mfusg_conduit_examples.py +++ b/.docs/Notebooks/mfusg_conduit_examples.py @@ -20,11 +20,14 @@ # + import os import shutil +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib.pyplot as plt import numpy as np +import pooch import flopy @@ -42,7 +45,35 @@ # A vertical conduit well is located at the center of the domain and has a radius of 0.5 m. The well pumps 62,840 m3/d and is open fully to both aquifers from top to bottom. The CLN Process was used with a circular conduit geometry type to discretize the well bore with two conduit cells, one in each layer. The WEL Package was used to pump from the bottom CLN cell. # -model_ws = os.path.join("../../examples/data/mfusg_test", "03_conduit_confined") +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = [ + "ex3.bas", + "ex3.bcf", + "ex3.cln", + "ex3.dis", + "ex3.nam", + "ex3.oc", + "ex3.sms", + "ex3.wel", + "run.bat", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mfusg_test/03_conduit_confined/{fname}", + fname=fname, + path=data_path / "mfusg_test" / "03_conduit_confined", + known_hash=None, + ) + +model_ws = data_path / "mfusg_test" / "03_conduit_confined" mf = flopy.mfusg.MfUsg.load( "ex3.nam", model_ws=model_ws, exe_name="mfusg", check=False, verbose=True ) diff --git a/.docs/Notebooks/mfusg_freyberg_example.py b/.docs/Notebooks/mfusg_freyberg_example.py index aa39d9bf9..bd1ee73d5 100644 --- a/.docs/Notebooks/mfusg_freyberg_example.py +++ b/.docs/Notebooks/mfusg_freyberg_example.py @@ -28,10 +28,47 @@ # + from pprint import pformat +import git +import pooch + import flopy root_name = "freyberg.usg" -model_ws = Path.cwd().parent / "../examples/data" / root_name.replace(".", "_") + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = { + "freyberg.usg.bas": None, + "freyberg.usg.disu": None, + "freyberg.usg.ghb": None, + "freyberg.usg.gnc": None, + "freyberg.usg.gsf": None, + "freyberg.usg.gsf.with_comment": None, + "freyberg.usg.lpf": None, + "freyberg.usg.nam": None, + "freyberg.usg.oc": None, + "freyberg.usg.rch": None, + "freyberg.usg.sfr": None, + "freyberg.usg.sms": None, + "freyberg.usg.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{root_name.replace('.', '_')}/{fname}", + fname=fname, + path=data_path / root_name.replace(".", "_"), + known_hash=None, + ) + + +model_ws = data_path / root_name.replace(".", "_") # - # Now construct an `UnstructuredGrid` from a grid specification file. diff --git a/.docs/Notebooks/modelgrid_examples.py b/.docs/Notebooks/modelgrid_examples.py index f8bffc09a..e9afe08cb 100644 --- a/.docs/Notebooks/modelgrid_examples.py +++ b/.docs/Notebooks/modelgrid_examples.py @@ -29,14 +29,17 @@ # 3) __Useful methods and features__ import os +import sys # + -import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid @@ -52,13 +55,80 @@ mf6_exe = "mf6" gridgen_exe = "gridgen" + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +sim_data = { + "freyberg_multilayer_transient": { + "freyberg.bas": None, + "freyberg.cbc": None, + "freyberg.ddn": None, + "freyberg.dis": None, + "freyberg.drn": None, + "freyberg.hds": None, + "freyberg.list": None, + "freyberg.nam": None, + "freyberg.nwt": None, + "freyberg.oc": None, + "freyberg.rch": None, + "freyberg.upw": None, + "freyberg.wel": None, + }, + "mf6-freyberg": { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", + }, + "unstructured": { + "TriMesh_local.exp": None, + "TriMesh_usg.exp": None, + "Trimesh_circle.exp": None, + "headu.githds": None, + "ugrid_iverts.dat": None, + "ugrid_verts.dat": None, + }, +} + +for sim_name in sim_data: + for fname, fhash in sim_data[sim_name].items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + # + # set paths to each of our model types for this example notebook -spth = os.path.join("..", "..", "examples", "data", "freyberg_multilayer_transient") -spth6 = os.path.join("..", "..", "examples", "data", "mf6-freyberg") -vpth = os.path.join("..", "..", "examples", "data") -upth = os.path.join("..", "..", "examples", "data") -u_data_ws = os.path.join("..", "..", "examples", "data", "unstructured") +spth = data_path / "freyberg_multilayer_transient" +spth6 = data_path / "mf6-freyberg" +vpth = data_path +upth = data_path +u_data_ws = data_path / "unstructured" # temporary workspace temp_dir = TemporaryDirectory() diff --git a/.docs/Notebooks/modflow_postprocessing_example.py b/.docs/Notebooks/modflow_postprocessing_example.py index 656aef5d4..12e7984c3 100644 --- a/.docs/Notebooks/modflow_postprocessing_example.py +++ b/.docs/Notebooks/modflow_postprocessing_example.py @@ -22,11 +22,14 @@ # + import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy import flopy.utils.binaryfile as bf @@ -43,19 +46,89 @@ # + mfnam = "EXAMPLE.nam" -model_ws = "../../examples/data/mp6/" heads_file = "EXAMPLE.HED" # temporary directory temp_dir = TemporaryDirectory() workspace = temp_dir.name + + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +file_names = { + "EXAMPLE-1.endpoint": None, + "EXAMPLE-1.mpsim": None, + "EXAMPLE-2.endpoint": None, + "EXAMPLE-2.mplist": None, + "EXAMPLE-2.mpsim": None, + "EXAMPLE-3.endpoint": None, + "EXAMPLE-3.mplist": None, + "EXAMPLE-3.mpsim": None, + "EXAMPLE-3.pathline": None, + "EXAMPLE-4.endpoint": None, + "EXAMPLE-4.mplist": None, + "EXAMPLE-4.mpsim": None, + "EXAMPLE-4.timeseries": None, + "EXAMPLE-5.endpoint": None, + "EXAMPLE-5.mplist": None, + "EXAMPLE-5.mpsim": None, + "EXAMPLE-6.endpoint": None, + "EXAMPLE-6.mplist": None, + "EXAMPLE-6.mpsim": None, + "EXAMPLE-6.timeseries": None, + "EXAMPLE-7.endpoint": None, + "EXAMPLE-7.mplist": None, + "EXAMPLE-7.mpsim": None, + "EXAMPLE-7.timeseries": None, + "EXAMPLE-8.endpoint": None, + "EXAMPLE-8.mplist": None, + "EXAMPLE-8.mpsim": None, + "EXAMPLE-8.timeseries": None, + "EXAMPLE-9.endpoint": None, + "EXAMPLE-9.mplist": None, + "EXAMPLE-9.mpsim": None, + "EXAMPLE.BA6": None, + "EXAMPLE.BUD": None, + "EXAMPLE.DIS": None, + "EXAMPLE.DIS.metadata": None, + "EXAMPLE.HED": None, + "EXAMPLE.LPF": None, + "EXAMPLE.LST": None, + "EXAMPLE.MPBAS": None, + "EXAMPLE.OC": None, + "EXAMPLE.PCG": None, + "EXAMPLE.RCH": None, + "EXAMPLE.RIV": None, + "EXAMPLE.WEL": None, + "EXAMPLE.mpnam": None, + "EXAMPLE.nam": None, + "example-1.mplist": None, + "example-6.locations": None, + "example-7.locations": None, + "example-8.locations": None, + "example.basemap": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=fhash, + ) + # - # ### Load example model and head results -m = flopy.modflow.Modflow.load(mfnam, model_ws=model_ws) +m = flopy.modflow.Modflow.load(mfnam, model_ws=data_path / "mp6") -hdsobj = bf.HeadFile(model_ws + heads_file) +hdsobj = bf.HeadFile(data_path / "mp6" / heads_file) hds = hdsobj.get_data(kstpkper=(0, 2)) hds.shape diff --git a/.docs/Notebooks/modpath6_example.py b/.docs/Notebooks/modpath6_example.py index 5620b023d..093e67adf 100644 --- a/.docs/Notebooks/modpath6_example.py +++ b/.docs/Notebooks/modpath6_example.py @@ -29,10 +29,12 @@ from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch import flopy @@ -48,16 +50,87 @@ # + from pathlib import Path +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # temporary directory temp_dir = TemporaryDirectory() -model_ws = temp_dir.name +model_ws = Path(temp_dir.name) + +file_names = { + "EXAMPLE-1.endpoint": None, + "EXAMPLE-1.mpsim": None, + "EXAMPLE-2.endpoint": None, + "EXAMPLE-2.mplist": None, + "EXAMPLE-2.mpsim": None, + "EXAMPLE-3.endpoint": None, + "EXAMPLE-3.mplist": None, + "EXAMPLE-3.mpsim": None, + "EXAMPLE-3.pathline": None, + "EXAMPLE-4.endpoint": None, + "EXAMPLE-4.mplist": None, + "EXAMPLE-4.mpsim": None, + "EXAMPLE-4.timeseries": None, + "EXAMPLE-5.endpoint": None, + "EXAMPLE-5.mplist": None, + "EXAMPLE-5.mpsim": None, + "EXAMPLE-6.endpoint": None, + "EXAMPLE-6.mplist": None, + "EXAMPLE-6.mpsim": None, + "EXAMPLE-6.timeseries": None, + "EXAMPLE-7.endpoint": None, + "EXAMPLE-7.mplist": None, + "EXAMPLE-7.mpsim": None, + "EXAMPLE-7.timeseries": None, + "EXAMPLE-8.endpoint": None, + "EXAMPLE-8.mplist": None, + "EXAMPLE-8.mpsim": None, + "EXAMPLE-8.timeseries": None, + "EXAMPLE-9.endpoint": None, + "EXAMPLE-9.mplist": None, + "EXAMPLE-9.mpsim": None, + "EXAMPLE.BA6": None, + "EXAMPLE.BUD": None, + "EXAMPLE.DIS": None, + "EXAMPLE.DIS.metadata": None, + "EXAMPLE.HED": None, + "EXAMPLE.LPF": None, + "EXAMPLE.LST": None, + "EXAMPLE.MPBAS": None, + "EXAMPLE.OC": None, + "EXAMPLE.PCG": None, + "EXAMPLE.RCH": None, + "EXAMPLE.RIV": None, + "EXAMPLE.WEL": None, + "EXAMPLE.mpnam": None, + "EXAMPLE.nam": None, + "example-1.mplist": None, + "example-6.locations": None, + "example-7.locations": None, + "example-8.locations": None, + "example.basemap": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=fhash, + ) -model_path = Path.cwd().parent.parent / "examples" / "data" / "mp6" -mffiles = list(model_path.glob("EXAMPLE.*")) +shutil.copytree(data_path / "mp6", model_ws, dirs_exist_ok=True) -m = flopy.modflow.Modflow.load("EXAMPLE.nam", model_ws=model_path) +mffiles = list(model_ws.glob("EXAMPLE.*")) -hdsfile = flopy.utils.HeadFile(os.path.join(model_path, "EXAMPLE.HED")) +m = flopy.modflow.Modflow.load("EXAMPLE.nam", model_ws=model_ws) + +hdsfile = flopy.utils.HeadFile(os.path.join(model_ws, "EXAMPLE.HED")) hdsfile.get_kstpkper() hds = hdsfile.get_data(kstpkper=(0, 2)) @@ -93,7 +166,7 @@ modelname="ex6", exe_name="mp6", modflowmodel=m, - model_ws=str(model_path), + model_ws=str(model_ws), ) mpb = flopy.modpath.Modpath6Bas( @@ -109,10 +182,6 @@ start_time=(2, 0, 1.0), ) -shutil.copy(model_path / "EXAMPLE.DIS", join(model_ws, "EXAMPLE.DIS")) -shutil.copy(model_path / "EXAMPLE.HED", join(model_ws, "EXAMPLE.HED")) -shutil.copy(model_path / "EXAMPLE.BUD", join(model_ws, "EXAMPLE.BUD")) - mp.change_model_ws(model_ws) mp.write_name_file() mp.write_input() @@ -203,7 +272,7 @@ # Replace WEL package with MNW2, and create backward tracking simulation using particles released at MNW well. m2 = flopy.modflow.Modflow.load( - "EXAMPLE.nam", model_ws=str(model_path), exe_name="mf2005" + "EXAMPLE.nam", model_ws=str(model_ws), exe_name="mf2005" ) m2.get_package_list() diff --git a/.docs/Notebooks/mt3d-usgs_example.py b/.docs/Notebooks/mt3d-usgs_example.py index 00da7ad06..dac13647a 100644 --- a/.docs/Notebooks/mt3d-usgs_example.py +++ b/.docs/Notebooks/mt3d-usgs_example.py @@ -35,12 +35,15 @@ # + import sys +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy @@ -56,6 +59,15 @@ mfexe = "mfnwt" mtexe = "mt3dusgs" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # Make sure modelpth directory exists if not os.path.isdir(modelpth): os.makedirs(modelpth, exist_ok=True) @@ -587,8 +599,13 @@ def load_ts_from_otis(fname, iobs=1): ts5_mt3d = load_ts_from_SFT_output(fname_SFTout, nd=619) # OTIS results located here -fname_OTIS = ( - "../../examples/data/mt3d_test/mfnwt_mt3dusgs/sft_crnkNic/OTIS_solution.out" +fname = "OTIS_solution.out" +fname_OTIS = data_path / "mt3d_test" / "mfnwt_mt3dusgs" / "sft_crnkNic" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mt3d_test/mfnwt_mt3dusgs/sft_crnkNic/{fname}", + fname=fname, + path=data_path / "mt3d_test" / "mfnwt_mt3dusgs" / "sft_crnkNic", + known_hash=None, ) # Loading OTIS output diff --git a/.docs/Notebooks/mt3dms_examples.py b/.docs/Notebooks/mt3dms_examples.py index 4c2cd3862..66fac6551 100644 --- a/.docs/Notebooks/mt3dms_examples.py +++ b/.docs/Notebooks/mt3dms_examples.py @@ -34,15 +34,18 @@ # 10. Three-Dimensional Field Case Study import os +import sys # + -import sys +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy from flopy.utils.util_array import read1d @@ -51,7 +54,6 @@ exe_name_mf = "mf2005" exe_name_mt = "mt3dms" -datadir = os.path.join("..", "..", "examples", "data", "mt3d_test", "mt3dms") # temporary directory temp_dir = TemporaryDirectory() @@ -62,6 +64,28 @@ print(f"matplotlib version: {mpl.__version__}") print(f"flopy version: {flopy.__version__}") +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +datadir = data_path / "mt3d_test" / "mt3dms" + +file_names = { + "p08shead.dat": None, + "p10cinit.dat": None, + "p10shead.dat": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mt3d_test/mt3dms/{fname}", + fname=fname, + path=data_path / "mt3d_test" / "mt3dms", + known_hash=None, + ) # - diff --git a/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py b/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py index 85448762a..35fdc2d67 100644 --- a/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py +++ b/.docs/Notebooks/mt3dms_sft_lkt_uzt_tutorial.py @@ -31,11 +31,14 @@ # + import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import numpy as np import pandas as pd +import pooch import flopy @@ -55,6 +58,15 @@ temp_dir = TemporaryDirectory() model_ws = temp_dir.name +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + modelpth = os.path.join(model_ws, "no3") modelname = "no3" mfexe = "mfnwt" @@ -124,23 +136,29 @@ # ### Instantiate discretization (DIS) package for MODFLOW-NWT # + -elv_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "dis_arrays", - "grnd_elv.txt", -) # Top of Layer 1 elevation determined using GW Vistas and stored locally +fname = "grnd_elv.txt" +folder_name = "mt3d_example_sft_lkt_uzt" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/dis_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "dis_arrays", + known_hash=None, +) +elv_pth = data_path / folder_name / "dis_arrays" / fname grndElv = np.loadtxt(elv_pth) # Bottom of layer 1 elevation also determined from use of GUI and stored locally -bt1_pth = os.path.join( - "..", "..", "examples", "data", "mt3d_example_sft_lkt_uzt", "dis_arrays", "bot1.txt" +fname = "bot1.txt" +folder_name = "mt3d_example_sft_lkt_uzt" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/dis_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "dis_arrays", + known_hash=None, ) +bt1_pth = data_path / folder_name / "dis_arrays" / fname bot1Elv = np.loadtxt(bt1_pth) bot2Elv = np.ones(bot1Elv.shape) * 100 @@ -220,14 +238,13 @@ # ### Instantiate basic (BAS or BA6) package for MODFLOW-NWT # + -ibnd1_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "bas_arrays", - "ibnd_lay1.txt", +fname = "ibnd_lay1.txt" +ibnd1_pth = data_path / folder_name / "bas_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/bas_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "bas_arrays", + known_hash=None, ) ibnd1 = np.loadtxt(ibnd1_pth) ibnd2 = np.ones(ibnd1.shape) @@ -236,36 +253,33 @@ ibnd = [ibnd1, ibnd2, ibnd3] ibnd = np.array(ibnd) -StHd1_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "bas_arrays", - "strthd1.txt", +fname = "strthd1.txt" +StHd1_pth = data_path / folder_name / "bas_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/bas_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "bas_arrays", + known_hash=None, ) StHd1 = np.loadtxt(StHd1_pth) -StHd2_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "bas_arrays", - "strthd2.txt", +fname = "strthd2.txt" +StHd2_pth = data_path / folder_name / "bas_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/bas_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "bas_arrays", + known_hash=None, ) StHd2 = np.loadtxt(StHd2_pth) -StHd3_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "bas_arrays", - "strthd3.txt", +fname = "strthd3.txt" +StHd3_pth = data_path / folder_name / "bas_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/bas_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "bas_arrays", + known_hash=None, ) StHd3 = np.loadtxt(StHd3_pth) @@ -316,28 +330,26 @@ # Remember that the cell indices stored in the pre-prepared NO3_ReachInput.csv file are based on 0-based indexing. # Flopy will convert to 1-based when it writes the files -rpth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "sfr_data", - "no3_reachinput.csv", +fname = "no3_reachinput.csv" +rpth = data_path / folder_name / "sfr_data" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/sfr_data/{fname}", + fname=fname, + path=data_path / folder_name / "sfr_data", + known_hash=None, ) reach_data = np.genfromtxt(rpth, delimiter=",", names=True) reach_data # Read pre-prepared segment data into numpy recarrays using numpy.genfromtxt() -spth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "sfr_data", - "no3_segmentdata.csv", +fname = "no3_segmentdata.csv" +spth = data_path / folder_name / "sfr_data" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/sfr_data/{fname}", + fname=fname, + path=data_path / folder_name / "sfr_data", + known_hash=None, ) ss_segment_data = np.genfromtxt(spth, delimiter=",", names=True) segment_data = {0: ss_segment_data, 1: ss_segment_data} @@ -378,14 +390,13 @@ # + # Read pre-prepared lake arrays -LakArr_pth = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "lak_arrays", - "lakarr1.txt", +fname = "lakarr1.txt" +LakArr_pth = data_path / folder_name / "lak_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/lak_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "lak_arrays", + known_hash=None, ) LakArr_lyr1 = np.loadtxt(LakArr_pth) LakArr_lyr2 = np.zeros(LakArr_lyr1.shape) @@ -510,23 +521,21 @@ thts = 0.30 thti = 0.13079 -fname_uzbnd = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "uzf_arrays", - "iuzbnd.txt", +fname = "iuzbnd.txt" +fname_uzbnd = data_path / folder_name / "uzf_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/uzf_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "uzf_arrays", + known_hash=None, ) -fname_runbnd = os.path.join( - "..", - "..", - "examples", - "data", - "mt3d_example_sft_lkt_uzt", - "uzf_arrays", - "irunbnd.txt", +fname = "irunbnd.txt" +fname_runbnd = data_path / folder_name / "uzf_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/uzf_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "uzf_arrays", + known_hash=None, ) iuzfbnd = np.loadtxt(fname_uzbnd) @@ -561,11 +570,21 @@ # ### Instantiate Drain (DRN) package for MODFLOW-NWT # + -fname_drnElv = os.path.join( - "..", "..", "examples", "data", "mt3d_example_sft_lkt_uzt", "drn_arrays", "elv.txt" +fname = "elv.txt" +fname_drnElv = data_path / folder_name / "drn_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/drn_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "drn_arrays", + known_hash=None, ) -fname_drnCond = os.path.join( - "..", "..", "examples", "data", "mt3d_example_sft_lkt_uzt", "drn_arrays", "cond.txt" +fname = "cond.txt" +fname_drnCond = data_path / folder_name / "drn_arrays" / fname +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/drn_arrays/{fname}", + fname=fname, + path=data_path / folder_name / "drn_arrays", + known_hash=None, ) drnElv = np.loadtxt(fname_drnElv) diff --git a/.docs/Notebooks/nwt_option_blocks_tutorial.py b/.docs/Notebooks/nwt_option_blocks_tutorial.py index 3e92a416b..ac9f33b66 100644 --- a/.docs/Notebooks/nwt_option_blocks_tutorial.py +++ b/.docs/Notebooks/nwt_option_blocks_tutorial.py @@ -26,8 +26,12 @@ # + import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git +import pooch + import flopy from flopy.utils import OptionBlock @@ -35,13 +39,40 @@ print(f"flopy version: {flopy.__version__}") # + -load_ws = os.path.join("..", "..", "examples", "data", "options", "sagehen") # temporary directory temp_dir = TemporaryDirectory() model_ws = os.path.join(temp_dir.name, "nwt_options", "output") # - +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = { + "sagehen.bas": None, + "sagehen.dis": None, + "sagehen.lpf": None, + "sagehen.nam": None, + "sagehen.nwt": None, + "sagehen.oc": None, + "sagehen.sfr": None, + "sagehen.uzf": None, + "sagehen.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/options/sagehen/{fname}", + fname=fname, + path=data_path / "options" / "sagehen", + known_hash=None, + ) + # ## Loading a MODFLOW-NWT model that has option block options # # It is critical to set the `version` flag in `flopy.modflow.Modflow.load()` to `version='mfnwt'` @@ -52,7 +83,10 @@ mfexe = "mfnwt" ml = flopy.modflow.Modflow.load( - "sagehen.nam", model_ws=load_ws, exe_name=mfexe, version="mfnwt" + "sagehen.nam", + model_ws=data_path / "options" / "sagehen", + exe_name=mfexe, + version="mfnwt", ) ml.change_model_ws(new_pth=model_ws) ml.write_input() diff --git a/.docs/Notebooks/plot_array_example.py b/.docs/Notebooks/plot_array_example.py index e97435a09..f3608ce56 100644 --- a/.docs/Notebooks/plot_array_example.py +++ b/.docs/Notebooks/plot_array_example.py @@ -23,10 +23,13 @@ import os import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import numpy as np +import pooch # + from IPython.display import Image @@ -44,12 +47,67 @@ version = "mf2005" exe_name = "mf2005" -# Set the paths -loadpth = os.path.join("..", "..", "examples", "data", "secp") + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +file_names = { + "secp.ba6": None, + "secp.chd": None, + "secp.dis": None, + "secp.gmg": None, + "secp.lpf": None, + "secp.mlt": None, + "secp.nam": None, + "secp.oc": None, + "secp.rch": None, + "secp.riv": None, + "secp.wel": None, + "secp.zon": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/secp/{fname}", + fname=fname, + path=data_path / "secp", + known_hash=None, + ) + +file_names = { + "HK1.DAT": None, + "HK10.DAT": None, + "HK11.DAT": None, + "HK12.DAT": None, + "HK13.DAT": None, + "HK14.DAT": None, + "HK15.DAT": None, + "HK16.DAT": None, + "HK2.DAT": None, + "HK3.DAT": None, + "HK4.DAT": None, + "HK5.DAT": None, + "HK6.DAT": None, + "HK7.DAT": None, + "HK8.DAT": None, + "HK9.DAT": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/secp/ref/{fname}", + fname=fname, + path=data_path / "secp" / "ref", + known_hash=None, + ) # temporary directory temp_dir = TemporaryDirectory() -modelpth = temp_dir.name +modelpth = Path(temp_dir.name) # make sure modelpth directory exists if not os.path.isdir(modelpth): @@ -63,14 +121,13 @@ # + ml = flopy.modflow.Modflow.load( - "secp.nam", model_ws=loadpth, exe_name=exe_name, version=version + "secp.nam", model_ws=data_path / "secp", exe_name=exe_name, version=version ) ml.change_model_ws(new_pth=modelpth) ml.write_input() success, buff = ml.run_model(silent=True) -if not success: - print("Something bad happened.") +assert success # confirm that the model files have been created for f in files: diff --git a/.docs/Notebooks/plot_cross_section_example.py b/.docs/Notebooks/plot_cross_section_example.py index 1799b2e81..68f4c6151 100644 --- a/.docs/Notebooks/plot_cross_section_example.py +++ b/.docs/Notebooks/plot_cross_section_example.py @@ -27,12 +27,16 @@ # + pycharm={"name": "#%%\n"} import os import sys +from pathlib import Path from pprint import pformat +from shutil import copytree from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy @@ -49,10 +53,41 @@ vmf6 = "mf6" exe_name_mf6 = "mf6" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +sim_name = "freyberg" + +file_names = { + "freyberg.bas": "63266024019fef07306b8b639c6c67d5e4b22f73e42dcaa9db18b5e0f692c097", + "freyberg.dis": "62d0163bf36c7ee9f7ee3683263e08a0abcdedf267beedce6dd181600380b0a2", + "freyberg.githds": "abe92497b55e6f6c73306e81399209e1cada34cf794a7867d776cfd18303673b", + "freyberg.gitlist": "aef02c664344a288264d5f21e08a748150e43bb721a16b0e3f423e6e3e293056", + "freyberg.lpf": "06500bff979424f58e5e4fbd07a7bdeb0c78f31bd08640196044b6ccefa7a1fe", + "freyberg.nam": "e66321007bb603ef55ed2ba41f4035ba6891da704a4cbd3967f0c66ef1532c8f", + "freyberg.oc": "532905839ccbfce01184980c230b6305812610b537520bf5a4abbcd3bd703ef4", + "freyberg.pcg": "0d1686fac4680219fffdb56909296c5031029974171e25d4304e70fa96ebfc38", + "freyberg.rch": "37a1e113a7ec16b61417d1fa9710dd111a595de738a367bd34fd4a359c480906", + "freyberg.riv": "7492a1d5eb23d6812ec7c8227d0ad4d1e1b35631a765c71182b71e3bd6a6d31d", + "freyberg.wel": "00aa55f59797c02f0be5318a523b36b168fc6651f238f34e8b0938c04292d3e7", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + + # Set the paths -loadpth = os.path.join("..", "..", "examples", "data", "freyberg") tempdir = TemporaryDirectory() -modelpth = tempdir.name +modelpth = Path(tempdir.name) # + [markdown] pycharm={"name": "#%% md\n"} # ### Load and Run an Existing MODFLOW-2005 Model @@ -60,7 +95,7 @@ # + ml = flopy.modflow.Modflow.load( - "freyberg.nam", model_ws=loadpth, exe_name=exe_name_2005, version=v2005 + "freyberg.nam", model_ws=data_path / sim_name, exe_name=exe_name_2005, version=v2005 ) ml.change_model_ws(new_pth=str(modelpth)) ml.write_input() @@ -319,6 +354,60 @@ # # Let's plot the shapefiles and the Freyberg model using `PlotMapView` for visualization purposes and then plot the cross-section. +file_names = { + "bedrock_outcrop_hole.dbf": "c48510bc0b04405e4d3433e6cd892351c8342a7c46215f48332a7e6292249da6", + "bedrock_outcrop_hole.sbn": "48fd1496d84822c9637d7f3065edf4dfa2038406be8fa239cb451b1a3b28127c", + "bedrock_outcrop_hole.sbx": "9a36aee5f3a4bcff0a453ab743a7523ea19acb8841e8273bbda34f27d7237ea5", + "bedrock_outcrop_hole.shp": "25c241ac90dd47be28f761ba60ba94a511744f5219600e35a80a93f19ec99f97", + "bedrock_outcrop_hole.shx": "88b06395fa4c58ea04d300e10e6f6ea81e17fb0baa20d8ac78470d19101430be", + "bedrock_outcrop_hole_rotate14.dbf": "e05bbfc826fc069666a05e949acc833b54de51b14267c9c54b1c129b4a8ab82d", + "bedrock_outcrop_hole_rotate14.sbn": "136d8f86b8a13abc8f0386108228ca398037cf8c28ba6077086fd7e1fd54abf7", + "bedrock_outcrop_hole_rotate14.sbx": "1c2f2f2791db9c752fb1b355f13e46a8740ccd66654ae34d130172a3bdcda805", + "bedrock_outcrop_hole_rotate14.shp": "3e722d8fa9331ab498dbf9544085b30f60d2e38cc82a0955792d11a4e6a4419d", + "bedrock_outcrop_hole_rotate14.shp.xml": "ff6a3e80d10d9e68863ffe224e8130b862c13c2265d3a604342eb20a700d38fd", + "bedrock_outcrop_hole_rotate14.shx": "32a75461fab39b21769c474901254e7cbd24073c53d62b494fd70080cfcd3383", + "cross_section.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "cross_section.dbf": "3b050b1d296a7efe1b4f001c78030d5c81f79d3cd101d459e4426944fbd4e8e7", + "cross_section.sbn": "3b6a8f72f78f7b0d12e5823d6e8307040cfd5af88a8fb9427687d027aa805126", + "cross_section.sbx": "72e33139aaa99a8d12922af3774bd6b1a73613fc1bc852d1a1d1426ef48a832a", + "cross_section.shp": "0eb9e37dcbdbb5d932101c4c5bcb971271feb2c1d81d2a5f8dbc0fbf8d799ee5", + "cross_section.shp.xml": "ff99002ecd63a843fe628c107dfb02926b6838132c6f503db38b792644fb368e", + "cross_section.shx": "c6fa1307e1c32c535842796b24b2a0a07865065ace3324b0f6b1b71e9c1a8e1e", + "cross_section_rotate14.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "cross_section_rotate14.dbf": "72f8ed25c45a92822fe593862e543ae4167357cbc8fba4f24b889aa2bbf2729a", + "cross_section_rotate14.sbn": "3f7a3b66cf58be8c979353d2c75777303035e19ff58d96a089dde5c95fa8b597", + "cross_section_rotate14.sbx": "7d40bc92b42fde2af01a2805c9205c18c0fe89ae7cf1ba88ac6627b7c6a69b89", + "cross_section_rotate14.shp": "5f0ea7a65b5ddc9a43c874035969e30d58ae578aec9feb6b0e8538b68d5bd0d2", + "cross_section_rotate14.shp.xml": "79e38d9542ce764ace47883c673cf1d9aab16cd7851ae62a8e9bf27ce1091e13", + "cross_section_rotate14.shx": "b750b9d44ef31e0c593e2f78acfc08813667bb73733e6524f1b417e605cae65d", + "model_extent.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "model_extent.dbf": "72f8ed25c45a92822fe593862e543ae4167357cbc8fba4f24b889aa2bbf2729a", + "model_extent.sbn": "622376387ac9686e54acc6c57ace348c217d3a82e626274f32911a1d0006a164", + "model_extent.sbx": "2957bc1b5c918e20089fb6f6998d60d4488995d174bac21afa8e3a2af90b3489", + "model_extent.shp": "c72d5a4c703100e98c356c7645ad4b0bcc124c55e0757e55c8cd8663c7bf15c6", + "model_extent.shx": "e8d3b5618f0c248b59284f4f795f5de8207aec5b15ed60ce8da5a021c1043e2f", + "wells_locations.dbf": "965c846ec0b8f0d27570ef0bdaadfbcb6e718ed70ab89c8dda01d3b819e7a7de", + "wells_locations.sbn": "63f8ad670c6ba53ddec13069e42cfd86f27b6d47c5d0b3f2c25dfd6fb6b55825", + "wells_locations.sbx": "8420907d426c44c38315a5bdc0b24fe07a8cd2cc9a7fc60b817500b8cda79a34", + "wells_locations.shp": "ee53a4532b513f5b8bcd37ee3468dc4b2c8f6afab6cfc5110d74362c79e52287", + "wells_locations.shx": "6e816e96ed0726c2acc61392d2a82df5e9265ab5f5b00dd12f765b139840be79", + "wells_locations_rotate14.dbf": "d9b3636b4312c2f76c837e698bcb0d8ef9f4bbaa1765c484787a9f9d7f8bbaae", + "wells_locations_rotate14.sbn": "b436e34b8f145966b18d571b47ebc18e35671ec73fca1abbc737d9e1aa984bfb", + "wells_locations_rotate14.sbx": "24911f8905155882ce76b0330c9ba5ed449ca985d46833ebc45eee11faabbdaf", + "wells_locations_rotate14.shp": "695894af4678358320fb914e872cadb2613fae2e54c2d159f40c02fa558514cf", + "wells_locations_rotate14.shp.xml": "288183eb273c1fc2facb49d51c34bcafb16710189242da48f7717c49412f3e29", + "wells_locations_rotate14.shx": "da3374865cbf864f81dd69192ab616d1093d2159ac3c682fe2bfc4c295a28e42", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/gis/{fname}", + fname=fname, + path=data_path / sim_name / "gis", + known_hash=fhash, + ) + +copytree(data_path / sim_name / "gis", modelpth / "gis") + # + pycharm={"name": "#%%\n"} # Setup the figure and PlotMapView. Show a very faint map of ibound and # model grid by specifying a transparency alpha value. @@ -333,7 +422,7 @@ mapview = flopy.plot.PlotMapView(model=ml) # Plot a shapefile of -shp = os.path.join(loadpth, "gis", "bedrock_outcrop_hole_rotate14") +shp = os.path.join(modelpth, "gis", "bedrock_outcrop_hole_rotate14") patch_collection = mapview.plot_shapefile( shp, edgecolor="green", @@ -341,13 +430,13 @@ alpha=0.5, # facecolor='none', ) # Plot a shapefile of a cross-section line -shp = os.path.join(loadpth, "gis", "cross_section_rotate14") +shp = os.path.join(modelpth, "gis", "cross_section_rotate14") patch_collection = mapview.plot_shapefile( shp, radius=0, lw=3, edgecolor="red", facecolor="None" ) # Plot a shapefile of well locations -shp = os.path.join(loadpth, "gis", "wells_locations_rotate14") +shp = os.path.join(modelpth, "gis", "wells_locations_rotate14") patch_collection = mapview.plot_shapefile(shp, radius=100, facecolor="red") # Plot the grid and boundary conditions over the top @@ -361,7 +450,7 @@ # + pycharm={"name": "#%%\n"} # get the vertices for cross-section lines in a shapefile -fpth = os.path.join(loadpth, "gis", "cross_section_rotate14") +fpth = os.path.join(modelpth, "gis", "cross_section_rotate14") line = flopy.plot.plotutil.shapefile_get_vertices(fpth) # Set up the figure @@ -385,7 +474,7 @@ # + pycharm={"name": "#%%\n"} # get the vertices for cross-section lines in a shapefile -fpth = os.path.join(loadpth, "gis", "cross_section_rotate14") +fpth = os.path.join(modelpth, "gis", "cross_section_rotate14") line = flopy.plot.plotutil.shapefile_get_vertices(fpth) # Set up the figure @@ -407,12 +496,45 @@ # # `PlotCrossSection` has support for MODFLOW-6 models and operates in the same fashion for Structured Grids, Vertex Grids, and Unstructured Grids. Here is a short example on how to plot with MODFLOW-6 structured grids using a version of the Freyberg model created for MODFLOW-6| +sim_name = "mf6-freyberg" +sim_path = modelpth / "mf6" +file_names = { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + # + # load the Freyberg model into mf6-flopy and run the simulation -sim_name = "mfsim.nam" -sim_path = os.path.join("..", "..", "examples", "data", "mf6-freyberg") sim = flopy.mf6.MFSimulation.load( - sim_name=sim_name, version=vmf6, exe_name=exe_name_mf6, sim_ws=sim_path + sim_name="mfsim.nam", + version=vmf6, + exe_name=exe_name_mf6, + sim_ws=data_path / sim_name, ) sim.set_sim_path(modelpth) diff --git a/.docs/Notebooks/plot_map_view_example.py b/.docs/Notebooks/plot_map_view_example.py index 78e3cb961..ef3a3e8dc 100644 --- a/.docs/Notebooks/plot_map_view_example.py +++ b/.docs/Notebooks/plot_map_view_example.py @@ -28,12 +28,16 @@ # + import os import sys +from pathlib import Path from pprint import pformat +from shutil import copytree from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import shapefile import flopy @@ -51,21 +55,51 @@ vmf6 = "mf6" exe_name_mf6 = "mf6" exe_mp = "mp6" +sim_name = "freyberg" # Set the paths -loadpth = os.path.join("..", "..", "examples", "data", "freyberg") tempdir = TemporaryDirectory() -modelpth = tempdir.name +modelpth = Path(tempdir.name) + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() # + [markdown] pycharm={"name": "#%% md\n"} # ### Load and Run an Existing MODFLOW-2005 Model -# A model called the "Freyberg Model" is located in the loadpth folder. In the following code block, we load that model, then change into a new workspace (modelpth) where we recreate and run the model. For this to work properly, the MODFLOW-2005 executable (mf2005) must be in the path. We verify that it worked correctly by checking for the presence of freyberg.hds and freyberg.cbc. +# A model called the "Freyberg Model" is located in the modelpth folder. In the following code block, we load that model, then change into a new workspace (modelpth) where we recreate and run the model. For this to work properly, the MODFLOW-2005 executable (mf2005) must be in the path. We verify that it worked correctly by checking for the presence of freyberg.hds and freyberg.cbc. + +file_names = { + "freyberg.bas": "63266024019fef07306b8b639c6c67d5e4b22f73e42dcaa9db18b5e0f692c097", + "freyberg.dis": "62d0163bf36c7ee9f7ee3683263e08a0abcdedf267beedce6dd181600380b0a2", + "freyberg.githds": "abe92497b55e6f6c73306e81399209e1cada34cf794a7867d776cfd18303673b", + "freyberg.gitlist": "aef02c664344a288264d5f21e08a748150e43bb721a16b0e3f423e6e3e293056", + "freyberg.lpf": "06500bff979424f58e5e4fbd07a7bdeb0c78f31bd08640196044b6ccefa7a1fe", + "freyberg.nam": "e66321007bb603ef55ed2ba41f4035ba6891da704a4cbd3967f0c66ef1532c8f", + "freyberg.oc": "532905839ccbfce01184980c230b6305812610b537520bf5a4abbcd3bd703ef4", + "freyberg.pcg": "0d1686fac4680219fffdb56909296c5031029974171e25d4304e70fa96ebfc38", + "freyberg.rch": "37a1e113a7ec16b61417d1fa9710dd111a595de738a367bd34fd4a359c480906", + "freyberg.riv": "7492a1d5eb23d6812ec7c8227d0ad4d1e1b35631a765c71182b71e3bd6a6d31d", + "freyberg.wel": "00aa55f59797c02f0be5318a523b36b168fc6651f238f34e8b0938c04292d3e7", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) # + ml = flopy.modflow.Modflow.load( - "freyberg.nam", model_ws=loadpth, exe_name=exe_name_2005, version=v2005 + "freyberg.nam", model_ws=data_path / sim_name, exe_name=exe_name_2005, version=v2005 ) -ml.change_model_ws(new_pth=modelpth) +ml.change_model_ws(modelpth) ml.write_input() success, buff = ml.run_model(silent=True, report=True) assert success, pformat(buff) @@ -432,6 +466,60 @@ # # The shapefile must have intersecting geographic coordinates as the `PlotMapView` object in order for it to overlay correctly on the plot. The `plot_shapefile()` method and function do not use any of the projection information that may be stored with the shapefile. If you reset `xoff`, `yoff`, and `angrot` in the `ml.modelgrid.set_coord_info()` call below, you will see that the grid will no longer overlay correctly with the shapefile. +file_names = { + "bedrock_outcrop_hole.dbf": "c48510bc0b04405e4d3433e6cd892351c8342a7c46215f48332a7e6292249da6", + "bedrock_outcrop_hole.sbn": "48fd1496d84822c9637d7f3065edf4dfa2038406be8fa239cb451b1a3b28127c", + "bedrock_outcrop_hole.sbx": "9a36aee5f3a4bcff0a453ab743a7523ea19acb8841e8273bbda34f27d7237ea5", + "bedrock_outcrop_hole.shp": "25c241ac90dd47be28f761ba60ba94a511744f5219600e35a80a93f19ec99f97", + "bedrock_outcrop_hole.shx": "88b06395fa4c58ea04d300e10e6f6ea81e17fb0baa20d8ac78470d19101430be", + "bedrock_outcrop_hole_rotate14.dbf": "e05bbfc826fc069666a05e949acc833b54de51b14267c9c54b1c129b4a8ab82d", + "bedrock_outcrop_hole_rotate14.sbn": "136d8f86b8a13abc8f0386108228ca398037cf8c28ba6077086fd7e1fd54abf7", + "bedrock_outcrop_hole_rotate14.sbx": "1c2f2f2791db9c752fb1b355f13e46a8740ccd66654ae34d130172a3bdcda805", + "bedrock_outcrop_hole_rotate14.shp": "3e722d8fa9331ab498dbf9544085b30f60d2e38cc82a0955792d11a4e6a4419d", + "bedrock_outcrop_hole_rotate14.shp.xml": "ff6a3e80d10d9e68863ffe224e8130b862c13c2265d3a604342eb20a700d38fd", + "bedrock_outcrop_hole_rotate14.shx": "32a75461fab39b21769c474901254e7cbd24073c53d62b494fd70080cfcd3383", + "cross_section.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "cross_section.dbf": "3b050b1d296a7efe1b4f001c78030d5c81f79d3cd101d459e4426944fbd4e8e7", + "cross_section.sbn": "3b6a8f72f78f7b0d12e5823d6e8307040cfd5af88a8fb9427687d027aa805126", + "cross_section.sbx": "72e33139aaa99a8d12922af3774bd6b1a73613fc1bc852d1a1d1426ef48a832a", + "cross_section.shp": "0eb9e37dcbdbb5d932101c4c5bcb971271feb2c1d81d2a5f8dbc0fbf8d799ee5", + "cross_section.shp.xml": "ff99002ecd63a843fe628c107dfb02926b6838132c6f503db38b792644fb368e", + "cross_section.shx": "c6fa1307e1c32c535842796b24b2a0a07865065ace3324b0f6b1b71e9c1a8e1e", + "cross_section_rotate14.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "cross_section_rotate14.dbf": "72f8ed25c45a92822fe593862e543ae4167357cbc8fba4f24b889aa2bbf2729a", + "cross_section_rotate14.sbn": "3f7a3b66cf58be8c979353d2c75777303035e19ff58d96a089dde5c95fa8b597", + "cross_section_rotate14.sbx": "7d40bc92b42fde2af01a2805c9205c18c0fe89ae7cf1ba88ac6627b7c6a69b89", + "cross_section_rotate14.shp": "5f0ea7a65b5ddc9a43c874035969e30d58ae578aec9feb6b0e8538b68d5bd0d2", + "cross_section_rotate14.shp.xml": "79e38d9542ce764ace47883c673cf1d9aab16cd7851ae62a8e9bf27ce1091e13", + "cross_section_rotate14.shx": "b750b9d44ef31e0c593e2f78acfc08813667bb73733e6524f1b417e605cae65d", + "model_extent.cpg": "3ad3031f5503a4404af825262ee8232cc04d4ea6683d42c5dd0a2f2a27ac9824", + "model_extent.dbf": "72f8ed25c45a92822fe593862e543ae4167357cbc8fba4f24b889aa2bbf2729a", + "model_extent.sbn": "622376387ac9686e54acc6c57ace348c217d3a82e626274f32911a1d0006a164", + "model_extent.sbx": "2957bc1b5c918e20089fb6f6998d60d4488995d174bac21afa8e3a2af90b3489", + "model_extent.shp": "c72d5a4c703100e98c356c7645ad4b0bcc124c55e0757e55c8cd8663c7bf15c6", + "model_extent.shx": "e8d3b5618f0c248b59284f4f795f5de8207aec5b15ed60ce8da5a021c1043e2f", + "wells_locations.dbf": "965c846ec0b8f0d27570ef0bdaadfbcb6e718ed70ab89c8dda01d3b819e7a7de", + "wells_locations.sbn": "63f8ad670c6ba53ddec13069e42cfd86f27b6d47c5d0b3f2c25dfd6fb6b55825", + "wells_locations.sbx": "8420907d426c44c38315a5bdc0b24fe07a8cd2cc9a7fc60b817500b8cda79a34", + "wells_locations.shp": "ee53a4532b513f5b8bcd37ee3468dc4b2c8f6afab6cfc5110d74362c79e52287", + "wells_locations.shx": "6e816e96ed0726c2acc61392d2a82df5e9265ab5f5b00dd12f765b139840be79", + "wells_locations_rotate14.dbf": "d9b3636b4312c2f76c837e698bcb0d8ef9f4bbaa1765c484787a9f9d7f8bbaae", + "wells_locations_rotate14.sbn": "b436e34b8f145966b18d571b47ebc18e35671ec73fca1abbc737d9e1aa984bfb", + "wells_locations_rotate14.sbx": "24911f8905155882ce76b0330c9ba5ed449ca985d46833ebc45eee11faabbdaf", + "wells_locations_rotate14.shp": "695894af4678358320fb914e872cadb2613fae2e54c2d159f40c02fa558514cf", + "wells_locations_rotate14.shp.xml": "288183eb273c1fc2facb49d51c34bcafb16710189242da48f7717c49412f3e29", + "wells_locations_rotate14.shx": "da3374865cbf864f81dd69192ab616d1093d2159ac3c682fe2bfc4c295a28e42", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/gis/{fname}", + fname=fname, + path=data_path / sim_name / "gis", + known_hash=fhash, + ) + +copytree(data_path / sim_name / "gis", modelpth / "gis") + # + pycharm={"name": "#%%\n"} # Setup the figure and PlotMapView. Show a very faint map of ibound and # model grid by specifying a transparency alpha value. @@ -444,7 +532,7 @@ mapview = flopy.plot.PlotMapView(model=ml, ax=ax) # Plot a shapefile of -shp = os.path.join(loadpth, "gis", "bedrock_outcrop_hole") +shp = os.path.join(modelpth, "gis", "bedrock_outcrop_hole") patch_collection = mapview.plot_shapefile( shp, edgecolor="green", @@ -452,13 +540,13 @@ alpha=0.5, # facecolor='none', ) # Plot a shapefile of a cross-section line -shp = os.path.join(loadpth, "gis", "cross_section") +shp = os.path.join(modelpth, "gis", "cross_section") patch_collection = mapview.plot_shapefile( shp, radius=0, lw=[3, 1.5], edgecolor=["red", "green"], facecolor="None" ) # Plot a shapefile of well locations -shp = os.path.join(loadpth, "gis", "wells_locations") +shp = os.path.join(modelpth, "gis", "wells_locations") patch_collection = mapview.plot_shapefile(shp, radius=100, facecolor="red") # Plot the grid and boundary conditions over the top @@ -483,7 +571,7 @@ mapview = flopy.plot.PlotMapView(model=ml) # Plot a shapefile of -shp = os.path.join(loadpth, "gis", "bedrock_outcrop_hole_rotate14") +shp = os.path.join(modelpth, "gis", "bedrock_outcrop_hole_rotate14") patch_collection = mapview.plot_shapefile( shp, edgecolor="green", @@ -491,11 +579,11 @@ alpha=0.5, # facecolor='none', ) # Plot a shapefile of a cross-section line -shp = os.path.join(loadpth, "gis", "cross_section_rotate14") +shp = os.path.join(modelpth, "gis", "cross_section_rotate14") patch_collection = mapview.plot_shapefile(shp, lw=3, edgecolor="red") # Plot a shapefile of well locations -shp = os.path.join(loadpth, "gis", "wells_locations_rotate14") +shp = os.path.join(modelpth, "gis", "wells_locations_rotate14") patch_collection = mapview.plot_shapefile(shp, radius=100, facecolor="red") # Plot the grid and boundary conditions over the top @@ -527,16 +615,16 @@ # + pycharm={"name": "#%%\n"} # lets extract some shapes from our shapefiles -shp = os.path.join(loadpth, "gis", "bedrock_outcrop_hole_rotate14") +shp = os.path.join(modelpth, "gis", "bedrock_outcrop_hole_rotate14") with shapefile.Reader(shp) as r: polygon_w_hole = [r.shape(0)] -shp = os.path.join(loadpth, "gis", "cross_section_rotate14") +shp = os.path.join(modelpth, "gis", "cross_section_rotate14") with shapefile.Reader(shp) as r: cross_section = r.shapes() # Plot a shapefile of well locations -shp = os.path.join(loadpth, "gis", "wells_locations_rotate14") +shp = os.path.join(modelpth, "gis", "wells_locations_rotate14") with shapefile.Reader(shp) as r: wells = r.shapes() @@ -575,14 +663,46 @@ # + pycharm={"name": "#%%\n"} # load the Freyberg model into mf6-flopy and run the simulation -sim_name = "mfsim.nam" -sim_path = os.path.join("..", "..", "examples", "data", "mf6-freyberg") + +sim_name = "mf6-freyberg" +sim_path = modelpth / "mf6" +file_names = { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + sim = flopy.mf6.MFSimulation.load( - sim_name=sim_name, version=vmf6, exe_name=exe_name_mf6, sim_ws=sim_path + sim_name="mfsim.nam", + version=vmf6, + exe_name=exe_name_mf6, + sim_ws=data_path / sim_name, ) - -newpth = os.path.join(modelpth) -sim.set_sim_path(newpth) +sim.set_sim_path(sim_path) sim.write_simulation() success, buff = sim.run_simulation() if not success: @@ -662,14 +782,14 @@ # + pycharm={"name": "#%%\n"} # get the specific discharge from the cell budget file -cbc_file = os.path.join(newpth, "freyberg.cbc") +cbc_file = os.path.join(sim_path, "freyberg.cbc") cbc = flopy.utils.CellBudgetFile(cbc_file) spdis = cbc.get_data(text="SPDIS")[0] qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, ml6) # get the head from the head file -head_file = os.path.join(newpth, "freyberg.hds") +head_file = os.path.join(sim_path, "freyberg.hds") head = flopy.utils.HeadFile(head_file) hdata = head.get_alldata()[0] @@ -985,10 +1105,10 @@ def run_vertex_grid_example(ws): run_vertex_grid_example(modelpth) # check if model ran properly -modelpth = os.path.join(modelpth, "mp7_ex2", "mf6") +mp7modelpth = os.path.join(modelpth, "mp7_ex2", "mf6") files = ["mp7p2.hds", "mp7p2.cbb"] for f in files: - if os.path.isfile(os.path.join(modelpth, f)): + if os.path.isfile(os.path.join(mp7modelpth, f)): msg = f"Output file located: {f}" print(msg) else: @@ -1002,7 +1122,7 @@ def run_vertex_grid_example(ws): sim_name=vertex_sim_name, version=vmf6, exe_name=exe_name_mf6, - sim_ws=modelpth, + sim_ws=mp7modelpth, ) vertex_ml6 = vertex_sim.get_model("mp7p2") @@ -1052,7 +1172,7 @@ def run_vertex_grid_example(ws): # + pycharm={"name": "#%%\n"} # get the head output for stress period 1 from the modflow6 head file -head = flopy.utils.HeadFile(os.path.join(modelpth, "mp7p2.hds")) +head = flopy.utils.HeadFile(os.path.join(mp7modelpth, "mp7p2.hds")) hdata = head.get_alldata()[0, :, :, :] fig = plt.figure(figsize=(12, 12)) @@ -1093,11 +1213,11 @@ def run_vertex_grid_example(ws): # + pycharm={"name": "#%%\n"} # load the MODPATH-7 results mp_namea = "mp7p2a_mp" -fpth = os.path.join(modelpth, f"{mp_namea}.mppth") +fpth = os.path.join(mp7modelpth, f"{mp_namea}.mppth") p = flopy.utils.PathlineFile(fpth) p0 = p.get_alldata() -fpth = os.path.join(modelpth, f"{mp_namea}.timeseries") +fpth = os.path.join(mp7modelpth, f"{mp_namea}.timeseries") ts = flopy.utils.TimeseriesFile(fpth) ts0 = ts.get_alldata() @@ -1128,7 +1248,7 @@ def run_vertex_grid_example(ws): # + pycharm={"name": "#%%\n"} cbb = flopy.utils.CellBudgetFile( - os.path.join(modelpth, "mp7p2.cbb"), precision="double" + os.path.join(mp7modelpth, "mp7p2.cbb"), precision="double" ) spdis = cbb.get_data(text="SPDIS")[0] qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, vertex_ml6) @@ -1154,8 +1274,24 @@ def run_vertex_grid_example(ws): # set up the notebook for unstructured grid plotting from flopy.discretization import UnstructuredGrid -# this is a folder containing some unstructured grids -datapth = os.path.join("..", "..", "examples", "data", "unstructured") +datapth = modelpth / "unstructured" +file_names = { + "TriMesh_local.exp": "0be6a1a1743972ba98c9d9e63ac2e457813c0809bfbda120e09a97b04411a65e", + "TriMesh_usg.exp": "0b450f2b306253a7b2889796e7a4eea52159f509c7b28a1f65929008dd854e08", + "Trimesh_circle.exp": "1efb86bb77060dcec20e752e242076e3bd23046f5e47d20d948bcf4623b3deb7", + "headu.githds": "cbe94655d471470d931923f70c7548b161ea4c5a22333b7fab6e2255450cda89", + "ugrid_iverts.dat": "7e33ec7f7d1fdbeb6cb7bc8dbcdf35f262c82aaa38dc79b4fb3fe7b53f7c7c1b", + "ugrid_verts.dat": "59493b26c8969789bb5a06d999db7a2dac324bffee280925e123007c81e689c7", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/unstructured/{fname}", + fname=fname, + path=data_path / "unstructured", + known_hash=fhash, + ) + +copytree(data_path / "unstructured", datapth, dirs_exist_ok=True) # simple functions to load vertices and incidence lists @@ -1259,14 +1395,14 @@ def load_iverts(fname): # + pycharm={"name": "#%%\n"} # get the specific discharge from the cell budget file -cbc_file = os.path.join(newpth, "freyberg.cbc") +cbc_file = os.path.join(sim_path, "freyberg.cbc") cbc = flopy.utils.CellBudgetFile(cbc_file) spdis = cbc.get_data(text="SPDIS")[0] qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, ml6) # get the head from the head file -head_file = os.path.join(newpth, "freyberg.hds") +head_file = os.path.join(sim_path, "freyberg.hds") head = flopy.utils.HeadFile(head_file) hdata = head.get_alldata()[0] diff --git a/.docs/Notebooks/raster_intersection_example.py b/.docs/Notebooks/raster_intersection_example.py index f1ec37007..3ea9a71cb 100644 --- a/.docs/Notebooks/raster_intersection_example.py +++ b/.docs/Notebooks/raster_intersection_example.py @@ -29,12 +29,15 @@ import os import sys import time +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch import shapefile import shapely @@ -53,12 +56,29 @@ temp_dir = TemporaryDirectory() workspace = temp_dir.name +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # ### Raster files can be loaded using the `Raster.load` method # + -raster_ws = os.path.join("..", "..", "examples", "data", "options", "dem") +raster_ws = data_path / "options" / "dem" raster_name = "dem.img" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/options/dem/{raster_name}", + fname=raster_name, + path=raster_ws, + known_hash=None, +) + + rio = Raster.load(os.path.join(raster_ws, raster_name)) # - @@ -91,8 +111,28 @@ # The structured grid example uses the DIS file from the GSFLOW Sagehen example problem to create a modelgrid # + -model_ws = os.path.join("..", "..", "examples", "data", "options", "sagehen") -ml = flopy.modflow.Modflow.load("sagehen.nam", version="mfnwt", model_ws=model_ws) +file_names = { + "sagehen.bas": None, + "sagehen.dis": None, + "sagehen.lpf": None, + "sagehen.nam": None, + "sagehen.nwt": None, + "sagehen.oc": None, + "sagehen.sfr": None, + "sagehen.uzf": None, + "sagehen.wel": None, +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/options/sagehen/{fname}", + fname=fname, + path=data_path / "options" / "sagehen", + known_hash=None, + ) + +ml = flopy.modflow.Modflow.load( + "sagehen.nam", version="mfnwt", model_ws=data_path / "options" / "sagehen" +) xoff = 214110 yoff = 4366620 @@ -445,6 +485,23 @@ # + rio = Raster.load(os.path.join(raster_ws, raster_name)) +file_names = [ + "model_boundary.CPG", + "model_boundary.dbf", + "model_boundary.prj", + "model_boundary.sbn", + "model_boundary.sbx", + "model_boundary.shp", + "model_boundary.shx", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/options/dem/{fname}", + fname=fname, + path=data_path / "options" / "dem", + known_hash=None, + ) + shp_name = os.path.join(raster_ws, "model_boundary.shp") # read in the shapefile diff --git a/.docs/Notebooks/sfrpackage_example.py b/.docs/Notebooks/sfrpackage_example.py index 43c63a054..c69b19b4a 100644 --- a/.docs/Notebooks/sfrpackage_example.py +++ b/.docs/Notebooks/sfrpackage_example.py @@ -34,13 +34,16 @@ import os import shutil import sys +from pathlib import Path from pprint import pformat from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch import flopy import flopy.utils.binaryfile as bf @@ -59,19 +62,58 @@ # assumes executable is in users path statement exe_name = "mf2005" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # # #### copy over the example files to the working directory # + # temporary directory temp_dir = TemporaryDirectory() -path = temp_dir.name - -gpth = os.path.join("..", "..", "examples", "data", "mf2005_test", "test1ss.*") -for f in glob.glob(gpth): - shutil.copy(f, path) -gpth = os.path.join("..", "..", "examples", "data", "mf2005_test", "test1tr.*") -for f in glob.glob(gpth): - shutil.copy(f, path) +workspace = Path(temp_dir.name) + +file_names = [ + "test1ss.ba6", + "test1ss.dis", + "test1ss.evt", + "test1ss.gag", + "test1ss.ghb", + "test1ss.lpf", + "test1ss.nam", + "test1ss.oc", + "test1ss.rch", + "test1ss.sfr", + "test1ss.sip", + "test1tr.ba6", + "test1tr.dis", + "test1tr.evt", + "test1tr.gag", + "test1tr.ghb", + "test1tr.gitcbc", + "test1tr.githds", + "test1tr.lpf", + "test1tr.nam", + "test1tr.oc", + "test1tr.rch", + "test1tr.sfr", + "test1tr.sip", + "test1tr.wel", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf2005_test/{fname}", + fname=fname, + path=data_path / "mf2005_test", + known_hash=None, + ) + +shutil.copytree(data_path / "mf2005_test", workspace, dirs_exist_ok=True) # - # ### Load example dataset, skipping the SFR package @@ -80,7 +122,7 @@ "test1ss.nam", version="mf2005", exe_name=exe_name, - model_ws=path, + model_ws=workspace, load_only=["ghb", "evt", "rch", "dis", "bas6", "oc", "sip", "lpf"], ) @@ -95,18 +137,23 @@ # For more information on Item 2, see the Online Guide to MODFLOW: # -rpth = os.path.join( - "..", "..", "examples", "data", "sfr_examples", "test1ss_reach_data.csv" -) +file_names = ["test1ss_reach_data.csv", "test1ss_segment_data.csv", "test1ss.flw"] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/sfr_examples/{fname}", + fname=fname, + path=data_path / "sfr_examples", + known_hash=None, + ) + +rpth = data_path / "sfr_examples" / file_names[0] reach_data = np.genfromtxt(rpth, delimiter=",", names=True) reach_data # ### Segment Data structure # Segment data are input and stored in a dictionary of record arrays, which -spth = os.path.join( - "..", "..", "examples", "data", "sfr_examples", "test1ss_segment_data.csv" -) +spth = data_path / "sfr_examples" / file_names[1] ss_segment_data = np.genfromtxt(spth, delimiter=",", names=True) segment_data = {0: ss_segment_data} segment_data[0][0:1]["width1"] @@ -200,9 +247,7 @@ # ### Load SFR formated water balance output into pandas dataframe using the `SfrFile` class -sfr_outfile = os.path.join( - "..", "..", "examples", "data", "sfr_examples", "test1ss.flw" -) +sfr_outfile = data_path / "sfr_examples" / file_names[2] sfrout = SfrFile(sfr_outfile) df = sfrout.get_dataframe() df.head() @@ -233,7 +278,7 @@ # ### Get SFR leakage results from cell budget file -bpth = os.path.join(path, "test1ss.cbc") +bpth = os.path.join(workspace, "test1ss.cbc") cbbobj = bf.CellBudgetFile(bpth) cbbobj.headers @@ -263,9 +308,9 @@ # >mf2005 test1tr.nam # ``` -flopy.run_model(exe_name, "test1tr.nam", model_ws=path, silent=True) +flopy.run_model(exe_name, "test1tr.nam", model_ws=workspace, silent=True) -sfrout_tr = SfrFile(os.path.join(path, "test1tr.flw")) +sfrout_tr = SfrFile(os.path.join(workspace, "test1tr.flw")) dftr = sfrout_tr.get_dataframe() dftr.head() diff --git a/.docs/Notebooks/shapefile_export_example.py b/.docs/Notebooks/shapefile_export_example.py index 8026c86d2..99f3b2151 100644 --- a/.docs/Notebooks/shapefile_export_example.py +++ b/.docs/Notebooks/shapefile_export_example.py @@ -25,15 +25,18 @@ # * general exporting and importing of geographic data from other sources import os +import sys # + -import sys +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch import flopy @@ -47,8 +50,40 @@ temp_dir = TemporaryDirectory() outdir = os.path.join(temp_dir.name, "shapefile_export") +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +sim_name = "freyberg" + +file_names = { + "freyberg.bas": "63266024019fef07306b8b639c6c67d5e4b22f73e42dcaa9db18b5e0f692c097", + "freyberg.dis": "62d0163bf36c7ee9f7ee3683263e08a0abcdedf267beedce6dd181600380b0a2", + "freyberg.githds": "abe92497b55e6f6c73306e81399209e1cada34cf794a7867d776cfd18303673b", + "freyberg.gitlist": "aef02c664344a288264d5f21e08a748150e43bb721a16b0e3f423e6e3e293056", + "freyberg.lpf": "06500bff979424f58e5e4fbd07a7bdeb0c78f31bd08640196044b6ccefa7a1fe", + "freyberg.nam": "e66321007bb603ef55ed2ba41f4035ba6891da704a4cbd3967f0c66ef1532c8f", + "freyberg.oc": "532905839ccbfce01184980c230b6305812610b537520bf5a4abbcd3bd703ef4", + "freyberg.pcg": "0d1686fac4680219fffdb56909296c5031029974171e25d4304e70fa96ebfc38", + "freyberg.rch": "37a1e113a7ec16b61417d1fa9710dd111a595de738a367bd34fd4a359c480906", + "freyberg.riv": "7492a1d5eb23d6812ec7c8227d0ad4d1e1b35631a765c71182b71e3bd6a6d31d", + "freyberg.wel": "00aa55f59797c02f0be5318a523b36b168fc6651f238f34e8b0938c04292d3e7", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=data_path / sim_name, + known_hash=fhash, + ) + # load an existing model -model_ws = "../../examples/data/freyberg" +model_ws = data_path / sim_name m = flopy.modflow.Modflow.load( "freyberg.nam", model_ws=model_ws, diff --git a/.docs/Notebooks/shapefile_feature_examples.py b/.docs/Notebooks/shapefile_feature_examples.py index 13f970a42..b745a24df 100644 --- a/.docs/Notebooks/shapefile_feature_examples.py +++ b/.docs/Notebooks/shapefile_feature_examples.py @@ -31,11 +31,14 @@ import shutil import sys import warnings +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy from flopy.export.shapefile_utils import recarray2shp, shp2recarray @@ -58,6 +61,15 @@ temp_dir = TemporaryDirectory() workspace = temp_dir.name +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + m = flopy.modflow.Modflow("toy_model", model_ws=workspace) botm = np.zeros((2, 10, 10)) botm[0, :, :] = 1.5 @@ -129,7 +141,14 @@ # * create geometry objects for pathlines from a MODPATH simulation # * plot the paths using the built in plotting method -pthfile = PathlineFile("../../examples/data/mp6/EXAMPLE-3.pathline") +fname = "EXAMPLE-3.pathline" +pthfile = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=None, +) +pthfile = PathlineFile(pthfile) pthdata = pthfile._data.view(np.recarray) # + @@ -162,7 +181,14 @@ # ## Points -eptfile = EndpointFile("../../examples/data/mp6/EXAMPLE-3.endpoint") +fname = "EXAMPLE-3.endpoint" +eptfile = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=None, +) +eptfile = EndpointFile(eptfile) eptdata = eptfile.get_alldata() # + diff --git a/.docs/Notebooks/uzf_example.py b/.docs/Notebooks/uzf_example.py index a64362f99..00128f6a2 100644 --- a/.docs/Notebooks/uzf_example.py +++ b/.docs/Notebooks/uzf_example.py @@ -41,10 +41,12 @@ from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch proj_root = Path.cwd().parent.parent @@ -62,13 +64,42 @@ # assumes executable is in users path statement exe_name = "mf2005" +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + # Set up a temporary workspace. # + temp_dir = TemporaryDirectory() path = Path(temp_dir.name) -gpth = proj_root / "examples" / "data" / "mf2005_test" / "UZFtest2.*" +file_names = [ + "UZFtest2.ba6", + "UZFtest2.dis", + "UZFtest2.gag", + "UZFtest2.ghb", + "UZFtest2.lpf", + "UZFtest2.nam", + "UZFtest2.oc", + "UZFtest2.sfr", + "UZFtest2.sip", + "UZFtest2.uzf", + "UZFtest2.wel", +] +for fname in file_names: + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mf2005_test/{fname}", + fname=fname, + path=data_path / "mf2005_test", + known_hash=None, + ) +gpth = data_path / "mf2005_test" / "UZFtest2.*" for f in glob.glob(str(gpth)): shutil.copy(f, path) # - @@ -102,7 +133,14 @@ # Read the ```irunbnd``` array from an external file. # + -irnbndpth = proj_root / "examples" / "data" / "uzf_examples" / "irunbnd.dat" +fname = "irunbnd.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/uzf_examples/{fname}", + fname=fname, + path=data_path / "uzf_examples", + known_hash=None, +) +irnbndpth = data_path / "uzf_examples" / fname irunbnd = np.loadtxt(irnbndpth) fig = plt.figure(figsize=(8, 8)) @@ -116,7 +154,14 @@ # Define the ``vks`` (unsaturated zone vertical hydraulic conductivity) array. # + -vksbndpth = proj_root / "examples" / "data" / "uzf_examples" / "vks.dat" +fname = "vks.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/uzf_examples/{fname}", + fname=fname, + path=data_path / "uzf_examples", + known_hash=None, +) +vksbndpth = data_path / "uzf_examples" / fname vks = np.loadtxt(vksbndpth) fig = plt.figure(figsize=(8, 8)) @@ -134,7 +179,14 @@ m.nrow_ncol_nlay_nper # + -finf = np.loadtxt(proj_root / "examples" / "data" / "uzf_examples" / "finf.dat") +fname = "finf.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/uzf_examples/{fname}", + fname=fname, + path=data_path / "uzf_examples", + known_hash=None, +) +finf = np.loadtxt(data_path / "uzf_examples" / "finf.dat") finf = np.reshape(finf, (m.nper, m.nrow, m.ncol)) finf = {i: finf[i] for i in range(finf.shape[0])} @@ -158,7 +210,14 @@ # Define `extwc` (extinction water content) array. # + -extwc = np.loadtxt(proj_root / "examples" / "data" / "uzf_examples" / "extwc.dat") +fname = "extwc.dat" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/uzf_examples/{fname}", + fname=fname, + path=data_path / "uzf_examples", + known_hash=None, +) +extwc = np.loadtxt(data_path / "uzf_examples" / "extwc.dat") fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1, aspect="equal") diff --git a/.docs/Notebooks/vtk_pathlines_example.py b/.docs/Notebooks/vtk_pathlines_example.py index 603afd494..231ff3f6f 100644 --- a/.docs/Notebooks/vtk_pathlines_example.py +++ b/.docs/Notebooks/vtk_pathlines_example.py @@ -26,6 +26,9 @@ # + import sys +import git +import pooch + import flopy print(sys.version) @@ -41,7 +44,45 @@ mdl_name = "freyberg" sim_name = f"mf6-{mdl_name}-vtk-pathlines" -sim_path = Path.cwd().parent / "../examples/data" / f"mf6-{mdl_name}" + +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() +sim_path = data_path / f"mf6-{mdl_name}" +file_names = { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=sim_path, + known_hash=fhash, + ) sim = MFSimulation.load(sim_name=sim_name, sim_ws=sim_path) # - @@ -56,6 +97,7 @@ sim.set_sim_path(workspace) # - + # Write the input files to the temporary workspace. sim.write_simulation() diff --git a/.docs/Notebooks/zonebudget_example.py b/.docs/Notebooks/zonebudget_example.py index ecb179255..0dada6671 100644 --- a/.docs/Notebooks/zonebudget_example.py +++ b/.docs/Notebooks/zonebudget_example.py @@ -28,10 +28,12 @@ from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pandas as pd +import pooch proj_root = Path.cwd().parent.parent @@ -48,9 +50,28 @@ temp_dir = TemporaryDirectory() workspace = Path(temp_dir.name) +# Check if we are in the repository and define the data path. + +try: + root = Path(git.Repo(".", search_parent_directories=True).working_dir) +except: + root = None + +data_path = root / "examples" / "data" if root else Path.cwd() + +folder_name = "zonbud_examples" + +fname = "freyberg.gitcbc" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/{fname}", + fname=fname, + path=data_path / folder_name, + known_hash=None, +) + # Set path to example datafiles -loadpth = proj_root / "examples" / "data" / "zonbud_examples" -cbc_f = loadpth / "freyberg.gitcbc" +loadpth = data_path / "zonbud_examples" +cbc_f = loadpth / fname # - # ### Read File Containing Zones @@ -59,6 +80,14 @@ # + from flopy.utils import ZoneBudget +fname = "zonef_mlt.zbr" +pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{folder_name}/{fname}", + fname=fname, + path=data_path / folder_name, + known_hash=None, +) + zone_file = loadpth / "zonef_mlt.zbr" zon = ZoneBudget.read_zone_file(zone_file) nlay, nrow, ncol = zon.shape @@ -331,7 +360,39 @@ def volumetric_budget_bar_plot(values_in, values_out, labels, **kwargs): mf6_exe = "mf6" zb6_exe = "zbud6" -sim_ws = proj_root / "examples" / "data" / "mf6-freyberg" +sim_name = "mf6-freyberg" +sim_ws = data_path / sim_name +file_names = { + "bot.asc": "3107f907cb027460fd40ffc16cb797a78babb31988c7da326c9f500fba855b62", + "description.txt": "94093335eec6a24711f86d4d217ccd5a7716dd9e01cb6b732bc7757d41675c09", + "freyberg.cbc": "c8ad843b1da753eb58cf6c462ac782faf0ca433d6dcb067742d8bd698db271e3", + "freyberg.chd": "d8b8ada8d3978daea1758b315be983b5ca892efc7d69bf6b367ceec31e0dd156", + "freyberg.dis": "cac230a207cc8483693f7ba8ae29ce40c049036262eac4cebe17a4e2347a8b30", + "freyberg.dis.grb": "c8c26fb1fa4b210208134b286d895397cf4b3131f66e1d9dda76338502c7e96a", + "freyberg.hds": "926a06411ca658a89db6b5686f51ddeaf5b74ced81239cab1d43710411ba5f5b", + "freyberg.ic": "6efb56ee9cdd704b9a76fb9efd6dae750facc5426b828713f2d2cf8d35194120", + "freyberg.ims": "6dddae087d85417e3cdaa13e7b24165afb7f9575ab68586f3adb6c1b2d023781", + "freyberg.nam": "cee9b7b000fe35d2df26e878d09d465250a39504f87516c897e3fa14dcda081e", + "freyberg.npf": "81104d3546045fff0eddf5059465e560b83b492fa5a5acad1907ce18c2b9c15f", + "freyberg.oc": "c0715acd75eabcc42c8c47260a6c1abd6c784350983f7e2e6009ddde518b80b8", + "freyberg.rch": "a6ec1e0eda14fd2cdf618a5c0243a9caf82686c69242b783410d5abbcf971954", + "freyberg.riv": "a8cafc8c317cbe2acbb43e2f0cfe1188cb2277a7a174aeb6f3e6438013de8088", + "freyberg.sto": "74d748c2f0adfa0a32ee3f2912115c8f35b91011995b70c1ec6ae1c627242c41", + "freyberg.tdis": "9965cbb17caf5b865ea41a4ec04bcb695fe15a38cb539425fdc00abbae385cbe", + "freyberg.wel": "f19847de455598de52c05a4be745698c8cb589e5acfb0db6ab1f06ded5ff9310", + "k11.asc": "b6a8aa46ef17f7f096d338758ef46e32495eb9895b25d687540d676744f02af5", + "mfsim.nam": "6b8d6d7a56c52fb2bff884b3979e3d2201c8348b4bbfd2b6b9752863cbc9975e", + "top.asc": "3ad2b131671b9faca7f74c1dd2b2f41875ab0c15027764021a89f9c95dccaa6a", +} +for fname, fhash in file_names.items(): + pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", + fname=fname, + path=sim_ws, + known_hash=fhash, + ) + + cpth = workspace / "zbud6" cpth.mkdir() diff --git a/.docs/examples.rst b/.docs/examples.rst index 14284e0d7..9666112ce 100644 --- a/.docs/examples.rst +++ b/.docs/examples.rst @@ -3,6 +3,11 @@ Examples gallery The following examples illustrate the functionality of Flopy. After the `tutorials `_, the examples are the best resource for learning the underlying capabilities of FloPy. +The basic set of MODFLOW executables as well as the `optional` dependency group are both required to run the tutorials. + +If the tutorial/example scripts detect that they are running within the repository, they will use local example data. +Otherwise they will download example data files where necessary from GitHub. + Preprocessing and Discretization -------------------------------- diff --git a/.docs/tutorials.rst b/.docs/tutorials.rst index 7b2525504..56a7b3773 100644 --- a/.docs/tutorials.rst +++ b/.docs/tutorials.rst @@ -3,6 +3,11 @@ Tutorials The following tutorials demonstrate basic FloPy features and usage with MODFLOW 2005, MODFLOW 6, and related programs. +The basic set of MODFLOW executables as well as the `optional` dependency group are both required to run the tutorials. + +If the tutorial/example scripts detect that they are running within the repository, they will use local example data. +Otherwise they will download example data files where necessary from GitHub. + FloPy ----- diff --git a/pyproject.toml b/pyproject.toml index 9f5cf4e12..ade0dbaf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,8 +62,10 @@ optional = [ "fiona", "geojson", "geopandas", + "GitPython", "imageio", "netcdf4", + "pooch", "pymetis ; platform_system != 'Windows'", "pyproj", "pyshp",