Skip to content

Commit

Permalink
Merge pull request #126 from ArtesiaWater/dev
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
dbrakenhoff authored Nov 2, 2022
2 parents 33e0d48 + 7f7f836 commit a6d0dfc
Show file tree
Hide file tree
Showing 81 changed files with 4,955 additions and 2,339 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@

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

The functions in nlmod have three main objectives:
1. Create and adapt the temporal and spatial discretization of a MODFLOW model using an xarray Dataset. These functions are contained in `nlmod.mdims`
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. These functions are contained in `nlmod.dims`
2. Read data from external sources, project this data on the modelgrid and add this data to an xarray Dataset. These functions are contained in `nlmod.read`
3. Use data in an xarray Dataset to build modflow packages using flopy. These functions are contained in `nlmod.mfpackages`
3. Use data in an xarray Dataset to build modflow packages using flopy. The functions for modflow 6 packages are in `nlmod.gwf`, for modpath in `nlmod.modpath`.
4. Visualise modeldata in Python or GIS software. These functions are contained in `nlmod.plot` and `nlmod.gis`.

External data sources that can be read are:
- REGIS, subsurface model
- AHN, digital elevation model
- bgt, surface water level geometries
- Geotop, subsurface model
- KNMI, precipitation and evaporation
- Jarkus, bathymetry
- KNMI, precipitation and evaporation
- REGIS, subsurface model
- Rijkswaterstaat, surface water polygons
- multiple waterboards, surface water level data

## Installation

Expand Down
333 changes: 333 additions & 0 deletions docs/examples/00_model_from_scratch.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<IMG SRC=\"https://avatars2.githubusercontent.com/u/31697400?s=400&u=a5a6fc31ec93c07853dd53835936fd90c44f7483&v=4\" WIDTH=125 ALIGN=\"right\">\n",
"\n",
"\n",
"# Building a groundwater model from scratch with `nlmod`\n",
"\n",
"This notebook shows how to build a basic model from scratch using `nlmod`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import flopy as fp\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nlmod.util.get_color_logger('INFO');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download MODFLOW-binaries\n",
"To run MODFLOW, we need to download the MODFLOW-excecutables. We do this with the following code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not nlmod.util.check_presence_mfbinaries():\n",
" nlmod.util.download_mfbinaries()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"extent = [-500, 500, -500, 500]\n",
"\n",
"top = 0.0\n",
"botm = [-10, -15, -30]\n",
"\n",
"kh = [10, 0.1, 20]\n",
"kv = [0.5 * k for k in kh]\n",
"\n",
"dx = 10.0\n",
"dy = 10.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create model dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = nlmod.get_ds(\n",
" extent,\n",
" delr=dx,\n",
" delc=dy,\n",
" layer=len(kh),\n",
" top=top,\n",
" botm=botm,\n",
" kh=kh,\n",
" kv=kv,\n",
" model_ws=\"./scratch_model\",\n",
" model_name=\"from_scratch\",\n",
")\n",
"ds"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Set time discretisation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds = nlmod.time.set_ds_time(\n",
" ds, time=[pd.Timestamp.today()], steady_state=True\n",
")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Start building model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim = nlmod.sim.sim(ds)\n",
"tdis = nlmod.sim.tdis(ds, sim)\n",
"ims = nlmod.sim.ims(sim, complexity=\"SIMPLE\")\n",
"gwf = nlmod.gwf.gwf(ds, sim)\n",
"dis = nlmod.gwf.dis(ds, gwf)\n",
"npf = nlmod.gwf.npf(ds, gwf)\n",
"ic = nlmod.gwf.ic(ds, gwf, starting_head=1.0)\n",
"oc = nlmod.gwf.oc(ds, gwf, save_head=True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add wells"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wells = pd.DataFrame(columns=[\"x\", \"y\", \"top\", \"botm\", \"Q\"], index=range(2))\n",
"wells.index.name = \"well no.\"\n",
"wells.loc[0] = 100, -50, -5, -10, -100.0\n",
"wells.loc[1] = 200, 150, -20, -30, -300.0\n",
"wells\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wel = nlmod.gwf.wells.wel_from_df(wells, gwf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add river"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xyriv = [\n",
" (250, -500),\n",
" (300, -300),\n",
" (275, 0),\n",
" (200, 250),\n",
" (175, 500),\n",
"]\n",
"\n",
"riv_layer = 0 # add to first layer\n",
"\n",
"bed_resistance = 0.1 # days\n",
"riv_cond = dx * dy / bed_resistance # conductance\n",
"riv_stage = 1.0 # m NAP\n",
"riv_botm = -3.0 # m NAP"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"riv_data = nlmod.gwf.surface_water.rivdata_from_xylist( \n",
" gwf, xyriv, riv_layer, riv_stage, riv_cond, riv_botm\n",
")\n",
"\n",
"riv = fp.mf6.ModflowGwfriv(gwf, stress_period_data={0: riv_data})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Write and run Simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nlmod.sim.write_and_run(sim, ds, silent=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load heads"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"head = nlmod.util.get_heads_dataarray(ds)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot heads"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"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",
" ds=ds,\n",
" cmap=\"RdYlBu\",\n",
" ax=ax,\n",
" edgecolor=\"k\",\n",
")\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",
"fig.tight_layout()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot heads in all layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"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",
" cmap=\"RdYlBu\",\n",
" plot_bc={\"WEL\": {}},\n",
" plot_grid=True,\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "dace5e1b41a98a8e52d2a8eebc3b981caf2c12e7a76736ebfb89a489e3b62e79"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit a6d0dfc

Please sign in to comment.