forked from MODFLOW-USGS/modflow-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import modflow_devtools.models as examples | ||
from modflow_devtools.markers import requires_github | ||
|
||
|
||
@requires_github | ||
def test_mf2005_freyberg(): | ||
files = examples.mf2005_freyberg() | ||
assert any(files) | ||
|
||
|
||
@requires_github | ||
def test_mf6_freyberg(): | ||
files = examples.mf6_freyberg() | ||
assert any(files) | ||
|
||
|
||
@requires_github | ||
def test_mfusg_freyberg(): | ||
files = examples.mfusg_freyberg() | ||
assert any(files) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Models API | ||
|
||
The `modflow_devtools.models` module provides programmatic access to a number of MODFLOW 6 (and other) example models. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import hashlib | ||
from pathlib import Path | ||
|
||
import pkg_resources | ||
|
||
from modflow_devtools.imports import import_optional_dependency | ||
|
||
pooch = import_optional_dependency("pooch") | ||
|
||
|
||
def _sha256(filename) -> str: | ||
""" | ||
Compute the SHA256 hash of the given file. | ||
Reference: https://stackoverflow.com/a/44873382/6514033 | ||
""" | ||
h = hashlib.sha256() | ||
b = bytearray(128 * 1024) | ||
mv = memoryview(b) | ||
with open(filename, "rb", buffering=0) as f: | ||
for n in iter(lambda: f.readinto(mv), 0): | ||
h.update(mv[:n]) | ||
return h.hexdigest() | ||
|
||
|
||
PROJ_ROOT = Path(__file__).parents[1] | ||
DATA_PATH = PROJ_ROOT / "data" | ||
OWNER = "wpbonelli" | ||
PACKAGE = "modflow-devtools" | ||
VERSION = pkg_resources.get_distribution(PACKAGE).version.rpartition(".dev")[0] | ||
EXCLUDED = [ | ||
".DS_Store", | ||
] | ||
REGISTRY = { | ||
p.name: _sha256(p) | ||
for p in DATA_PATH.rglob("*") | ||
if p.is_file() and not any(e in p.name for e in EXCLUDED) | ||
} | ||
FETCHER = pooch.create( | ||
# Folder where the data will be stored. For a sensible default, use the | ||
# default cache folder for your OS. | ||
path=pooch.os_cache(PACKAGE), | ||
# Base URL of the remote data store. Will call .format on this string | ||
# to insert the version (see below). | ||
base_url="https://github.com/" | ||
+ OWNER | ||
+ "/" | ||
+ PACKAGE | ||
+ "/raw/models-api/data/", # todo: replace branch (debugging) | ||
# Pooches are versioned so that you can use multiple versions of a | ||
# package simultaneously. Use PEP440 compliant version number. The | ||
# version will be appended to the path. | ||
version=VERSION, | ||
# The cache file registry. A dictionary with all files managed by this | ||
# pooch. Keys are the file names (relative to *base_url*) and values | ||
# are their respective SHA256 hashes. Files will be downloaded | ||
# automatically when needed (see fetch_gravity_data). | ||
registry=REGISTRY, | ||
) | ||
|
||
|
||
def mf2005_freyberg(): | ||
""" | ||
Load the MF2005 Freyberg example model files. | ||
""" | ||
return FETCHER.fetch("mf2005_freyberg.zip", processor=pooch.Unzip()) | ||
|
||
|
||
def mf6_freyberg(): | ||
""" | ||
Load the MF6 Freyberg example model files. | ||
""" | ||
return FETCHER.fetch("mf6_freyberg.zip", processor=pooch.Unzip()) | ||
|
||
|
||
def mfusg_freyberg(): | ||
""" | ||
Load the MFUSG Freyberg example model files. | ||
""" | ||
return FETCHER.fetch("mfusg_freyberg.zip", processor=pooch.Unzip()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters