Skip to content

Commit

Permalink
use pooch for a few more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jan 11, 2024
1 parent 84a1e97 commit 8187830
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 65 deletions.
12 changes: 6 additions & 6 deletions scripts/ex-gwf-advtidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import flopy
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from flopy.utils.gridintersect import GridIntersect
from modflow_devtools.misc import timed
from shapely.geometry import Polygon
import pooch

# Simulation name and workspace

Expand Down Expand Up @@ -191,7 +191,7 @@ def build_model():
ghb_spd = {0: ghb_spd}
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/tides.csv",
known_hash="md5:425337a0bf24fa72c9e40f4e3d9f698a"
known_hash="md5:425337a0bf24fa72c9e40f4e3d9f698a",
)
tsdict = get_timeseries(fname, "tides", "linear")
ghbobs_dict = {}
Expand Down Expand Up @@ -230,7 +230,7 @@ def build_model():
]
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/wellrates.csv",
known_hash="md5:6ca7366be279d679b14e8338a195422f"
known_hash="md5:6ca7366be279d679b14e8338a195422f",
)
tsdict = get_timeseries(
fname,
Expand Down Expand Up @@ -263,7 +263,7 @@ def build_model():
riv_spd = list(zip(rivlay, rivrow, rivcol, rivstg, rivcnd, rivrbt, rivbnd))
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/riverstage.csv",
known_hash="md5:83f8b526ec6e6978b1d9dbd6fde231ef"
known_hash="md5:83f8b526ec6e6978b1d9dbd6fde231ef",
)
tsdict = get_timeseries(
fname,
Expand All @@ -281,7 +281,7 @@ def build_model():
hashes = [
"f8b9b26a3403101f3568cd42f759554f",
"c1ea7ded8edf33d6d70a1daf2524584a",
"9ca294d3260c9d3c3487f8db498a0aa6"
"9ca294d3260c9d3c3487f8db498a0aa6",
]
for ipak, p in enumerate([recharge_zone_1, recharge_zone_2, recharge_zone_3]):
ix = GridIntersect(gwf.modelgrid, method="vertex", rtree=True)
Expand All @@ -298,7 +298,7 @@ def build_model():
)
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/recharge{ipak + 1}.csv",
known_hash=f"md5:{hashes[ipak]}"
known_hash=f"md5:{hashes[ipak]}",
)
tsdict = get_timeseries(
fname,
Expand Down
7 changes: 5 additions & 2 deletions scripts/ex-gwf-bcf2ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from modflow_devtools.misc import timed

# Simulation name and workspace

sim_name = "ex-gwf-bcf2ss"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand All @@ -43,7 +43,10 @@

# Load the wetdry array for layer 1

pth = data_ws / sim_name / "wetdry01.txt"
pth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/wetdry01.txt",
known_hash="md5:3a4b357b7d2cd5175a205f3347ab973d",
)
wetdry_layer0 = np.loadtxt(
pth,
)
Expand Down
20 changes: 13 additions & 7 deletions scripts/ex-gwf-capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import matplotlib.pyplot as plt
import modflowapi
import numpy as np
import pooch
from flopy.plot.styles import styles
from modflow_devtools.misc import timed

Expand All @@ -48,16 +49,21 @@

# Load the bottom, hydraulic conductivity, and idomain arrays

bottom = np.loadtxt(
os.path.join("..", "data", sim_name, "bottom.txt"),
pth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/bottom.txt",
known_hash="md5:201758a5b7febb0390b8b52e634be27f",
)
k11 = np.loadtxt(
os.path.join("..", "data", sim_name, "hydraulic_conductivity.txt"),
bottom = np.loadtxt(pth)
pth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/hydraulic_conductivity.txt",
known_hash="md5:6c78564ba92e850d7d51d6e957b8a3ff",
)
idomain = np.loadtxt(
os.path.join("..", "data", sim_name, "idomain.txt"),
dtype=np.int32,
k11 = np.loadtxt(pth)
pth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/idomain.txt",
known_hash="md5:435d4490adff7a35d1d4928661e45d81",
)
idomain = np.loadtxt(pth, dtype=np.int32)


# Table Capture Fraction Model Parameters
Expand Down
7 changes: 5 additions & 2 deletions scripts/ex-gwf-csub-p01.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from modflow_devtools.misc import timed

# Simulation name and workspace

sim_name = "ex-gwf-csub-p01"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand Down Expand Up @@ -82,7 +82,10 @@

# Load the aquifer load time series

pth = data_ws / sim_name / "train_load_193704231304.csv"
pth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/train_load_193704231304.csv",
known_hash="md5:32dc8e7b7e39876374af43605e264725",
)
csv_load = np.genfromtxt(pth, names=True, delimiter=",")

# Reformat csv data into format for MODFLOW 6 timeseries file
Expand Down
1 change: 0 additions & 1 deletion scripts/ex-gwf-csub-p02.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

sim_name = "ex-gwf-csub-p02"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Scenario parameters

Expand Down
1 change: 0 additions & 1 deletion scripts/ex-gwf-csub-p03.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

sim_name = "ex-gwf-csub-p03"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand Down
1 change: 0 additions & 1 deletion scripts/ex-gwf-csub-p04.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

sim_name = "ex-gwf-csub-p03"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand Down
7 changes: 5 additions & 2 deletions scripts/ex-gwf-disvmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import flopy.utils.cvfdutil
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from flopy.utils.geometry import get_polygon_area
from flopy.utils.gridintersect import GridIntersect
Expand All @@ -32,7 +33,6 @@
# Simulation name and workspace
sim_name = "ex-gwf-disvmesh"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand Down Expand Up @@ -110,7 +110,10 @@ def from_argus_export(fname):

# Load argus mesh and get disv grid properties

fname = os.path.join(data_ws, "ex-gwf-disvmesh", "argus.exp")
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/ex-gwf-disvmesh/argus.exp",
known_hash="md5:072a758ca3d35831acb7e1e27e7b8524",
)
verts, iverts = from_argus_export(fname)
gridprops = flopy.utils.cvfdutil.get_disv_gridprops(verts, iverts)
cell_areas = []
Expand Down
34 changes: 25 additions & 9 deletions scripts/ex-gwf-drn-p01.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import flopy
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from modflow_devtools.latex import (build_table, exp_format, float_format,
int_format)
Expand All @@ -30,7 +31,6 @@

sim_name = "ex-gwf-drn-p01"
ws = pl.Path("../examples")
data_ws = pl.Path("../data")

# Configuration

Expand Down Expand Up @@ -92,20 +92,36 @@

# Load the idomain, top, bottom, and uzf/mvr arrays

data_pth = data_ws / "ex-gwf-sfr-p01"
fpth = os.path.join(data_pth, "idomain.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/ex-gwf-sfr-p01/idomain.txt",
known_hash="md5:a0b12472b8624aecdc79e5c19c97040c",
)
idomain = np.loadtxt(fpth, dtype=int)
fpth = os.path.join(data_pth, "bottom.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/ex-gwf-sfr-p01/bottom.txt",
known_hash="md5:fa5fe276f4f58a01eabfe88516cc90af",
)
botm = np.loadtxt(fpth, dtype=float)

data_pth = data_ws / sim_name
fpth = os.path.join(data_pth, "top.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/top.txt",
known_hash="md5:88cc15f87824ebfd35ed5b4be7f68387",
)
top = np.loadtxt(fpth, dtype=float)
fpth = os.path.join(data_pth, "infilt_mult.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/infilt_mult.txt",
known_hash="md5:8bf0a48d604263cb35151587a9d8ca29",
)
infilt_mult = np.loadtxt(fpth, dtype=float)
fpth = os.path.join(data_pth, "extwc_mult.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/extwc_mult.txt",
known_hash="md5:6e289692a2b55b7bafb8bd9d71b0a2cb",
)
extwc_mult = np.loadtxt(fpth, dtype=float)
fpth = os.path.join(data_pth, "routing_map.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/routing_map.txt",
known_hash="md5:1bf9a6bb3513a184aa5093485e622f5b",
)
routing_map = np.loadtxt(fpth, dtype=int)

# convert routing map to zero-based reach numbers
Expand Down
46 changes: 12 additions & 34 deletions scripts/process-scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,20 @@
>>> process-scripts.py -k *-maw-* # process all MAW example problems.
"""
import ast
import fnmatch
import os
import re
import sys
import fnmatch

import flopy

from modflow_devtools.latex import get_header, get_footer
from modflow_devtools.latex import get_footer, get_header

# path to the example files
ex_pth = os.path.join("..", "examples")

# only process python files starting with ex_
files = sorted(
[
file
for file in os.listdir()
if file.endswith(".py") and file.startswith("ex-")
]
[file for file in os.listdir() if file.endswith(".py") and file.startswith("ex-")]
)

only_process_ex = []
Expand All @@ -89,9 +84,7 @@ def table_standard_header(caption, label):
"Parameter",
"Value",
)
return get_header(
caption, label, headings, col_widths=col_widths, center=False
)
return get_header(caption, label, headings, col_widths=col_widths, center=False)


def table_scenario_header(caption, label):
Expand All @@ -107,9 +100,7 @@ def table_scenario_header(caption, label):
"Parameter",
"Value",
)
return get_header(
caption, label, headings, col_widths=col_widths, center=False
)
return get_header(caption, label, headings, col_widths=col_widths, center=False)


def table_footer():
Expand All @@ -123,9 +114,7 @@ def make_tables():

for file in files:
print(f"processing...'{file}'")
basename = os.path.splitext(os.path.basename(file))[0].replace(
"_", "-"
)
basename = os.path.splitext(os.path.basename(file))[0].replace("_", "-")
# do a little processing
with open(file) as f:
txt = f.read()
Expand Down Expand Up @@ -183,9 +172,7 @@ def make_tables():
except:
units = " (unknown)"
if len(table_line) > 0:
table_line += "\t{}{} & {}".format(
text_to_write, units, value
)
table_line += "\t{}{} & {}".format(text_to_write, units, value)
else:
table_line = "\t& & {}{} & {}".format(
text_to_write, units, value
Expand Down Expand Up @@ -338,14 +325,11 @@ def get_examples_dict(verbose=False):
if file_name.lower() == "mfsim.nam":
if verbose:
msg = (
" Found MODFLOW 6 simulation "
+ f"name file: {file_name}"
" Found MODFLOW 6 simulation " + f"name file: {file_name}"
)
print(msg)
print(f"Using flopy to load {dirName}")
sim = flopy.mf6.MFSimulation.load(
sim_ws=dirName, verbosity_level=0
)
sim = flopy.mf6.MFSimulation.load(sim_ws=dirName, verbosity_level=0)
sim_paks = []
for pak in sim.sim_package_list:
pak_type = pak.package_abbr
Expand Down Expand Up @@ -402,9 +386,7 @@ def build_md_tables(ex_dict):
for ex_name in ex_paks.keys():
for ex_root in ex_order:
if ex_root in ex_name:
pak_link[ex_name] = "[{}](_examples/{}.html)".format(
ex_name, ex_root
)
pak_link[ex_name] = "[{}](_examples/{}.html)".format(ex_name, ex_root)
break
if ex_name not in list(pak_link.keys()):
pak_link[ex_name] = ex_name
Expand Down Expand Up @@ -587,9 +569,7 @@ def build_tex_tables(ex_dict):
for idx, ex in enumerate(ex_order):
for key, d in ex_dict.items():
if ex in key:
ex_number = [idx + 1] + [
" " for i in range(len(d["paks"]) - 1)
]
ex_number = [idx + 1] + [" " for i in range(len(d["paks"]) - 1)]
d["ex_number"] = ex_number
ex_tex[key] = d

Expand All @@ -611,9 +591,7 @@ def build_tex_tables(ex_dict):
caption = "List of example problems and simulation characteristics."
label = "tab:ex-table"

lines = get_header(
caption, label, headings, col_widths=col_widths, firsthead=True
)
lines = get_header(caption, label, headings, col_widths=col_widths, firsthead=True)

on_ex = 0
for idx, (key, sim_dict) in enumerate(ex_tex.items()):
Expand Down

0 comments on commit 8187830

Please sign in to comment.