|
23 | 23 | from pprint import pformat
|
24 | 24 | from tempfile import TemporaryDirectory
|
25 | 25 |
|
| 26 | +import git |
26 | 27 | import matplotlib as mpl
|
27 | 28 | import matplotlib.pyplot as plt
|
28 | 29 | import numpy as np
|
29 | 30 | import pandas as pd
|
30 |
| - |
31 |
| -# + |
| 31 | +import pooch |
32 | 32 | from IPython.display import clear_output, display
|
33 | 33 |
|
34 |
| -proj_root = Path.cwd().parent.parent |
35 |
| - |
36 |
| -# run installed version of flopy or add local path |
37 | 34 | import flopy
|
38 | 35 |
|
39 | 36 | print(sys.version)
|
40 | 37 | print(f"numpy version: {np.__version__}")
|
41 | 38 | print(f"matplotlib version: {mpl.__version__}")
|
42 | 39 | print(f"pandas version: {pd.__version__}")
|
43 | 40 | print(f"flopy version: {flopy.__version__}")
|
44 |
| -# - |
45 | 41 |
|
| 42 | +# First create a temporary workspace. |
| 43 | + |
| 44 | +sim_name = "freyberg_multilayer_transient" |
| 45 | +temp_dir = TemporaryDirectory() |
| 46 | +workspace = Path(temp_dir.name) |
| 47 | + |
| 48 | +# Check if we are in the repository and define the data path. |
| 49 | + |
| 50 | +try: |
| 51 | + root = Path(git.Repo(".", search_parent_directories=True).working_dir) |
| 52 | +except: |
| 53 | + root = None |
| 54 | + |
| 55 | +data_path = root / "examples" / "data" if root else Path.cwd() |
| 56 | + |
| 57 | +# Download files if needed. |
| 58 | + |
| 59 | +file_names = { |
| 60 | + "freyberg.bas": "781585c140d40a27bce9369baee262c621bcf969de82361ad8d6b4d8c253ee02", |
| 61 | + "freyberg.cbc": "d4e18e968cabde8470fcb7cb8a1c4cc57fcd643bd63b23e7751460bfdb651ea4", |
| 62 | + "freyberg.ddn": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", |
| 63 | + "freyberg.dis": "1ef61a467a219c036e58902ce11297e06b4eeb5f2f9d2ea40245b421a248a471", |
| 64 | + "freyberg.drn": "93c22ab27d599938a8c2fc5b420ec03e5251b11b050d6ae1cb23ce2aa1b77997", |
| 65 | + "freyberg.hds": "0b3e911ef35f625d2d046e05a20bc1300341b41028220c5b25ace6f5a267ceef", |
| 66 | + "freyberg.list": "14ec36c22b48d253d6b82c44f36c5bad4f0785b3a3384b386f6b69c4ee2e31bf", |
| 67 | + "freyberg.nam": "9e3747ce6d6229caec55a9357285a96cb4608dae11d90dd165a23e0bb394a2bd", |
| 68 | + "freyberg.nwt": "d66c5cc255d050a0f871639af4af0cef8d48fa59c1c64217de65fc6e7fd78cb1", |
| 69 | + "freyberg.oc": "faefd462d11b9a21c4579420b2156fb616ca642bc1e66fc5eb5e1b9046449e43", |
| 70 | + "freyberg.rch": "93a12742a2d37961d53df0405e39cbecf0e6f14d45b5ca8cbba84a2d90828258", |
| 71 | + "freyberg.upw": "80838be7af2f97c92965bad1d121c252b69d9c66e4885c5f3f49a6e99582deac", |
| 72 | + "freyberg.wel": "dd322655eadff3f618f0835c9277af30720197bd48328aae2d6772f26eef2686", |
| 73 | +} |
| 74 | +for fname, fhash in file_names.items(): |
| 75 | + pooch.retrieve( |
| 76 | + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/{sim_name}/{fname}", |
| 77 | + fname=fname, |
| 78 | + path=data_path / sim_name, |
| 79 | + known_hash=fhash, |
| 80 | + ) |
| 81 | + |
| 82 | +# - |
46 | 83 | # ### Model Inputs
|
47 | 84 |
|
48 |
| -# first lets load an existing model |
49 |
| -model_ws = proj_root / "examples" / "data" / "freyberg_multilayer_transient" |
50 | 85 | ml = flopy.modflow.Modflow.load(
|
51 | 86 | "freyberg.nam",
|
52 |
| - model_ws=model_ws, |
| 87 | + model_ws=data_path / sim_name, |
53 | 88 | verbose=False,
|
54 | 89 | check=False,
|
55 | 90 | exe_name="mfnwt",
|
|
66 | 101 | ml.drn.plot(key="cond")
|
67 | 102 | ml.drn.plot(key="elev")
|
68 | 103 |
|
69 |
| -# First create a temporary workspace. |
70 |
| - |
71 |
| -# create a temporary workspace |
72 |
| -temp_dir = TemporaryDirectory() |
73 |
| -workspace = Path(temp_dir.name) |
74 | 104 |
|
75 | 105 | # Write a shapefile of the DIS package.
|
76 | 106 |
|
|
96 | 126 | #
|
97 | 127 | # First, let's look at the list file. The list file summarizes the model's results.
|
98 | 128 |
|
99 |
| -mfl = flopy.utils.MfListBudget(model_ws / "freyberg.list") |
| 129 | +mfl = flopy.utils.MfListBudget(workspace / "freyberg.list") |
100 | 130 | df_flux, df_vol = mfl.get_dataframes(start_datetime="10-21-2015")
|
101 | 131 | df_flux
|
102 | 132 |
|
|
116 | 146 | # Now let's look at the simulated head.
|
117 | 147 |
|
118 | 148 | # if you pass the model instance, then the plots will be offset and rotated
|
119 |
| -h = flopy.utils.HeadFile(model_ws / "freyberg.hds", model=ml) |
| 149 | +h = flopy.utils.HeadFile(workspace / "freyberg.hds", model=ml) |
120 | 150 | h.times
|
121 | 151 |
|
122 | 152 | h.plot(totim=900, contour=True, grid=True, colorbar=True, figsize=(10, 10))
|
|
0 commit comments