Skip to content

Commit

Permalink
Merge pull request #160 from ArtesiaWater/dev
Browse files Browse the repository at this point in the history
Update to 0.5.2
  • Loading branch information
rubencalje authored Apr 12, 2023
2 parents 8942bee + 7386579 commit 7a8e495
Show file tree
Hide file tree
Showing 75 changed files with 4,279 additions and 1,436 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ cython_debug/

# vscode
.vscode
.code-workspace
*.code-workspace

# nlmod specific
nlmod/bin/
flowchartnlmod.pptx
tests/data/
docs/examples/*/
docs/examples/*/
!docs/examples/data/
!docs/examples/data/chloride_hbossche.nc
13 changes: 5 additions & 8 deletions docs/examples/00_model_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"nlmod.util.get_color_logger('INFO');"
"nlmod.util.get_color_logger(\"INFO\");"
]
},
{
Expand Down Expand Up @@ -94,7 +94,6 @@
" extent,\n",
" delr=dx,\n",
" delc=dy,\n",
" layer=len(kh),\n",
" top=top,\n",
" botm=botm,\n",
" kh=kh,\n",
Expand All @@ -118,9 +117,7 @@
"metadata": {},
"outputs": [],
"source": [
"ds = nlmod.time.set_ds_time(\n",
" ds, time=[pd.Timestamp.today()], steady_state=True\n",
")\n"
"ds = nlmod.time.set_ds_time(ds, time=pd.Timestamp.today())"
]
},
{
Expand All @@ -143,7 +140,7 @@
"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"
"oc = nlmod.gwf.oc(ds, gwf, save_head=True)"
]
},
{
Expand All @@ -163,7 +160,7 @@
"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"
"wells"
]
},
{
Expand Down Expand Up @@ -210,7 +207,7 @@
"metadata": {},
"outputs": [],
"source": [
"riv_data = nlmod.gwf.surface_water.rivdata_from_xylist( \n",
"riv_data = nlmod.gwf.surface_water.rivdata_from_xylist(\n",
" gwf, xyriv, riv_layer, riv_stage, riv_cond, riv_botm\n",
")\n",
"\n",
Expand Down
24 changes: 9 additions & 15 deletions docs/examples/01_basic_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n"
"import nlmod"
]
},
{
Expand All @@ -35,7 +35,7 @@
"source": [
"print(f\"nlmod version: {nlmod.__version__}\")\n",
"\n",
"nlmod.util.get_color_logger('INFO');"
"nlmod.util.get_color_logger(\"INFO\");"
]
},
{
Expand Down Expand Up @@ -94,9 +94,7 @@
")\n",
"\n",
"# create a model ds by changing grid of layer_model\n",
"ds = nlmod.to_model_ds(\n",
" layer_model, model_name, model_ws, delr=delr, delc=delc\n",
")\n",
"ds = nlmod.to_model_ds(layer_model, model_name, model_ws, delr=delr, delc=delc)\n",
"\n",
"# add time discretisation\n",
"ds = nlmod.time.set_ds_time(\n",
Expand Down Expand Up @@ -135,7 +133,7 @@
"ic = nlmod.gwf.ic(ds, gwf, starting_head=starting_head)\n",
"\n",
"# Create the output control package\n",
"oc = nlmod.gwf.oc(ds, gwf)\n"
"oc = nlmod.gwf.oc(ds, gwf)"
]
},
{
Expand All @@ -153,7 +151,7 @@
"ds.update(rws_ds)\n",
"\n",
"# build ghb package\n",
"ghb = nlmod.gwf.ghb(ds, gwf, da_name)\n"
"ghb = nlmod.gwf.ghb(ds, gwf, da_name)"
]
},
{
Expand All @@ -179,7 +177,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\")\n"
"chd = nlmod.gwf.chd(ds, gwf, chd=\"edge_mask\", head=\"starting_head\")"
]
},
{
Expand All @@ -189,14 +187,12 @@
"outputs": [],
"source": [
"# download knmi recharge data\n",
"knmi_ds = nlmod.read.knmi.get_recharge(\n",
" ds, cachedir=ds.cachedir, cachename=\"recharge\"\n",
")\n",
"knmi_ds = nlmod.read.knmi.get_recharge(ds, cachedir=ds.cachedir, cachename=\"recharge\")\n",
"# update model dataset\n",
"ds.update(knmi_ds)\n",
"\n",
"# create recharge package\n",
"rch = nlmod.gwf.rch(ds, gwf)\n"
"rch = nlmod.gwf.rch(ds, gwf)"
]
},
{
Expand Down Expand Up @@ -231,9 +227,7 @@
"metadata": {},
"outputs": [],
"source": [
"nlmod.sim.write_and_run(\n",
" sim, ds, write_ds=True, nb_path=\"01_basic_model.ipynb\"\n",
")"
"nlmod.sim.write_and_run(sim, ds, write_ds=True, nb_path=\"01_basic_model.ipynb\")"
]
},
{
Expand Down
50 changes: 18 additions & 32 deletions docs/examples/02_surface_water.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"source": [
"print(f\"nlmod version: {nlmod.__version__}\")\n",
"\n",
"nlmod.util.get_color_logger('INFO');"
"nlmod.util.get_color_logger(\"INFO\");"
]
},
{
Expand Down Expand Up @@ -92,7 +92,7 @@
"source": [
"fname_ahn = os.path.join(cachedir, \"ahn.tif\")\n",
"if not os.path.isfile(fname_ahn):\n",
" ahn = nlmod.read.ahn.get_ahn4(extent, identifier='AHN4_DTM_5m')\n",
" ahn = nlmod.read.ahn.get_ahn4(extent, identifier=\"AHN4_DTM_5m\")\n",
" ahn.rio.to_raster(fname_ahn)\n",
"ahn = rioxarray.open_rasterio(fname_ahn, mask_and_scale=True)"
]
Expand Down Expand Up @@ -122,7 +122,7 @@
"metadata": {},
"source": [
"#### Add minimum surface height around surface water bodies\n",
"Get the minimum surface level in 1 meter around surface water levels and add these data to the column 'ahn_min'."
"Get the minimum surface level in 5 meter around surface water levels and add these data to the column 'ahn_min'."
]
},
{
Expand All @@ -132,18 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"# use geocube\n",
"gc = make_geocube(\n",
" vector_data=bgt.buffer(5.0).reset_index().rename_geometry('geometry'),\n",
" measurements=[\"index\"],\n",
" like=ahn, # ensure the data are on the same grid\n",
" rasterize_function=partial(rasterize_image, all_touched=True),\n",
")\n",
"gc['ahn'] = ahn\n",
"\n",
"ahn_min = gc.groupby('index').min()['ahn'].to_pandas()\n",
"ahn_min.index = ahn_min.index.astype(int)\n",
"bgt['ahn_min'] = ahn_min"
"bgt = nlmod.gwf.add_min_ahn_to_gdf(bgt, ahn, buffer=5.0, column='ahn_min')"
]
},
{
Expand Down Expand Up @@ -182,7 +171,7 @@
"metadata": {},
"outputs": [],
"source": [
"pg = nlmod.gwf.surface_water.download_level_areas(bgt, extent=extent)"
"la = nlmod.gwf.surface_water.download_level_areas(bgt, extent=extent, raise_exceptions=False)"
]
},
{
Expand All @@ -203,8 +192,8 @@
"source": [
"f, ax = nlmod.plot.get_map(extent)\n",
"bgt.plot(color=\"k\", ax=ax)\n",
"for wb in pg:\n",
" pg[wb].plot(\"summer_stage\", ax=ax, vmin=-3, vmax=1, zorder=0)"
"for wb in la:\n",
" la[wb].plot(\"summer_stage\", ax=ax, vmin=-3, vmax=1, zorder=0)"
]
},
{
Expand All @@ -223,7 +212,7 @@
"metadata": {},
"outputs": [],
"source": [
"bgt = nlmod.gwf.surface_water.add_stages_from_waterboards(bgt, pg=pg)"
"bgt = nlmod.gwf.surface_water.add_stages_from_waterboards(bgt, la=la)"
]
},
{
Expand Down Expand Up @@ -349,7 +338,9 @@
"outputs": [],
"source": [
"# layer model\n",
"layer_model = nlmod.read.get_regis(extent, cachedir=cachedir, cachename=\"layer_model.nc\")\n",
"layer_model = nlmod.read.get_regis(\n",
" extent, cachedir=cachedir, cachename=\"layer_model.nc\"\n",
")\n",
"layer_model"
]
},
Expand All @@ -361,9 +352,7 @@
"outputs": [],
"source": [
"# create a model ds by changing grid of layer_model\n",
"ds = nlmod.to_model_ds(\n",
" layer_model, model_name, model_ws, delr=delr, delc=delc\n",
")\n",
"ds = nlmod.to_model_ds(layer_model, model_name, model_ws, delr=delr, delc=delc)\n",
"\n",
"# create model time dataset\n",
"ds = nlmod.time.set_ds_time(ds, start_time=start_time, steady_state=True)\n",
Expand Down Expand Up @@ -502,12 +491,13 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n",
"sfw_grid.loc[mask].plot(column=\"identificatie\", legend=True, ax=ax,\n",
" legend_kwds={\"loc\": \"upper left\"})\n",
"sfw_grid.loc[mask].plot(\n",
" column=\"identificatie\", legend=True, ax=ax, legend_kwds={\"loc\": \"upper left\"}\n",
")\n",
"xlim = ax.get_xlim()\n",
"ylim = ax.get_ylim()\n",
"gwf.modelgrid.plot(ax=ax)\n",
"ax.set_xlim(xlim[0], xlim[0]+ds.delr*1.1)\n",
"ax.set_xlim(xlim[0], xlim[0] + ds.delr * 1.1)\n",
"ax.set_ylim(ylim)\n",
"ax.set_title(f\"Surface water shapes in cell: {cid}\");"
]
Expand Down Expand Up @@ -581,9 +571,7 @@
"metadata": {},
"outputs": [],
"source": [
"celldata = nlmod.gwf.surface_water.aggregate(\n",
" sfw_grid, \"area_weighted\"\n",
")"
"celldata = nlmod.gwf.surface_water.aggregate(sfw_grid, \"area_weighted\")"
]
},
{
Expand Down Expand Up @@ -723,9 +711,7 @@
"metadata": {},
"outputs": [],
"source": [
"nlmod.sim.write_and_run(\n",
" sim, ds, write_ds=True, nb_path=\"02_surface_water.ipynb\"\n",
")"
"nlmod.sim.write_and_run(sim, ds, write_ds=True, nb_path=\"02_surface_water.ipynb\")"
]
},
{
Expand Down
24 changes: 10 additions & 14 deletions docs/examples/03_local_grid_refinement.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"metadata": {},
"outputs": [],
"source": [
"print(f'nlmod version: {nlmod.__version__}')\n",
"print(f\"nlmod version: {nlmod.__version__}\")\n",
"\n",
"nlmod.util.get_color_logger('INFO');"
"nlmod.util.get_color_logger(\"INFO\");"
]
},
{
Expand Down Expand Up @@ -91,9 +91,7 @@
")\n",
"\n",
"# create a model ds by changing grid of layer_model\n",
"ds = nlmod.to_model_ds(\n",
" layer_model, model_name, model_ws, delr=delr, delc=delc\n",
")\n",
"ds = nlmod.to_model_ds(layer_model, model_name, model_ws, delr=delr, delc=delc)\n",
"\n",
"# add time discretisation\n",
"ds = nlmod.time.set_ds_time(\n",
Expand Down Expand Up @@ -122,9 +120,7 @@
"outputs": [],
"source": [
"# use gridgen to create vertex grid\n",
"ds = nlmod.grid.refine(\n",
" ds, refinement_features=[(refine_shp_fname, \"line\", levels)]\n",
")\n",
"ds = nlmod.grid.refine(ds, refinement_features=[(refine_shp_fname, \"line\", levels)])\n",
"\n",
"if add_northsea:\n",
" ds = nlmod.read.rws.add_northsea(ds, cachedir=cachedir)"
Expand Down Expand Up @@ -194,9 +190,7 @@
"outputs": [],
"source": [
"# add knmi recharge to the model datasets\n",
"knmi_ds = nlmod.read.knmi.get_recharge(\n",
" ds, cachedir=ds.cachedir, cachename=\"recharge\"\n",
")\n",
"knmi_ds = nlmod.read.knmi.get_recharge(ds, cachedir=ds.cachedir, cachename=\"recharge\")\n",
"ds.update(knmi_ds)\n",
"\n",
"# create recharge package\n",
Expand Down Expand Up @@ -321,13 +315,15 @@
"metadata": {},
"outputs": [],
"source": [
"fname = os.path.join(ds.figdir, 'results.nc')\n",
"fname = os.path.join(ds.figdir, \"results.nc\")\n",
"nlmod.gis.ds_to_ugrid_nc_file(ds, fname)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"cell_type": "raw",
"metadata": {
"raw_mimetype": "text/x-python"
},
"source": [
"## Compare with measurements\n",
"We can download the BRO groundwater observation data and compare the model results with this data."
Expand Down
Loading

0 comments on commit 7a8e495

Please sign in to comment.