You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/md/models.md
+40-19Lines changed: 40 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,42 @@
1
1
# Models API
2
2
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.
4
4
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.
6
6
7
7
## `ModelRegistry`
8
8
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.
10
10
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
14
15
-`examples`: a map of example scenarios to models
15
16
16
17
An *example* is a set of models which run in a particular order.
17
18
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.
19
28
20
-
## Listing models
29
+
###Listing models
21
30
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`.
23
34
24
35
```python
25
36
from pprint import pprint
26
-
import modflow_devtools.models as models
37
+
from modflow_devtools.models importDEFAULT_REGISTRY, get_models
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.
70
86
71
87
### Local registries
72
88
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.
74
90
75
91
For instance, to load all MODFLOW models (pre-MF6 as well):
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.
84
105
85
106
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:
0 commit comments