From 6792fde85e0ce2f3924abe7654e1f12b680a7432 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Wed, 11 Dec 2024 20:27:12 -0500 Subject: [PATCH] 3 more --- .../groundwater2023_watershed_example.py | 29 +++++++++- .../Notebooks/load_swr_binary_data_example.py | 33 ++++++++++- .docs/Notebooks/mf6_complex_model_example.py | 57 ++++++++++++++++++- 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/.docs/Notebooks/groundwater2023_watershed_example.py b/.docs/Notebooks/groundwater2023_watershed_example.py index 3b9c804dc..3e1baa140 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/mf6//{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/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) # +