Skip to content

Commit

Permalink
Merge branch 'modflowpy-develop' into mfusg
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhang4 committed Dec 20, 2024
2 parents 08e108a + 7caa527 commit 642e649
Show file tree
Hide file tree
Showing 345 changed files with 13,575 additions and 28,255 deletions.
37 changes: 36 additions & 1 deletion .docs/Notebooks/array_output_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
40 changes: 39 additions & 1 deletion .docs/Notebooks/export_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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``
Expand Down
87 changes: 38 additions & 49 deletions .docs/Notebooks/export_vtk_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -216,13 +246,7 @@

## add recharge to the VTK object
recharge = ml.rch.rech.transient_2ds
vtkobj.add_transient_array(
recharge,
"recharge",
masked_values=[
0,
],
)
vtkobj.add_transient_array(recharge, "recharge", masked_values=[0])

## write vtk files
vtkobj.write(output_dir / "tr_array_example" / "recharge.vtu")
Expand All @@ -242,12 +266,7 @@

## add well fluxes to the VTK object
spd = ml.wel.stress_period_data
vtkobj.add_transient_list(
spd,
masked_values=[
0,
],
)
vtkobj.add_transient_list(spd, masked_values=[0])

## write vtk files
vtkobj.write(output_dir / "tr_list_example" / "wel_flux.vtu")
Expand Down Expand Up @@ -412,53 +431,23 @@ def run_vertex_grid_example(ws):
xmax = 12 * delr
ymin = 8 * delc
ymax = 13 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 1, range(nlay))

rf1shp = os.path.join(gridgen_ws, "rf1")
xmin = 8 * delr
xmax = 11 * delr
ymin = 9 * delc
ymax = 12 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 2, range(nlay))

rf2shp = os.path.join(gridgen_ws, "rf2")
xmin = 9 * delr
xmax = 10 * delr
ymin = 10 * delc
ymax = 11 * delc
rfpoly = [
[
[
(xmin, ymin),
(xmax, ymin),
(xmax, ymax),
(xmin, ymax),
(xmin, ymin),
]
]
]
rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
g.add_refinement_features(rfpoly, "polygon", 3, range(nlay))

g.build(verbose=False)
Expand Down
62 changes: 46 additions & 16 deletions .docs/Notebooks/feat_working_stack_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,68 @@
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)
print(f"numpy version: {np.__version__}")
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",
Expand All @@ -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.

Expand All @@ -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

Expand All @@ -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))
Expand Down
6 changes: 1 addition & 5 deletions .docs/Notebooks/get_transmissivities_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@
plt.plot(heads[0], label="piezometric surface", color="b", linestyle=":")
for iw in range(len(sctop)):
ax.fill_between(
[iw - 0.25, iw + 0.25],
scbot[iw],
sctop[iw],
facecolor="None",
edgecolor="k",
[iw - 0.25, iw + 0.25], scbot[iw], sctop[iw], facecolor="None", edgecolor="k"
)
ax.legend(loc=2)

Expand Down
Loading

0 comments on commit 642e649

Please sign in to comment.