Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/md/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The leading prefix identifies where the model came from. Currently three prefixe

- `example/...`: example models in https://github.com/MODFLOW-ORG/modflow6-examples
- `test/...`: test models in https://github.com/MODFLOW-ORG/modflow6-testmodels
- `mf2005/...`: mf2005 models in https://github.com/MODFLOW-ORG/modflow6-testmodels
- `large/...`: large test models in https://github.com/MODFLOW-ORG/modflow6-largetestmodels

The remaining path parts reflect the relative location of the model within the source repository.
Expand Down Expand Up @@ -61,4 +62,5 @@ For example, to create a registry of models in the MF6 examples and test models
python -m modflow_devtools.make_registry ../modflow6-examples/examples --url https://github.com/MODFLOW-ORG/modflow6-examples/releases/download/current/mf6examples.zip --prefix example
python -m modflow_devtools.make_registry ../modflow6-testmodels/mf6 --append --url https://github.com/MODFLOW-ORG/modflow6-testmodels/raw/master/mf6 --prefix test
python -m modflow_devtools.make_registry ../modflow6-largetestmodels --append --url https://github.com/MODFLOW-ORG/modflow6-largetestmodels/raw/master --prefix large
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"
```
44 changes: 42 additions & 2 deletions modflow_devtools/make_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,34 @@ def write_registry(
url: str,
prefix: str = "",
append: bool = False,
namefile: str = "mfsim.nam",
):
"""
Make registry files for a directory of models.

The directory may contain model subdirectories
at arbitrary depth. Model input subdirectories
are identified by the presence of a namefile
matching the provided pattern. A prefix may be
specified for model names to avoid collisions.
The registry files are written to the registry
folder alongside this script. Typically, this
function will run once or more in append mode
to iteratively create a registry.

Parameters
----------
path : str | PathLike
Path to the directory containing the models.
url : str
Base URL for the models.
prefix : str
Prefix to add to model names.
append : bool
Append to the registry files instead of overwriting them.
namefile : str
Namefile pattern to look for in the model directories.
"""
path = Path(path).expanduser().absolute()
if not path.is_dir():
raise NotADirectoryError(f"Path {path} is not a directory.")
Expand All @@ -46,7 +73,7 @@ def write_registry(
if is_zip := url.endswith((".zip", ".tar")):
registry[url.rpartition("/")[2]] = {"hash": None, "url": url}

model_paths = get_model_paths(path)
model_paths = get_model_paths(path, namefile=namefile)
for model_path in model_paths:
model_path = model_path.expanduser().absolute()
rel_path = model_path.relative_to(path)
Expand Down Expand Up @@ -112,5 +139,18 @@ def drop_none_or_empty(path, key, value):
help="Base URL for models.",
default=BASE_URL,
)
parser.add_argument(
"--namefile",
"-n",
type=str,
help="Namefile pattern to look for in the model directories.",
default="mfsim.nam",
)
args = parser.parse_args()
write_registry(path=args.path, url=args.url, prefix=args.prefix, append=args.append)
write_registry(
path=args.path,
url=args.url,
prefix=args.prefix,
append=args.append,
namefile=args.namefile,
)
3 changes: 2 additions & 1 deletion modflow_devtools/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# TODO
# - support mf2005 models in modflow6-testmodels repo
# - switch modflow6-testmodels and -largetestmodels to
# fetch zip of the repo instead of individual files?

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