Skip to content

Commit

Permalink
download/cache with pooch, eliminate local data/ dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jan 11, 2024
1 parent 84a1e97 commit 75a0bc2
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 136 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
1 change: 0 additions & 1 deletion scripts/ex-gwf-fhb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

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

# Configuration

Expand Down
13 changes: 9 additions & 4 deletions scripts/ex-gwf-lak-p02.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import flopy
import matplotlib.pyplot as plt
import numpy as np
import pooch
import shapefile as shp
from flopy.plot.styles import styles
from modflow_devtools.misc import timed
Expand Down Expand Up @@ -130,12 +131,16 @@
shape3d = (nlay, nrow, ncol)

# Load the idomain arrays

data_pth = os.path.join("..", "data", sim_name)
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/lakes-01.txt",
known_hash="md5:a74ded5357aa667b9df793847e5f8f41",
)
lake_map = np.ones(shape3d, dtype=int) * -1
fpth = os.path.join(data_pth, "lakes-01.txt")
lake_map[0, :, :] = np.loadtxt(fpth, dtype=int) - 1
fpth = os.path.join(data_pth, "lakes-02.txt")
fpth = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/lakes-02.txt",
known_hash="md5:7830e5223c958c35be349a3be24a60a3",
)
lake_map[1, :, :] = np.loadtxt(fpth, dtype=int) - 1

# create linearly varying evapotranspiration surface
Expand Down
51 changes: 44 additions & 7 deletions scripts/ex-gwf-lgrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import flopy.utils.lgrutil
import matplotlib.pyplot as plt
import numpy as np
import pooch
from flopy.plot.styles import styles
from modflow_devtools.misc import timed

Expand All @@ -25,8 +26,8 @@

# Base simulation and data workspace

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

# Configuration

Expand All @@ -42,9 +43,9 @@
# Scenario parameters

parameters = {
"ex-gwf-lgrv-gr": {"configuration": "Refined"},
"ex-gwf-lgrv-gc": {"configuration": "Coarse"},
"ex-gwf-lgrv-lgr": {"configuration": "LGR"},
f"{sim_name}-gr": {"configuration": "Refined"},
f"{sim_name}-gc": {"configuration": "Coarse"},
f"{sim_name}-lgr": {"configuration": "LGR"},
}

# Table LGRV Model Parameters
Expand Down Expand Up @@ -78,13 +79,49 @@

# load data files and process into arrays

fname = data_ws / "top.dat"
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/top.dat",
known_hash="md5:7e95923e78d0a2e2133929376d913ecf",
)
top = np.loadtxt(fname)
ikzone = np.empty((nlay, nrow, ncol), dtype=float)
hashes = [
"548876af515cb8db0c17e7cba0cda364",
"548876af515cb8db0c17e7cba0cda364",
"548876af515cb8db0c17e7cba0cda364",
"548876af515cb8db0c17e7cba0cda364",
"d91e2663ad671119de17a91ffb2a65ab",
"1702d97a83074669db86521b22b87304",
"da973a8edd77a44ed23a29661e2935eb",
"0d514a8f7b208e840a8e5cbfe4018c63",
"afd45ac7125f8351b73add34d35d8435",
"dc99e101996376e1dde1d172dea05f5d",
"fe8d2de0558245c9270597b01070403a",
"cd1fcf0fe2c807ff53eda80860bfe50f",
"c77b43c8045f5459a75547d575665134",
"2252b57927d7d01d0f9a0dda262397d7",
"1399c6872dd7c41be4b10c1251ad7c65",
"331e4006370cceb3864b881b7a0558d6",
"a46e66e632c5af7bf104900793509e5d",
"41f44eee3db48234069de4e9e329317b",
"8f4f1bdd6b6863c3ba68e2336f5ff70a",
"a1c856c05bcc4a17cf3fe61b87fbc720",
"a23fef9e866ad9763943150a3b70f5eb",
"02d67bc7f67814d2248c27cdd5205cf8",
"e7a07da76d111ef2229d26c553daa7eb",
"f6bc51735c4af81e1298d0efd06cd506",
"432b9a02f3ff4906a214b271c965ebad",
]
for k in range(nlay):
fname = data_ws / f"ikzone{k + 1}.dat"
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/ikzone{k + 1}.dat",
known_hash=f"md5:{hashes[k]}",
)
ikzone[k, :, :] = np.loadtxt(fname)
fname = data_ws / "riv.dat"
fname = pooch.retrieve(
url=f"https://github.com/MODFLOW-USGS/modflow6-examples/raw/master/data/{sim_name}/riv.dat",
known_hash="md5:5ccbe4f29940376309db445dbb2d75d0",
)
dt = [
("k", int),
("i", int),
Expand Down
Loading

0 comments on commit 75a0bc2

Please sign in to comment.