Skip to content

Commit

Permalink
docs(generate_classes): add docs for generate_classes() (#1844)
Browse files Browse the repository at this point in the history
* add generate_classes.md docs for generate_classes()
* link to generate_classes.md from DEVELOPER.md
  • Loading branch information
wpbonelli committed Jun 28, 2023
1 parent 4583d77 commit 1d4e838
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ URLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certifica

This can be fixed by running `Install Certificates.command` in your Python installation directory (see the [StackOverflow discussion here](https://stackoverflow.com/a/58525755/6514033) for more information).

### Updating FloPy packages

FloPy must be up-to-date with the version of MODFLOW 6 and other executables it is being used with. Synchronization is achieved via "definition" (DFN) files, which define the format of MODFLOW6 inputs and outputs. FloPy contains Python source code automatically generated from DFN files. This is done with the `generate_classes` function in `flopy.mf6.utils`. See [this document](./docs/generate_classes.md) for usage examples.

## Examples

A number of scripts and notebooks demonstrating various `flopy` functions and features are located in `examples/` and `.docs/`. These are probably the easiest way to get acquainted with `flopy`.
Expand Down
56 changes: 56 additions & 0 deletions docs/generate_classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generating FloPy classes

MODFLOW 6 input continues to evolve as new models, packages, and options are developed, updated, and supported. All MODFLOW 6 input is described by DFN (definition) files, which are simple text files that describe the blocks and keywords in each input file. These definition files are used to build the input and output guide for MODFLOW 6. These definition files are also used to automatically generate FloPy classes for creating, reading and writing MODFLOW 6 models, packages, and options. FloPy and MODFLOW 6 are kept in sync by these DFN (definition) files, and therefore, it may be necessary for a user to update FloPy using a custom set of definition files, or a set of definition files from a previous release.

The FloPy classes for MODFLOW 6 are largely generated by a utility which converts DFN files in a modflow6 repository on GitHub or on the local machine into Python source files in your local FloPy install. For instance (output much abbreviated):

```python
>>> from flopy.mf6.utils import generate_classes
>>> generate_classes()



************************************************************************
Updating the flopy MODFLOW 6 classes
Updating the MODFLOW 6 classes using MODFLOW-USGS/modflow6/master
Downloading MODFLOW 6 repository from https://github.com/MODFLOW-USGS/modflow6/archive/master.zip
Downloading https://github.com/MODFLOW-USGS/modflow6/archive/master.zip
file size: 15,821,180 bytes

total download time: 0.88 seconds
Uncompressing: C:\Users\***\AppData\Local\Temp\***\master.zip
Deleting zipfile C:\Users\***\AppData\Local\Temp\***\master.zip
Done downloading and extracting master.zip to C:\Users\***\AppData\Local\Temp\***
Backup existing definition files in: C:\Users\***\flopy\flopy\mf6\data\dfn
Replacing existing definition files with new ones.
removing...common.dfn
removing...exg-gwfgwf.dfn
...
copying..common.dfn
copying..exg-gwfgwf.dfn
...
Deleting existing mf6 classes.
removing...mfgnc.py
removing...mfgwf.py
...
Create mf6 classes using the downloaded definition files.
LIST OF FILES IN C:\Users\***\flopy\flopy\mf6\modflow
1 - mfgnc.py
2 - mfgwf.py
...
```

The `generate_classes()` function has several optional arguments.

```python
# use the develop branch instead
generate_classes(branch="develop")

# use a fork of modflow6
generate_classes(owner="your-username", branch="your-branch")

# local copy of the repo
generate_classes(dfnpath="../your/dfn/path"))
```

By default, a backup is made of FloPy's package classes before rewriting them. To disable backups, use `backup=False`.

0 comments on commit 1d4e838

Please sign in to comment.