From 623659554ca8a4438f3fe9b628197a9f51275ae5 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Wed, 11 Dec 2024 20:41:19 -0500 Subject: [PATCH] last few --- .../groundwater_paper_uspb_example.py | 2 +- .docs/Notebooks/shapefile_export_example.py | 39 ++++++++++++++++++- .docs/Notebooks/shapefile_feature_examples.py | 30 +++++++++++++- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/.docs/Notebooks/groundwater_paper_uspb_example.py b/.docs/Notebooks/groundwater_paper_uspb_example.py index 983f01d21b..367939b8a6 100644 --- a/.docs/Notebooks/groundwater_paper_uspb_example.py +++ b/.docs/Notebooks/groundwater_paper_uspb_example.py @@ -44,7 +44,7 @@ if not os.path.exists(ws): os.makedirs(ws) - # Check if we are in the repository and define the data path. +# Check if we are in the repository and define the data path. try: root = Path(git.Repo(".", search_parent_directories=True).working_dir) diff --git a/.docs/Notebooks/shapefile_export_example.py b/.docs/Notebooks/shapefile_export_example.py index 8026c86d20..99f3b21518 100644 --- a/.docs/Notebooks/shapefile_export_example.py +++ b/.docs/Notebooks/shapefile_export_example.py @@ -25,15 +25,18 @@ # * general exporting and importing of geographic data from other sources import os +import sys # + -import sys +from pathlib import Path 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 import flopy @@ -47,8 +50,40 @@ temp_dir = TemporaryDirectory() outdir = os.path.join(temp_dir.name, "shapefile_export") +# 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, + ) + # load an existing model -model_ws = "../../examples/data/freyberg" +model_ws = data_path / sim_name m = flopy.modflow.Modflow.load( "freyberg.nam", model_ws=model_ws, diff --git a/.docs/Notebooks/shapefile_feature_examples.py b/.docs/Notebooks/shapefile_feature_examples.py index 13f970a428..b745a24df0 100644 --- a/.docs/Notebooks/shapefile_feature_examples.py +++ b/.docs/Notebooks/shapefile_feature_examples.py @@ -31,11 +31,14 @@ import shutil import sys import warnings +from pathlib import Path from tempfile import TemporaryDirectory +import git import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np +import pooch import flopy from flopy.export.shapefile_utils import recarray2shp, shp2recarray @@ -58,6 +61,15 @@ temp_dir = TemporaryDirectory() workspace = 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() + m = flopy.modflow.Modflow("toy_model", model_ws=workspace) botm = np.zeros((2, 10, 10)) botm[0, :, :] = 1.5 @@ -129,7 +141,14 @@ # * create geometry objects for pathlines from a MODPATH simulation # * plot the paths using the built in plotting method -pthfile = PathlineFile("../../examples/data/mp6/EXAMPLE-3.pathline") +fname = "EXAMPLE-3.pathline" +pthfile = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=None, +) +pthfile = PathlineFile(pthfile) pthdata = pthfile._data.view(np.recarray) # + @@ -162,7 +181,14 @@ # ## Points -eptfile = EndpointFile("../../examples/data/mp6/EXAMPLE-3.endpoint") +fname = "EXAMPLE-3.endpoint" +eptfile = pooch.retrieve( + url=f"https://github.com/modflowpy/flopy/raw/develop/examples/data/mp6/{fname}", + fname=fname, + path=data_path / "mp6", + known_hash=None, +) +eptfile = EndpointFile(eptfile) eptdata = eptfile.get_alldata() # +