Skip to content

Commit

Permalink
Merge pull request #192 from ArtesiaWater/dev
Browse files Browse the repository at this point in the history
Update to 0.6.0
  • Loading branch information
rubencalje authored Jun 7, 2023
2 parents feb6b46 + 3610637 commit 1c988bb
Show file tree
Hide file tree
Showing 91 changed files with 3,374 additions and 2,208 deletions.
25 changes: 9 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,40 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install codecov
pip install pytest-cov
pip install pytest-dependency
pip install codacy-coverage
pip install mfpymake
pip install -e .
pip install -e .[ci]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics
- name: Download executables needed for tests
shell: bash -l {0}
run: |
python -c "import nlmod; nlmod.util.download_mfbinaries()"
- name: Run notebooks
if: ${{ github.event_name == 'push' }}
run: |
py.test ./tests -m "not notebooks"
- name: Run tests only
if: ${{ github.event_name == 'pull_request' }}
run: |
py.test ./tests -m "not notebooks"
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@master
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ cython_debug/
*.code-workspace

# nlmod specific
nlmod/bin/
nlmod/bin/*
!nlmod/bin/
!nlmod/bin/mp7_2_002_provisional
flowchartnlmod.pptx
tests/data/
docs/examples/*/
Expand Down
8 changes: 6 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ sphinx:

# Optionally declare the Python requirements required to build your docs
python:
system_packages: true
install:
- requirements: docs/requirements.txt
- method: setuptools
- method: pip
path: .
extra_requirements:
- nbtest
- rtd

20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# nlmod

<img src="docs/_static/logo_10000_2.png" width="256"/>

[![nlmod](https://github.com/ArtesiaWater/nlmod/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ArtesiaWater/nlmod/actions/workflows/ci.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6fadea550ea04ea28b6ccde88fc56f35)](https://www.codacy.com/gh/ArtesiaWater/nlmod/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ArtesiaWater/nlmod&amp;utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6fadea550ea04ea28b6ccde88fc56f35)](https://www.codacy.com/gh/ArtesiaWater/nlmod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ArtesiaWater/nlmod&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/6fadea550ea04ea28b6ccde88fc56f35)](https://www.codacy.com/gh/ArtesiaWater/nlmod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ArtesiaWater/nlmod&utm_campaign=Badge_Coverage)
[![PyPI version](https://badge.fury.io/py/nlmod.svg)](https://badge.fury.io/py/nlmod)
[![Documentation Status](https://readthedocs.org/projects/nlmod/badge/?version=stable)](https://nlmod.readthedocs.io/en/stable/?badge=stable)

Python package with functions to process, build and visualise MODFLOW models in the Netherlands.
Python package with functions to process, build and visualise MODFLOW models in the Netherlands.

The functions in nlmod have four main objectives:

1. Create and adapt the temporal and spatial discretization of a MODFLOW model using an xarray Dataset (`nlmod.dims`).
2. Download and read data from external sources, project this data on the modelgrid and add this data to an xarray Dataset (`nlmod.read`).
3. Use data in an xarray Dataset to build modflow packages using FloPy (`nlmod.gwf` for Modflow 6 and `nlmod.modpath` for Modpath).
Expand All @@ -23,16 +25,18 @@ Install the module with pip:

`pip install nlmod`

`nlmod` has many dependencies `xarray`, `flopy`, `rasterio`, `rioxarray`, `owslib`, `hydropandas`, `netcdf4`, `pyshp`, `rtree`, `openpyxl` and `matplotlib`.
`nlmod` has many required dependencies: `flopy`, `xarray`, `netcdf4`, `rasterio`, `rioxarray`, `affine`, `geopandas`, `owslib`, `hydropandas`, `shapely`, `pyshp`, `rtree`, `matplotlib`, `dask` and `colorama`. On top of that there are some optional dependecies, only needed (and imported) in a single method. Examples of this are `bottleneck` (used in calculate_gxg), `geocube` (used in add_min_ahn_to_gdf), `h5netcdf` (used for hdf5 files backend in xarray). To install the nlmod with the optional dependencies use:

When using pip the dependencies are automatically installed. Some dependencies are notoriously hard to install on certain platforms.
Please see the [dependencies](https://github.com/ArtesiaWater/hydropandas#dependencies) section of the `hydropandas` package for more information on how to install these packages manually.
`pip install nlmod[full]`

When using pip the dependencies are automatically installed. Some dependencies are notoriously hard to install on certain platforms.
Please see the [dependencies](https://github.com/ArtesiaWater/hydropandas#dependencies) section of the `hydropandas` package for more information on how to install these packages manually.

## Getting started

If you are using nlmod for the first time you need to download the MODFLOW executables. You can easily download these executables by running this Python code:

import nlmod
nlmod.util.download_mfbinaries()
import nlmod
nlmod.download_mfbinaries()

After you've downloaded the executables you can run the Jupyter Notebooks in the examples folder. These notebooks illustrate how you to use the nlmod package.
After you've downloaded the executables you can run the Jupyter Notebooks in the examples folder. These notebooks illustrate how you to use the nlmod package.
46 changes: 33 additions & 13 deletions docs/examples/00_model_from_scratch.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -35,6 +36,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -49,10 +51,11 @@
"outputs": [],
"source": [
"if not nlmod.util.check_presence_mfbinaries():\n",
" nlmod.util.download_mfbinaries()"
" nlmod.download_mfbinaries()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -78,6 +81,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -105,6 +109,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -121,6 +126,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -144,6 +150,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -173,6 +180,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -215,6 +223,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -231,6 +240,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -247,6 +257,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -262,20 +273,21 @@
"fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n",
"\n",
"pc = nlmod.plot.data_array(\n",
" head.sel(layer=1).isel(time=0),\n",
" head.sel(layer=0).isel(time=0),\n",
" ds=ds,\n",
" cmap=\"RdYlBu\",\n",
" ax=ax,\n",
" edgecolor=\"k\",\n",
")\n",
"nlmod.plot.modelgrid(ds, ax=ax, alpha=0.5, lw=0.5)\n",
"ax.axis(extent)\n",
"cbar = ax.figure.colorbar(pc, shrink=1.0)\n",
"cbar.set_label(\"head [m NAP]\")\n",
"ax.set_title(\"head layer 1\")\n",
"ax.set_title(\"head first layer\")\n",
"fig.tight_layout()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -288,17 +300,25 @@
"metadata": {},
"outputs": [],
"source": [
"fig, axes = nlmod.plot.facet_plot(\n",
" gwf,\n",
" head,\n",
" lbl=\"head [m NAP]\",\n",
" plot_dim=\"layer\",\n",
" period=0,\n",
"fg = head.plot(\n",
" x=\"x\",\n",
" y=\"y\",\n",
" col=\"layer\",\n",
" col_wrap=3,\n",
" cmap=\"RdYlBu\",\n",
" plot_bc={\"WEL\": {}},\n",
" plot_grid=True,\n",
")"
" subplot_kws={\"aspect\": \"equal\"},\n",
")\n",
"\n",
"for iax in fg.axs.flat:\n",
" nlmod.plot.modelgrid(ds, ax=iax, alpha=0.5, lw=0.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/01_basic_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -49,7 +50,7 @@
"- a structured grid based on the subsurface models [Regis](https://www.dinoloket.nl/regis-ii-het-hydrogeologische-model) and [Geotop](https://www.dinoloket.nl/detaillering-van-de-bovenste-lagen-met-geotop). The Regis layers that are not present within the extent are removed. In this case we use 'MSz1' as the bottom layer of the model. Use `nlmod.read.regis.get_layer_names()` to get all the layer names of Regis. All Regis layers below this layer are not used in the model. Geotop is used to replace the holoceen layer in Regis because there is no kh or kv defined for the holoceen in Regis. Part of the model is in the North sea. Regis and Geotop have no data there. Therefore the Regis and Geotop layers are extrapolated from the shore and the seabed is added using bathymetry data from [Jarkus](https://www.openearth.nl/rws-bathymetry/2018.html).\n",
"- starting heads of 1 in every cell.\n",
"- the model is a steady state model of a single time step.\n",
"- big surface water bodies (Northsea, IJsselmeer, Markermeer, Noordzeekanaal) within the extent are added as a general head boundary. The surface water bodies are obtained from a [shapefile](..\\data\\opp_water.shp).\n",
"- big surface water bodies (Northsea, IJsselmeer, Markermeer, Noordzeekanaal) within the extent are added as a general head boundary. The surface water bodies are obtained from a [shapefile](..\\data\\shapes\\opp_water.shp).\n",
"- surface drainage is added using [ahn](https://www.ahn.nl) data and a default conductance of $1000 m^2/d$\n",
"- recharge is added using data from the [knmi](https://www.knmi.nl/nederland-nu/klimatologie/daggegevens) using the following steps:~~\n",
" 1. Check for each cell which KNMI weather and/or rainfall station is closest.\n",
Expand Down Expand Up @@ -151,7 +152,7 @@
"ds.update(rws_ds)\n",
"\n",
"# build ghb package\n",
"ghb = nlmod.gwf.ghb(ds, gwf, da_name)"
"ghb = nlmod.gwf.ghb(ds, gwf, bhead=f\"{da_name}_stage\", cond=f\"{da_name}_cond\")"
]
},
{
Expand All @@ -177,7 +178,7 @@
"source": [
"# add constant head cells at model boundaries\n",
"ds.update(nlmod.grid.mask_model_edge(ds, ds[\"idomain\"]))\n",
"chd = nlmod.gwf.chd(ds, gwf, chd=\"edge_mask\", head=\"starting_head\")"
"chd = nlmod.gwf.chd(ds, gwf, mask=\"edge_mask\", head=\"starting_head\")"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/02_surface_water.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"bgt = nlmod.gwf.add_min_ahn_to_gdf(bgt, ahn, buffer=5.0, column='ahn_min')"
"bgt = nlmod.gwf.add_min_ahn_to_gdf(bgt, ahn, buffer=5.0, column=\"ahn_min\")"
]
},
{
Expand Down Expand Up @@ -171,7 +171,9 @@
"metadata": {},
"outputs": [],
"source": [
"la = nlmod.gwf.surface_water.download_level_areas(bgt, extent=extent, raise_exceptions=False)"
"la = nlmod.gwf.surface_water.download_level_areas(\n",
" bgt, extent=extent, raise_exceptions=False\n",
")"
]
},
{
Expand Down
Loading

0 comments on commit 1c988bb

Please sign in to comment.