Skip to content

Commit 9106727

Browse files
authored
feat(models): add mf2005 models from modflow6-testmodels repo (#206)
1 parent 6534389 commit 9106727

5 files changed

Lines changed: 1527 additions & 3 deletions

File tree

docs/md/models.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The leading prefix identifies where the model came from. Currently three prefixe
2727

2828
- `example/...`: example models in https://github.com/MODFLOW-ORG/modflow6-examples
2929
- `test/...`: test models in https://github.com/MODFLOW-ORG/modflow6-testmodels
30+
- `mf2005/...`: mf2005 models in https://github.com/MODFLOW-ORG/modflow6-testmodels
3031
- `large/...`: large test models in https://github.com/MODFLOW-ORG/modflow6-largetestmodels
3132

3233
The remaining path parts reflect the relative location of the model within the source repository.
@@ -61,4 +62,5 @@ For example, to create a registry of models in the MF6 examples and test models
6162
python -m modflow_devtools.make_registry ../modflow6-examples/examples --url https://github.com/MODFLOW-ORG/modflow6-examples/releases/download/current/mf6examples.zip --prefix example
6263
python -m modflow_devtools.make_registry ../modflow6-testmodels/mf6 --append --url https://github.com/MODFLOW-ORG/modflow6-testmodels/raw/master/mf6 --prefix test
6364
python -m modflow_devtools.make_registry ../modflow6-largetestmodels --append --url https://github.com/MODFLOW-ORG/modflow6-largetestmodels/raw/master --prefix large
65+
python -m modflow_devtools.make_registry ../modflow6-testmodels/mf5to6 --append --url https://github.com/MODFLOW-ORG/modflow6-testmodels/raw/master/mf5to6 --prefix mf2005 --namefile "*.nam"
6466
```

modflow_devtools/make_registry.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,34 @@ def write_registry(
3434
url: str,
3535
prefix: str = "",
3636
append: bool = False,
37+
namefile: str = "mfsim.nam",
3738
):
39+
"""
40+
Make registry files for a directory of models.
41+
42+
The directory may contain model subdirectories
43+
at arbitrary depth. Model input subdirectories
44+
are identified by the presence of a namefile
45+
matching the provided pattern. A prefix may be
46+
specified for model names to avoid collisions.
47+
The registry files are written to the registry
48+
folder alongside this script. Typically, this
49+
function will run once or more in append mode
50+
to iteratively create a registry.
51+
52+
Parameters
53+
----------
54+
path : str | PathLike
55+
Path to the directory containing the models.
56+
url : str
57+
Base URL for the models.
58+
prefix : str
59+
Prefix to add to model names.
60+
append : bool
61+
Append to the registry files instead of overwriting them.
62+
namefile : str
63+
Namefile pattern to look for in the model directories.
64+
"""
3865
path = Path(path).expanduser().absolute()
3966
if not path.is_dir():
4067
raise NotADirectoryError(f"Path {path} is not a directory.")
@@ -46,7 +73,7 @@ def write_registry(
4673
if is_zip := url.endswith((".zip", ".tar")):
4774
registry[url.rpartition("/")[2]] = {"hash": None, "url": url}
4875

49-
model_paths = get_model_paths(path)
76+
model_paths = get_model_paths(path, namefile=namefile)
5077
for model_path in model_paths:
5178
model_path = model_path.expanduser().absolute()
5279
rel_path = model_path.relative_to(path)
@@ -112,5 +139,18 @@ def drop_none_or_empty(path, key, value):
112139
help="Base URL for models.",
113140
default=BASE_URL,
114141
)
142+
parser.add_argument(
143+
"--namefile",
144+
"-n",
145+
type=str,
146+
help="Namefile pattern to look for in the model directories.",
147+
default="mfsim.nam",
148+
)
115149
args = parser.parse_args()
116-
write_registry(path=args.path, url=args.url, prefix=args.prefix, append=args.append)
150+
write_registry(
151+
path=args.path,
152+
url=args.url,
153+
prefix=args.prefix,
154+
append=args.append,
155+
namefile=args.namefile,
156+
)

modflow_devtools/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO
2+
# - support mf2005 models in modflow6-testmodels repo
23
# - switch modflow6-testmodels and -largetestmodels to
34
# fetch zip of the repo instead of individual files?
45

@@ -66,7 +67,7 @@ def _fetch_zip(zip_name):
6667
REGISTRY_ANCHOR, REGISTRY_FILE_NAME
6768
) as registry_file:
6869
REGISTRY = tomli.load(registry_file)
69-
# extract urls then drop them, leaving a direct map of name to hash
70+
# extract urls then drop them. registry directly maps file name to hash
7071
urls = {k: v["url"] for k, v in REGISTRY.items() if v.get("url", None)}
7172
REGISTRY = {k: v.get("hash", None) for k, v in REGISTRY.items()}
7273
POOCH.registry = REGISTRY

0 commit comments

Comments
 (0)