Skip to content

Commit

Permalink
Fix warnings and clean notebooks (#116)
Browse files Browse the repository at this point in the history
* Fix warnings and clean notebooks

* Add fixed vmin and vmax for plots of data-arrays
  • Loading branch information
rubencalje authored Oct 31, 2022
1 parent e454fbf commit afd1dad
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 79 deletions.
52 changes: 24 additions & 28 deletions docs/examples/02_surface_water.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n"
"import numpy as np\n",
"import warnings\n",
"from shapely.errors import ShapelyDeprecationWarning"
]
},
{
Expand All @@ -57,10 +59,12 @@
"metadata": {},
"outputs": [],
"source": [
"warnings.filterwarnings(\"ignore\", category=ShapelyDeprecationWarning)\n",
"\n",
"print(f\"nlmod version: {nlmod.__version__}\")\n",
"\n",
"# toon informatie bij het aanroepen van functies\n",
"logging.basicConfig(level=logging.INFO)\n"
"logging.basicConfig(level=logging.INFO)"
]
},
{
Expand Down Expand Up @@ -106,7 +110,7 @@
"# set the stage of the Lek to 0.0 m NAP and the botm to -3 m NAP\n",
"mask = sfw[\"bronhouder\"] == \"L0002\"\n",
"sfw.loc[mask, \"stage\"] = 0.0\n",
"sfw.loc[mask, \"botm\"] = -3.0\n"
"sfw.loc[mask, \"botm\"] = -3.0"
]
},
{
Expand Down Expand Up @@ -147,7 +151,7 @@
"ax.set_xlabel(\"X (m RD)\")\n",
"ax.set_ylabel(\"Y (m RD)\")\n",
"plt.yticks(rotation=90, va=\"center\")\n",
"fig.tight_layout()\n"
"fig.tight_layout()"
]
},
{
Expand All @@ -172,7 +176,7 @@
"ax.set_xlabel(\"X (m RD)\")\n",
"ax.set_ylabel(\"Y (m RD)\")\n",
"plt.yticks(rotation=90, va=\"center\")\n",
"fig.tight_layout()\n"
"fig.tight_layout()"
]
},
{
Expand Down Expand Up @@ -206,7 +210,7 @@
"figdir, cachedir = nlmod.util.get_model_dirs(model_ws)\n",
"\n",
"delr = delc = 50.0\n",
"start_time = \"2021-01-01\"\n"
"start_time = \"2021-01-01\""
]
},
{
Expand All @@ -224,7 +228,7 @@
" cachedir=cachedir,\n",
" cachename=\"combined_layer_ds.nc\",\n",
")\n",
"layer_model\n"
"layer_model"
]
},
{
Expand All @@ -242,7 +246,7 @@
"# create model time dataset\n",
"ds = nlmod.mdims.set_ds_time(ds, start_time=start_time, steady_state=True)\n",
"\n",
"ds\n"
"ds"
]
},
{
Expand Down Expand Up @@ -274,7 +278,7 @@
"ic = nlmod.gwf.ic(ds, gwf, starting_head=1.0)\n",
"\n",
"# Create the output control package\n",
"oc = nlmod.gwf.oc(ds, gwf)\n"
"oc = nlmod.gwf.oc(ds, gwf)"
]
},
{
Expand Down Expand Up @@ -311,7 +315,7 @@
"metadata": {},
"outputs": [],
"source": [
"sfw_grid = nlmod.mdims.gdf_to_grid(sfw, gwf)\n"
"sfw_grid = nlmod.mdims.gdf_to_grid(sfw, gwf)"
]
},
{
Expand Down Expand Up @@ -359,7 +363,7 @@
"cid = (107, 6) # for 50 x 50 m grid\n",
"# cid = (5, 45) # for 100 x 100 m grid\n",
"mask = sfw_grid.cellid == cid\n",
"sfw_grid.loc[mask]\n"
"sfw_grid.loc[mask]"
]
},
{
Expand Down Expand Up @@ -421,7 +425,7 @@
"try:\n",
" nlmod.gwf.surface_water.aggregate(sfw_grid, \"area_weighted\")\n",
"except ValueError as e:\n",
" print(e)\n"
" print(e)"
]
},
{
Expand All @@ -439,7 +443,7 @@
"metadata": {},
"outputs": [],
"source": [
"sfw_grid[\"c0\"] = 1.0 # days\n"
"sfw_grid[\"c0\"] = 1.0 # days"
]
},
{
Expand All @@ -459,7 +463,7 @@
"source": [
"celldata = nlmod.gwf.surface_water.aggregate(\n",
" sfw_grid, \"area_weighted\"\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -512,7 +516,7 @@
"outputs": [],
"source": [
"new_celldata = celldata.loc[~celldata.rbot.isna()]\n",
"print(f\"removed {len(celldata)-len(new_celldata)} reaches because rbot is nan\")\n"
"print(f\"removed {len(celldata)-len(new_celldata)} reaches because rbot is nan\")"
]
},
{
Expand All @@ -522,7 +526,7 @@
"metadata": {},
"outputs": [],
"source": [
"riv_spd = nlmod.gwf.surface_water.build_spd(new_celldata, \"RIV\", ds)\n"
"riv_spd = nlmod.gwf.surface_water.build_spd(new_celldata, \"RIV\", ds)"
]
},
{
Expand Down Expand Up @@ -560,7 +564,7 @@
"metadata": {},
"outputs": [],
"source": [
"riv = flopy.mf6.ModflowGwfriv(gwf, stress_period_data=riv_spd)\n"
"riv = flopy.mf6.ModflowGwfriv(gwf, stress_period_data=riv_spd)"
]
},
{
Expand All @@ -580,7 +584,7 @@
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(10, 8), constrained_layout=True)\n",
"mv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)\n",
"mv.plot_bc(\"RIV\")\n"
"mv.plot_bc(\"RIV\")"
]
},
{
Expand All @@ -602,7 +606,7 @@
"source": [
"nlmod.sim.write_and_run(\n",
" sim, ds, write_ds=True, nb_path=\"02_surface_water.ipynb\"\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -694,14 +698,6 @@
"col = gwf.modelgrid.ncol // 2\n",
"ax.set_title(f\"Cross-section along column {col}\");\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4478d66",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -720,7 +716,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
Expand Down
22 changes: 13 additions & 9 deletions docs/examples/03_local_grid_refinement.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n"
"import nlmod\n",
"import warnings\n",
"from shapely.errors import ShapelyDeprecationWarning"
]
},
{
Expand All @@ -46,6 +48,8 @@
"metadata": {},
"outputs": [],
"source": [
"warnings.filterwarnings(\"ignore\", category=ShapelyDeprecationWarning)\n",
"\n",
"print(f'nlmod version: {nlmod.__version__}')\n",
"\n",
"# toon informatie bij het aanroepen van functies\n",
Expand Down Expand Up @@ -85,7 +89,7 @@
"regis_botm_layer = \"MSz1\"\n",
"use_geotop = True\n",
"add_northsea = True\n",
"starting_head = 1.0\n"
"starting_head = 1.0"
]
},
{
Expand Down Expand Up @@ -116,7 +120,7 @@
" steady_start=steady_start,\n",
" transient_timesteps=transient_timesteps,\n",
" perlen=perlen,\n",
")\n"
")"
]
},
{
Expand All @@ -140,7 +144,7 @@
")\n",
"\n",
"if add_northsea:\n",
" ds = nlmod.read.rws.add_northsea(ds, cachedir=cachedir)\n"
" ds = nlmod.read.rws.add_northsea(ds, cachedir=cachedir)"
]
},
{
Expand Down Expand Up @@ -171,7 +175,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 @@ -197,7 +201,7 @@
"\n",
"# add constant head cells at model boundaries\n",
"ds.update(nlmod.mgrid.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 @@ -213,7 +217,7 @@
"ds.update(knmi_ds)\n",
"\n",
"# create recharge package\n",
"rch = nlmod.gwf.rch(ds, gwf)\n"
"rch = nlmod.gwf.rch(ds, gwf)"
]
},
{
Expand All @@ -240,7 +244,7 @@
"source": [
"nlmod.sim.write_and_run(\n",
" sim, ds, write_ds=True, nb_path=\"03_local_grid_refinement.ipynb\"\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -318,7 +322,7 @@
"nlmod.plot.data_array(ds[\"bathymetry\"], ds, ax=axes[0][0])\n",
"nlmod.plot.data_array(ds[\"northsea\"], ds, ax=axes[0][1])\n",
"nlmod.plot.data_array(ds[\"kh\"][1], ds, ax=axes[1][0])\n",
"nlmod.plot.data_array(ds[\"recharge\"][:, 0], ds, ax=axes[1][1])\n"
"nlmod.plot.data_array(ds[\"recharge\"][:, 0], ds, ax=axes[1][1])"
]
},
{
Expand Down
33 changes: 14 additions & 19 deletions docs/examples/07_resampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"# Resampling \n",
"\n",
"Resampling data is a very common operation when building a Modflow model. Usually it is used to project data from one grid onto the other. There are many different ways to do this. This notebook shows some examples of resampling methods that are incorporated in the `nlmod` package. These methods rely heavily on resampling methods in other packages such as `scipy.interpolate` and `xarray`."
"Resampling data is a very common operation when building a Modflow model. Usually it is used to project data from one grid onto the other. There are many different ways to do this. This notebook shows some examples of resampling methods that are incorporated in the `nlmod` package. These methods rely heavily on resampling methods in packages such as `rioxarray` and `scipy.interpolate`."
]
},
{
Expand Down Expand Up @@ -198,7 +198,7 @@
"# create vertextured dataarray\n",
"coords = dict(x=xr.DataArray(xvc, dims=['icell2d',]), y=xr.DataArray(yvc, dims=['icell2d',]))\n",
"vertex1 = xr.DataArray(values, dims=('icell2d'), coords=coords)\n",
"nlmod.visualise.plots.plot_vertex_array(vertex1, vertices, gridkwargs={'edgecolor': 'k'});"
"nlmod.plot.plot_vertex_array(vertex1, vertices, gridkwargs={'edgecolor': 'k'});"
]
},
{
Expand All @@ -217,7 +217,7 @@
"vertex1_nan = vertex1.copy().astype(float)\n",
"vertex1_nan.values[7] = np.nan\n",
"\n",
"nlmod.visualise.plots.plot_vertex_array(vertex1_nan, vertices, gridkwargs={'edgecolor': 'k'});"
"nlmod.plot.plot_vertex_array(vertex1_nan, vertices, gridkwargs={'edgecolor': 'k'});"
]
},
{
Expand Down Expand Up @@ -247,10 +247,10 @@
"source": [
"def compare_structured_data_arrays(da1, da2, method, edgecolor='k'):\n",
" fig, axes = plt.subplots(ncols=2, figsize=(12,6))\n",
" da1.plot(ax=axes[0], edgecolor=edgecolor)\n",
" da1.plot(ax=axes[0], edgecolor=edgecolor, vmin=0, vmax=9)\n",
" axes[0].set_aspect('equal')\n",
" axes[0].set_title('original grid')\n",
" da2.plot(ax=axes[1], edgecolor=edgecolor)\n",
" da2.plot(ax=axes[1], edgecolor=edgecolor, vmin=0, vmax=9)\n",
" axes[1].set_aspect('equal')\n",
" axes[1].set_title(f'resampled grid, method {method}')"
]
Expand Down Expand Up @@ -367,10 +367,10 @@
"source": [
"def compare_struct_to_vertex(struc2d, res_vertex2d_n, vertices, method):\n",
" fig, axes = plt.subplots(ncols=2, figsize=(12,6))\n",
" struc2d.plot(ax=axes[0], edgecolor='k')\n",
" struc2d.plot(ax=axes[0], edgecolor='k', vmin=0, vmax=9)\n",
" axes[0].set_aspect('equal')\n",
" axes[0].set_title('structured grid')\n",
" nlmod.visualise.plots.plot_vertex_array(res_vertex2d_n, vertices, ax=axes[1], gridkwargs={'edgecolor': 'k'})\n",
" nlmod.plot.plot_vertex_array(res_vertex2d_n, vertices, ax=axes[1], gridkwargs={'edgecolor': 'k'}, vmin=0, vmax=9)\n",
" axes[1].set_title(f'locally refined grid, method {method}')"
]
},
Expand Down Expand Up @@ -419,9 +419,9 @@
"source": [
"def compare_vertex_to_struct(vertex1, struc_out_n, method):\n",
" fig, axes = plt.subplots(ncols=2, figsize=(12,6))\n",
" nlmod.visualise.plots.plot_vertex_array(vertex1, vertices, ax=axes[0], gridkwargs={'edgecolor': 'k'})\n",
" nlmod.plot.plot_vertex_array(vertex1, vertices, ax=axes[0], gridkwargs={'edgecolor': 'k'}, vmin=0, vmax=9)\n",
" axes[0].set_title('original')\n",
" struc_out_n.plot(ax=axes[1], edgecolor='k')\n",
" struc_out_n.plot(ax=axes[1], edgecolor='k', vmin=0, vmax=9)\n",
" axes[1].set_title(f'resampled, method {method}')\n",
" axes[1].set_aspect('equal')"
]
Expand Down Expand Up @@ -502,9 +502,9 @@
"source": [
"def compare_vertex_arrays(vertex1, vertex2, method):\n",
" fig, axes = plt.subplots(ncols=2, figsize=(12,6))\n",
" nlmod.visualise.plots.plot_vertex_array(vertex1, vertices, ax=axes[0], gridkwargs={'edgecolor': 'k'})\n",
" nlmod.plot.plot_vertex_array(vertex1, vertices, ax=axes[0], gridkwargs={'edgecolor': 'k'}, vmin=0, vmax=9)\n",
" axes[0].set_title('original')\n",
" nlmod.visualise.plots.plot_vertex_array(vertex2, vertices, ax=axes[1], gridkwargs={'edgecolor': 'k'})\n",
" nlmod.plot.plot_vertex_array(vertex2, vertices, ax=axes[1], gridkwargs={'edgecolor': 'k'}, vmin=0, vmax=9)\n",
" axes[1].set_title(f'resampled, method {method}')\n",
" axes[1].set_aspect('equal')"
]
Expand Down Expand Up @@ -549,7 +549,9 @@
"source": [
"point_geom = [Point(x,y) for x, y in zip([1000, 1200, 1225, 1300],[20200, 20175, 20175, 20425])]\n",
"point_gdf = gpd.GeoDataFrame({'values':[1,52,66,24]}, geometry=point_geom)\n",
"line_geom = [LineString([point_geom[0], point_geom[1]]), LineString([point_geom[2], point_geom[3]]), LineString([point_geom[0], point_geom[3]])]\n",
"line_geom = [LineString([point_geom[0], point_geom[1]]),\n",
" LineString([point_geom[2], point_geom[3]]),\n",
" LineString([point_geom[0], point_geom[3]])]\n",
"line_gdf = gpd.GeoDataFrame({'values':[1,52,66]}, geometry=line_geom)\n",
"pol_geom = [shp_polygon([point_geom[0], point_geom[1], point_geom[2], point_geom[3], point_geom[0]]),\n",
" shp_polygon([point_geom[0], point_geom[1], point_geom[2], Point(1200,20300), point_geom[0]])]\n",
Expand Down Expand Up @@ -1100,13 +1102,6 @@
" axes[1].set_aspect('equal')\n",
" axes[1].set_title(f'resampled grid, method {method}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit afd1dad

Please sign in to comment.