Skip to content

Commit 75e6136

Browse files
authored
docs(models): correct some stale things, misc improvements (#217)
1 parent 777dd3d commit 75e6136

1 file changed

Lines changed: 40 additions & 19 deletions

File tree

docs/md/models.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
# Models API
22

3-
The `modflow_devtools.models` module provides programmatic access to MODFLOW 6 example models via a `ModelRegistry`. There is one "official" `PoochRegistry`, aimed at users and developers — developers may create `LocalRegistry` instances to load models from the local filesystem.
3+
The `modflow_devtools.models` module provides programmatic access to MODFLOW 6 (and other) models.
44

5-
This module leans heavily on [Pooch](https://www.fatiando.org/pooch/latest/index.html), but it is an independent layer on top with strong opinions about how to train (configure) the fetch-happy friend.
5+
**Note**: While this module leans heavily on [Pooch](https://www.fatiando.org/pooch/latest/index.html), it is an independent layer with opinions about how to train (configure) it.
66

77
## `ModelRegistry`
88

9-
Registries expose the following properties:
9+
The `ModelRegistry` base class represents a set of models living in a GitHub repository or on the local filesystem. This package provides an "official" GitHub-backed registry. Local registries may be created as needed.
1010

11-
- `path`: the data path
12-
- `files`: a map of files to file info
13-
- `models`: a map of models to files
11+
All `ModelRegistry` subclasses expose the following properties:
12+
13+
- `files`: a map of model input files to file-scoped info
14+
- `models`: a map of model names to model input files
1415
- `examples`: a map of example scenarios to models
1516

1617
An *example* is a set of models which run in a particular order.
1718

18-
The default `PoochRegistry` is available at `modflow_devtools.models.DEFAULT_REGISTRY`. Its `path` is the pooch cache. Values in the `files` are dictionaries including a hash and url. Configuring the default registry is a developer task — see the instructions on [creating a registry](#creating-a-registry) below.
19+
Dictionary keys are consistently strings. Dictionary values may vary depending on the type of registry. For instance, values in `PoochRegistry.files` are dictionaries including a hash and url.
20+
21+
### Subclasses
22+
23+
A registry backed by a remote repository is called a `PoochRegistry`. A `PoochRegistry` maintains a persistent index on disk.
24+
25+
A `LocalRegistry` lives in-memory only. Its purpose is simply to store some knowledge about where model files are on disk, and provide an identical API for accessing them as the official `PoochRegistry`.
26+
27+
Most users will interact only with the default `PoochRegistry`, available at `modflow_devtools.models.DEFAULT_REGISTRY`. A `LocalRegistry` can be useful for developing and debugging MODFLOW and/or MODFLOW models alongside one another.
1928

20-
## Listing models
29+
### Listing models
2130

22-
The `get_models()` function returns a mapping of model names to model input files.
31+
This module provides convenience functions to access the default registry.
32+
33+
For instance, the `get_models()` function aliases `DEFAULT_REGISTRY.models`.
2334

2435
```python
2536
from pprint import pprint
26-
import modflow_devtools.models as models
37+
from modflow_devtools.models import DEFAULT_REGISTRY, get_models
2738

28-
pprint(list(models.get_models())[:5])
39+
pprint(list(get_models())[:5])
2940
```
3041

3142
```
@@ -36,7 +47,7 @@ pprint(list(models.get_models())[:5])
3647
'mf6/example/ex-gwe-geotherm/mf6gwe']
3748
```
3849

39-
### Model names
50+
#### Model names
4051

4152
Model names follow a hierarchical addressing scheme.
4253

@@ -51,17 +62,22 @@ Currently the following prefixes are in use:
5162

5263
The remaining parts may reflect the relative location of the model within the source repository.
5364

54-
**Note**: until this module stabilizes, model naming conventions may change without notice.
65+
**Note**: Until this module stabilizes, model naming conventions may change without notice.
5566

56-
## Using models
67+
### Using models
5768

58-
To copy model input files to a workspace of your choosing:
69+
To copy model input files to a workspace of your choosing, call `copy_to` on the registry.
5970

6071
```python
72+
6173
from tempfile import TemporaryDirectory
6274

6375
with TemporaryDirectory() as td:
64-
workspace = models.copy_to(td, "example/ex-gwe-ates", verbose=True)
76+
workspace = DEFAULT_REGISTRY.copy_to(td, "example/ex-gwe-ates", verbose=True)
77+
# the module provides a shortcut for this too
78+
# from modflow_devtools.models import copy_to
79+
# workspace = copy_to(td, "example/ex-gwe-ates", verbose=True)
80+
6581
```
6682

6783
If the target directory doesn't exist, it will be created.
@@ -70,17 +86,22 @@ If the target directory doesn't exist, it will be created.
7086

7187
### Local registries
7288

73-
A `LocalRegistry` accepts a `path` on initialization. This must be a directory containing model subdirectories at arbitrary depth. Model subdirectories are identified by the presence of a namefile matching `namefile_pattern`. By default `namefile_pattern="mfsim.nam"`, causing only MODFLOW 6 models to be returned.
89+
To prepare a local registry, just create it and call `index` once or more. The `path` to index must be a directory containing model subdirectories at arbitrary depth. Model subdirectories are identified by the presence of a namefile matching `namefile_pattern`. By default `namefile_pattern="mfsim.nam"`, causing only MODFLOW 6 models to be returned.
7490

7591
For instance, to load all MODFLOW models (pre-MF6 as well):
7692

7793
```python
78-
registry = LocalRegistry("path/to/models", namefile_pattern="*.nam")
94+
registry = LocalRegistry()
95+
registry.index("path/to/models", namefile_pattern="*.nam")
7996
```
8097

98+
The registry may then be used
99+
81100
### Pooch registry
82101

83-
The `make_registry.py` script is responsible for generating a registry text file and a mapping between files and models. This script should be run in the CI pipeline at release time before the package is built. The generated registry file and model mapping are used to create a pooch instance for fetching model files, and should be distributed with the package.
102+
The `make_registry.py` script is responsible for generating a registry text file and a mapping between files and models.
103+
104+
The generated registry file and model mapping are used to create a pooch instance for fetching model files, and should be distributed with the package.
84105

85106
The script can be executed with `python -m modflow_devtools.make_registry`. It accepts a single positional argument, specifying the base directory containing model directories. It accepts two named arguments:
86107

0 commit comments

Comments
 (0)