Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CI and some code cleanup #358

Merged
merged 13 commits into from
Jul 2, 2024
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]

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

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

Expand All @@ -32,12 +32,10 @@ jobs:
python -m pip install --upgrade pip
pip install -e .[ci]

- name: Lint with flake8
- name: Download executables needed for tests
shell: bash -l {0}
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
python -c "import nlmod; nlmod.util.download_mfbinaries()"

- name: Run tests only
env:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

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

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build setuptools wheel

- name: build binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/

- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ groundwater models, makes models more reproducible and transparent.

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 for both groundwater flow and transport models using FloPy (`nlmod.sim`, `nlmod.gwf` and `nlmod.gwt` for Modflow 6 and `nlmod.modpath` for Modpath).
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 for both groundwater flow
and transport models using FloPy (`nlmod.sim`, `nlmod.gwf` and `nlmod.gwt` for
Modflow 6 and `nlmod.modpath` for Modpath).
4. Visualise modeldata in Python (`nlmod.plot`) or GIS software (`nlmod.gis`).

More information can be found on the documentation-website:
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from nlmod import __version__
import os
import sys

from nlmod import __version__

sys.path.insert(0, os.path.abspath("."))


Expand Down
7 changes: 3 additions & 4 deletions docs/examples/00_model_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
"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"
"import pandas as pd\n",
"\n",
"import nlmod"
]
},
{
Expand Down
5 changes: 0 additions & 5 deletions docs/examples/01_basic_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import os\n",
"\n",
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod"
]
},
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/02_surface_water.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"import os\n",
"\n",
"import flopy\n",
"import rioxarray\n",
"import matplotlib.pyplot as plt\n",
"import rioxarray\n",
"\n",
"import nlmod"
]
},
Expand Down
9 changes: 3 additions & 6 deletions docs/examples/03_local_grid_refinement.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@
"source": [
"import os\n",
"\n",
"import flopy\n",
"import numpy as np\n",
"import pandas as pd\n",
"import geopandas as gpd\n",
"import hydropandas as hpd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from IPython.display import HTML\n",
"import nlmod\n",
"import warnings"
"\n",
"import nlmod"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/04_modifying_layermodels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import pandas as pd\n",
"from nlmod.plot import DatasetCrossSection\n",
"from shapely.geometry import LineString"
"from shapely.geometry import LineString\n",
"\n",
"import nlmod\n",
"from nlmod.plot import DatasetCrossSection"
]
},
{
Expand Down
10 changes: 4 additions & 6 deletions docs/examples/05_caching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
"outputs": [],
"source": [
"import os\n",
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import xarray as xr"
"\n",
"import xarray as xr\n",
"\n",
"import nlmod"
]
},
{
Expand Down
15 changes: 7 additions & 8 deletions docs/examples/06_gridding_vector_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
"metadata": {},
"outputs": [],
"source": [
"import nlmod\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import geopandas as gpd\n",
"from IPython.display import display\n",
"from shapely.geometry import LineString, Point\n",
"from shapely.geometry import Polygon as shp_polygon\n",
"\n",
"from IPython.display import display"
"import nlmod"
]
},
{
Expand Down Expand Up @@ -391,8 +389,9 @@
" ds = ds.expand_dims({\"layer\": range(3)})\n",
"\n",
"# create some data arrays\n",
"ds[\"da1\"] = (\"layer\", \"y\", \"x\"), np.random.randint(\n",
" 0, 10, (ds.sizes[\"layer\"], ds.sizes[\"y\"], ds.sizes[\"x\"])\n",
"ds[\"da1\"] = (\n",
" (\"layer\", \"y\", \"x\"),\n",
" np.random.randint(0, 10, (ds.sizes[\"layer\"], ds.sizes[\"y\"], ds.sizes[\"x\"])),\n",
")\n",
"ds[\"da2\"] = (\"y\", \"x\"), np.random.randint(0, 10, (ds.sizes[\"y\"], ds.sizes[\"x\"]))\n",
"ds[\"da3\"] = (\"y\", \"x\"), np.random.randint(0, 10, (ds.sizes[\"y\"], ds.sizes[\"x\"]))\n",
Expand Down
24 changes: 8 additions & 16 deletions docs/examples/07_resampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,17 @@
"metadata": {},
"outputs": [],
"source": [
"import nlmod\n",
"from nlmod import resample\n",
"\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
"import flopy\n",
"import warnings\n",
"\n",
"\n",
"from matplotlib.colors import Normalize\n",
"from matplotlib.patches import Polygon\n",
"from matplotlib.collections import PatchCollection\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import geopandas as gpd\n",
"from shapely.geometry import LineString, Point\n",
"from shapely.geometry import Polygon as shp_polygon\n",
"from scipy.interpolate import RectBivariateSpline\n",
"from shapely.geometry import LineString, Point\n",
"\n",
"from IPython.display import display"
"import nlmod\n",
"from nlmod import resample"
]
},
{
Expand Down Expand Up @@ -100,7 +92,7 @@
"outputs": [],
"source": [
"ds[\"data_nan\"] = ds[\"data\"].copy()\n",
"ds[\"data_nan\"].data[0, 1] = np.NaN\n",
"ds[\"data_nan\"].data[0, 1] = np.nan\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.set_aspect(\"equal\")\n",
Expand Down Expand Up @@ -144,7 +136,7 @@
"outputs": [],
"source": [
"dsv[\"data_nan\"] = dsv[\"data\"].copy()\n",
"dsv[\"data_nan\"][7] = np.NaN\n",
"dsv[\"data_nan\"][7] = np.nan\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.set_aspect(\"equal\")\n",
Expand Down
10 changes: 4 additions & 6 deletions docs/examples/08_gis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import xarray as xr\n",
"from IPython.display import FileLink, FileLinks\n",
"from shapely.geometry import Polygon"
"from IPython.display import FileLink\n",
"\n",
"import nlmod"
]
},
{
Expand Down
11 changes: 5 additions & 6 deletions docs/examples/09_schoonhoven.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import xarray as xr\n",
"import pandas as pd\n",
"import hydropandas as hpd\n",
"import geopandas as gpd\n",
"from nlmod.plot import DatasetCrossSection\n",
"from shapely.geometry import LineString, Point\n",
"import warnings"
"\n",
"import nlmod\n",
"from nlmod.plot import DatasetCrossSection"
]
},
{
Expand Down
13 changes: 7 additions & 6 deletions docs/examples/10_modpath.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
"\n",
"import flopy\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import xarray as xr"
"import xarray as xr\n",
"\n",
"import nlmod"
]
},
{
Expand Down Expand Up @@ -164,7 +165,7 @@
" marker=\"o\",\n",
" color=\"red\",\n",
")\n",
"ax.set_title(f\"pathlines\")\n",
"ax.set_title(\"pathlines\")\n",
"ax.legend(loc=\"upper right\")"
]
},
Expand Down Expand Up @@ -265,7 +266,7 @@
" marker=\"o\",\n",
" color=\"red\",\n",
" )\n",
" ax.set_title(f\"pathlines\")\n",
" ax.set_title(\"pathlines\")\n",
" ax.legend(loc=\"upper right\")\n",
"\n",
" if i == 1:\n",
Expand Down Expand Up @@ -370,7 +371,7 @@
" marker=\"o\",\n",
" color=\"red\",\n",
" )\n",
" ax.set_title(f\"pathlines\")\n",
" ax.set_title(\"pathlines\")\n",
" ax.legend(loc=\"upper right\")\n",
"\n",
" if i == 1:\n",
Expand Down Expand Up @@ -477,7 +478,7 @@
" marker=\"o\",\n",
" color=\"red\",\n",
" )\n",
" ax.set_title(f\"pathlines\")\n",
" ax.set_title(\"pathlines\")\n",
" ax.legend(loc=\"upper right\")\n",
"\n",
" if i == 1:\n",
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/11_grid_rotation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"import matplotlib\n",
"import nlmod\n",
"import pandas as pd\n",
"import warnings\n",
"import flopy"
"\n",
"import nlmod"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/12_layer_generation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
"metadata": {},
"outputs": [],
"source": [
"import nlmod\n",
"from shapely.geometry import LineString"
"from shapely.geometry import LineString\n",
"\n",
"import nlmod"
]
},
{
Expand Down
Loading