From 34e69f7b0a5c4746a69b2b6fe88aa479b7765476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Thu, 24 Aug 2023 18:10:28 +0200 Subject: [PATCH 1/5] improve plotting in notebooks #224 - use nlmod.plot.get_map() where possible - simplify plotting with nlmod.plot.map_array() - other nb improvements (e.g. descriptions, text, etc). - rename kwarg background to backgroundmap in get_map - improve default axis ticks in get_map - some typos - rename layer coord to source_layer in get_concentration_at_gw_surface() --- docs/examples/00_model_from_scratch.ipynb | 31 ++++---- docs/examples/01_basic_model.ipynb | 28 ++++--- docs/examples/02_surface_water.ipynb | 78 ++++++++++++-------- docs/examples/03_local_grid_refinement.ipynb | 2 +- docs/examples/06_gridding_vector_data.ipynb | 25 ++----- docs/examples/07_resampling.ipynb | 8 +- docs/examples/08_gis.ipynb | 2 +- docs/examples/09_schoonhoven.ipynb | 33 ++++++--- docs/examples/11_grid_rotation.ipynb | 2 +- docs/examples/12_layer_generation.ipynb | 10 +-- docs/examples/13_plot_methods.ipynb | 29 ++++++-- docs/examples/14_stromingen_example.ipynb | 14 ++-- nlmod/cache.py | 4 +- nlmod/dims/grid.py | 2 +- nlmod/gwt/output.py | 4 + nlmod/plot/dcs.py | 2 +- nlmod/plot/plot.py | 20 +++-- nlmod/plot/plotutil.py | 18 +++-- nlmod/read/__init__.py | 2 +- nlmod/read/boundaries.py | 3 +- nlmod/read/jarkus.py | 6 +- nlmod/sim/sim.py | 2 +- nlmod/util.py | 1 - tests/test_012_plot.py | 2 +- 24 files changed, 190 insertions(+), 138 deletions(-) diff --git a/docs/examples/00_model_from_scratch.ipynb b/docs/examples/00_model_from_scratch.ipynb index ca010ed9..da381157 100644 --- a/docs/examples/00_model_from_scratch.ipynb +++ b/docs/examples/00_model_from_scratch.ipynb @@ -270,20 +270,17 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n", - "\n", - "pc = nlmod.plot.data_array(\n", + "# using nlmod plotting methods\n", + "ax = nlmod.plot.map_array(\n", " head.sel(layer=0).isel(time=0),\n", - " ds=ds,\n", + " ds,\n", " cmap=\"RdYlBu\",\n", - " ax=ax,\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 first layer\")\n", - "fig.tight_layout()" + " colorbar_label=\"head [m NAP]\",\n", + " xlabel=\"x [km]\",\n", + " ylabel=\"y [km]\",\n", + " title=\"head first layer\",\n", + " plot_grid=True,\n", + ")" ] }, { @@ -300,6 +297,7 @@ "metadata": {}, "outputs": [], "source": [ + "# using xarray plotting methods\n", "fg = head.plot(\n", " x=\"x\",\n", " y=\"y\",\n", @@ -307,6 +305,7 @@ " col_wrap=3,\n", " cmap=\"RdYlBu\",\n", " subplot_kws={\"aspect\": \"equal\"},\n", + " cbar_kwargs={\"label\": \"head [m NAP]\"},\n", ")\n", "\n", "for iax in fg.axs.flat:\n", @@ -322,8 +321,14 @@ } ], "metadata": { + "kernelspec": { + "display_name": "artesia", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "name": "python", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/docs/examples/01_basic_model.ipynb b/docs/examples/01_basic_model.ipynb index a1ee2ef6..ab0f9e14 100644 --- a/docs/examples/01_basic_model.ipynb +++ b/docs/examples/01_basic_model.ipynb @@ -262,30 +262,36 @@ "metadata": {}, "outputs": [], "source": [ - "fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(14, 11))\n", + "fig, axes = nlmod.plot.get_map(ds.extent, nrows=2, ncols=2, figsize=14)\n", "ds[\"ahn\"].plot(ax=axes[0][0])\n", "ds[\"botm\"][0].plot(ax=axes[0][1])\n", "ds[\"idomain\"][0].plot(ax=axes[1][0])\n", "ds[\"edge_mask\"][0].plot(ax=axes[1][1])\n", - "for axes1 in axes:\n", - " for ax in axes1:\n", - " ax.axis(\"scaled\")\n", "\n", - "fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(14, 11))\n", + "fig, axes = nlmod.plot.get_map(ds.extent, nrows=2, ncols=2, figsize=14)\n", "ds[\"bathymetry\"].plot(ax=axes[0][0])\n", "ds[\"northsea\"].plot(ax=axes[0][1])\n", "ds[\"kh\"][1].plot(ax=axes[1][0])\n", - "ds[\"recharge\"].plot(ax=axes[1][1])\n", - "\n", - "for axes1 in axes:\n", - " for ax in axes1:\n", - " ax.axis(\"scaled\")" + "ds[\"recharge\"].plot(ax=axes[1][1]);" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { + "kernelspec": { + "display_name": "artesia", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "name": "python", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/docs/examples/02_surface_water.ipynb b/docs/examples/02_surface_water.ipynb index f96a20bd..888c9b3d 100644 --- a/docs/examples/02_surface_water.ipynb +++ b/docs/examples/02_surface_water.ipynb @@ -293,14 +293,8 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n", - "ax.set_aspect(\"equal\", adjustable=\"box\")\n", - "sfw.plot(ax=ax, column=\"stage\", legend=True)\n", - "ax.grid(True)\n", - "ax.set_xlabel(\"X (m RD)\")\n", - "ax.set_ylabel(\"Y (m RD)\")\n", - "plt.yticks(rotation=90, va=\"center\")\n", - "fig.tight_layout()" + "fig, ax = nlmod.plot.get_map(extent)\n", + "sfw.plot(ax=ax, column=\"stage\", legend=True)" ] }, { @@ -446,14 +440,9 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n", - "ax.set_aspect(\"equal\", adjustable=\"box\")\n", + "fig, ax = nlmod.plot.get_map(extent)\n", "sfw_grid.plot(ax=ax, column=\"cellid\")\n", - "gwf.modelgrid.plot(ax=ax, linewidth=0.5, color=\"k\")\n", - "xmin, xmax, ymin, ymax = extent\n", - "offset = 100\n", - "ax.set_xlim(xmin - offset, xmax + offset)\n", - "ax.set_ylim(ymin - offset, ymax + offset);" + "nlmod.plot.modelgrid(ds, ax=ax, lw=0.2)" ] }, { @@ -494,7 +483,10 @@ "source": [ "fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n", "sfw_grid.loc[mask].plot(\n", - " column=\"identificatie\", legend=True, ax=ax, legend_kwds={\"loc\": \"upper left\"}\n", + " column=\"identificatie\",\n", + " legend=True,\n", + " ax=ax,\n", + " legend_kwds={\"loc\": \"lower left\", \"ncol\": 2, \"fontsize\": \"x-small\"},\n", ")\n", "xlim = ax.get_xlim()\n", "ylim = ax.get_ylim()\n", @@ -691,6 +683,7 @@ "metadata": {}, "outputs": [], "source": [ + "# use flopy plotting methods\n", "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\")" @@ -751,13 +744,17 @@ "metadata": {}, "outputs": [], "source": [ - "ilay = 0\n", - "fig, ax = plt.subplots(1, 1, figsize=(10, 8), constrained_layout=True)\n", - "mv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=ilay)\n", - "qm = mv.plot_array(head[-1], cmap=\"RdBu\") # last timestep\n", - "mv.plot_ibound() # plot inactive cells in red\n", - "fig.colorbar(qm, shrink=1.0)\n", - "ax.set_title(f\"Heads top-view, layer {ilay}\");" + "# using nlmod plotting methods\n", + "ax = nlmod.plot.map_array(\n", + " head,\n", + " ds,\n", + " ilay=0,\n", + " iper=0,\n", + " plot_grid=True,\n", + " title=\"Heads top-view\",\n", + " cmap=\"RdBu\",\n", + " colorbar_label=\"head [m NAP]\",\n", + ")" ] }, { @@ -775,21 +772,40 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = plt.subplots(1, 1, figsize=(10, 3), constrained_layout=True)\n", - "xs = flopy.plot.PlotCrossSection(\n", - " model=gwf, ax=ax, line={\"column\": gwf.modelgrid.ncol // 2}\n", - ")\n", + "# using flopy plotting methods\n", + "col = gwf.modelgrid.ncol // 2\n", + "\n", + "fig, ax = plt.subplots(1, 1, figsize=(10, 3))\n", + "xs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={\"column\": col})\n", "qm = xs.plot_array(head[-1], cmap=\"RdBu\") # last timestep\n", "xs.plot_ibound() # plot inactive cells in red\n", - "fig.colorbar(qm, shrink=1.0)\n", - "col = gwf.modelgrid.ncol // 2\n", - "ax.set_title(f\"Cross-section along column {col}\");" + "xs.plot_grid(lw=0.25, color=\"k\")\n", + "ax.set_ylim(bottom=-150)\n", + "ax.set_ylabel(\"elevation [m NAP]\")\n", + "ax.set_xlabel(\"distance along cross-section [m]\")\n", + "ax.set_title(f\"Cross-section along column {col}\")\n", + "cbar = fig.colorbar(qm, shrink=1.0)\n", + "cbar.set_label(\"head [m NAP]\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e5833d6", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { + "kernelspec": { + "display_name": "artesia", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "name": "python", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/docs/examples/03_local_grid_refinement.ipynb b/docs/examples/03_local_grid_refinement.ipynb index 79d7f9cd..0cf3113f 100644 --- a/docs/examples/03_local_grid_refinement.ipynb +++ b/docs/examples/03_local_grid_refinement.ipynb @@ -315,7 +315,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])" + "nlmod.plot.data_array(ds[\"recharge\"][0], ds, ax=axes[1][1]);" ] }, { diff --git a/docs/examples/06_gridding_vector_data.ipynb b/docs/examples/06_gridding_vector_data.ipynb index 11455287..e200775c 100644 --- a/docs/examples/06_gridding_vector_data.ipynb +++ b/docs/examples/06_gridding_vector_data.ipynb @@ -183,12 +183,11 @@ "sim = nlmod.sim.sim(ds)\n", "gwf = nlmod.gwf.gwf(ds, sim)\n", "dis = nlmod.gwf.dis(ds, gwf)\n", - "da1 = nlmod.grid.gdf_to_da(\n", - " point_gdf, ds, column=\"values\", agg_method=\"nearest\"\n", - ")\n", + "da1 = nlmod.grid.gdf_to_da(point_gdf, ds, column=\"values\", agg_method=\"nearest\")\n", "da2 = xr.DataArray(np.nan, dims=(\"y\", \"x\"), coords={\"y\": ds.y, \"x\": ds.x})\n", - "da2.values = nlmod.grid.interpolate_gdf_to_array(point_gdf, gwf, field='values', \n", - "method='linear')\n", + "da2.values = nlmod.grid.interpolate_gdf_to_array(\n", + " point_gdf, gwf, field=\"values\", method=\"linear\"\n", + ")\n", "\n", "vmin = min(da1.min(), da2.min())\n", "vmax = max(da1.max(), da2.max())\n", @@ -575,22 +574,8 @@ } ], "metadata": { - "kernelspec": { - "display_name": "nlmod", - "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.4" + "name": "python" } }, "nbformat": 4, diff --git a/docs/examples/07_resampling.ipynb b/docs/examples/07_resampling.ipynb index 7edaeaca..093e046b 100644 --- a/docs/examples/07_resampling.ipynb +++ b/docs/examples/07_resampling.ipynb @@ -224,7 +224,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Rectangular Bivariate Spline (not yet included in nlmod)" + "### Rectangular Bivariate Spline\n", + "\n", + "*Note: not yet included as a method in nlmod*" ] }, { @@ -251,7 +253,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Rectangular Bivariate Spline with nans (not yet included in nlmod)" + "### Rectangular Bivariate Spline with nans\n", + "\n", + "*Note: not yet included as a method in nlmod*" ] }, { diff --git a/docs/examples/08_gis.ipynb b/docs/examples/08_gis.ipynb index 37d56bde..358dee67 100644 --- a/docs/examples/08_gis.ipynb +++ b/docs/examples/08_gis.ipynb @@ -217,7 +217,7 @@ "source": [ "## Export griddata\n", "\n", - "The model data can be exported to a netcdf file that can be visualised in Qgis. For a structured model the standard model dataset (xarray.Dataset) can be exported to a netdf file. For a vertex model you have to convert the model dataset to a certain format before you can write it to a netcdf and read it with Qgis. With the code below we export the vertex model dataset to a netcdf file ('model_qgis.nc') that can be read using Qgis. For more background, see this discussion https://github.com/ArtesiaWater/nlmod/issues/14. " + "The model data can be exported to a netcdf file that can be visualised in Qgis. For a structured model the standard model dataset (xarray.Dataset) can be exported to a netdf file. For a vertex model you have to convert the model dataset to a certain format before you can write it to a netcdf and read it with Qgis. With the code below we export the vertex model dataset to a netcdf file ('model_qgis.nc') that can be read using Qgis." ] }, { diff --git a/docs/examples/09_schoonhoven.ipynb b/docs/examples/09_schoonhoven.ipynb index e07f069c..9e971d09 100644 --- a/docs/examples/09_schoonhoven.ipynb +++ b/docs/examples/09_schoonhoven.ipynb @@ -121,7 +121,7 @@ "norm = matplotlib.colors.Normalize(vmin=-3, vmax=1)\n", "cmap = \"viridis\"\n", "bgt.plot(\"summer_stage\", ax=ax, norm=norm, cmap=cmap)\n", - "nlmod.plot.colorbar_inside(norm=norm, cmap=cmap)" + "nlmod.plot.colorbar_inside(norm=norm, cmap=cmap);" ] }, { @@ -141,7 +141,7 @@ "source": [ "f, ax = nlmod.plot.get_map(extent)\n", "bgt.plot(\"ahn_min\", ax=ax, norm=norm, cmap=cmap)\n", - "nlmod.plot.colorbar_inside(norm=norm, cmap=cmap)" + "nlmod.plot.colorbar_inside(norm=norm, cmap=cmap);" ] }, { @@ -491,13 +491,18 @@ "metadata": {}, "outputs": [], "source": [ - "f, ax = nlmod.plot.get_map(extent)\n", "norm = matplotlib.colors.Normalize(-2.5, 0.0)\n", - "pc = nlmod.plot.data_array(\n", - " head.sel(layer=\"HLc\").mean(\"time\"), ds=ds, edgecolor=\"k\", norm=norm\n", + "\n", + "\n", + "pc = nlmod.plot.map_array(\n", + " head.sel(layer=\"HLc\").mean(\"time\"),\n", + " ds,\n", + " norm=norm,\n", + " colorbar=True,\n", + " colorbar_label=\"head [m NAP]\",\n", + " title=\"mean head\",\n", ")\n", - "cbar = nlmod.plot.colorbar_inside(pc)\n", - "bgt.plot(ax=ax, edgecolor=\"k\", facecolor=\"none\")" + "bgt.plot(ax=ax, edgecolor=\"k\", facecolor=\"none\");" ] }, { @@ -517,14 +522,15 @@ "source": [ "x = 118228.0\n", "line = [(x, 439000), (x, 442000)]\n", + "\n", "f, ax = plt.subplots(figsize=(10, 6))\n", - "ax.grid()\n", "dcs = DatasetCrossSection(ds, line, ax=ax, zmin=-100.0, zmax=10.0)\n", "pc = dcs.plot_array(head.mean(\"time\"), norm=norm, head=head.mean(\"time\"))\n", + "\n", "# add labels with layer names\n", - "cbar = nlmod.plot.colorbar_inside(pc, bounds=[0.05, 0.05, 0.02, 0.9])\n", + "cbar = nlmod.plot.colorbar_inside(pc)\n", "dcs.plot_grid()\n", - "dcs.plot_layers(alpha=0.0, min_label_area=1000)\n", + "dcs.plot_layers(colors=\"none\", min_label_area=1000)\n", "f.tight_layout(pad=0.0)" ] }, @@ -546,7 +552,9 @@ "x = 118228\n", "y = 439870\n", "head_point = nlmod.gwf.get_head_at_point(head, x=x, y=y, ds=ds)\n", - "head_point.plot.line(hue=\"layer\", size=10);" + "fig, ax = plt.subplots(1, 1, figsize=(10, 3))\n", + "handles = head_point.plot.line(ax=ax, hue=\"layer\")\n", + "ax.set_ylabel(\"head [m NAP]\");" ] }, { @@ -659,6 +667,7 @@ "outputs": [], "source": [ "layer = \"HLc\"\n", + "\n", "f, axes = nlmod.plot.get_map(extent, nrows=2, ncols=2)\n", "variables = [\"top\", \"kh\", \"botm\", \"kv\"]\n", "for i, variable in enumerate(variables):\n", @@ -723,7 +732,7 @@ "outputs": [], "source": [ "# run modpath model\n", - "nlmod.modpath.write_and_run(mpf, nb_path=\"10_modpath.ipynb\")" + "nlmod.modpath.write_and_run(mpf, script_path=\"10_modpath.ipynb\")" ] }, { diff --git a/docs/examples/11_grid_rotation.ipynb b/docs/examples/11_grid_rotation.ipynb index de54f199..c58d4c28 100644 --- a/docs/examples/11_grid_rotation.ipynb +++ b/docs/examples/11_grid_rotation.ipynb @@ -146,7 +146,7 @@ "pc = nlmod.plot.data_array(\n", " ds[\"ahn\"], ds=ds, ax=axes[1], rotated=True, norm=norm, edgecolor=\"face\"\n", ")\n", - "nlmod.plot.colorbar_inside(pc, ax=axes[1])" + "nlmod.plot.colorbar_inside(pc, ax=axes[1]);" ] }, { diff --git a/docs/examples/12_layer_generation.ipynb b/docs/examples/12_layer_generation.ipynb index 67c38b08..d11e5ae3 100644 --- a/docs/examples/12_layer_generation.ipynb +++ b/docs/examples/12_layer_generation.ipynb @@ -8,15 +8,15 @@ "# Generating model datasets\n", "\n", "This notebook contains two workflows to generate a model dataset and add layer\n", - "infomration to it:\n", + "information to it:\n", "\n", - "- Get data\n", - "- Regrid\n", + "- Get data (download or read from file)\n", + "- Regrid (convert data to match your desired grid)\n", "\n", "or\n", "\n", - "- Create grid\n", - "- Add data to dataset" + "- Create grid (define your desired grid)\n", + "- Add data to dataset (add data based on this grid)" ] }, { diff --git a/docs/examples/13_plot_methods.ipynb b/docs/examples/13_plot_methods.ipynb index 0b69f2d0..26d3faeb 100644 --- a/docs/examples/13_plot_methods.ipynb +++ b/docs/examples/13_plot_methods.ipynb @@ -7,13 +7,25 @@ "source": [ "# Plot methods in nlmod\n", "\n", - "This notebook shows the plot methods that are available in nlmod. Most plot\n", - "methods use a model Dataset as input, which is an xarray Dataset with some\n", - "required variables and attributes.\n", + "This notebook shows different methods of plotting data with nlmod. \n", "\n", - "There are some plot methods in flopy as well, which require a flopy modelgrid.\n", - "This notebook shows the plot methods in nlmod and flopy create similar plots,\n", - "so the user can choose the methods that best fit their needs." + "There are many ways to plot data and it depends on the type of data and plot which of\n", + "these method is the most convenient:\n", + "- using `nlmod.plot` utilities\n", + "- using `flopy` plot methods\n", + "- using `xarray` plot methods\n", + "\n", + "The default plot methods in nlmod use a model Dataset as input (this is an xarray\n", + "Dataset with some required variables and attributes). These plotting methods are\n", + "accessible through `nlmod.plot`.\n", + "\n", + "Flopy contains its own plotting utilities and nlmod contains some wrapper functions that\n", + "use flopy's plotting utilities under the hood. These require a flopy modelgrid or model\n", + "object. These plotting methods are accessible through `nlmod.plot.flopy`.\n", + "\n", + "Finally, xarray also allows plotting of data with `.plot()`. This is used in a few\n", + "cases in this notebook but for more detailed information, refer to the \n", + "[xarray documentation](https://xarray.pydata.org/en/v2023.08.0/gallery.html)." ] }, { @@ -63,6 +75,7 @@ "model_ws = \"schoonhoven\"\n", "figdir, cachedir = nlmod.util.get_model_dirs(model_ws)\n", "ds = xr.open_dataset(os.path.join(cachedir, f\"{model_name}.nc\"))\n", + "\n", "# add calculated heads\n", "ds[\"head\"] = nlmod.gwf.get_heads_da(ds)\n", "ds" @@ -151,7 +164,7 @@ "# plot using flopy\n", "pcs = flopy.plot.PlotCrossSection(modelgrid=modelgrid, line={\"line\": line}, ax=ax[1])\n", "pcs.plot_array(ds[\"kh\"])\n", - "pcs.ax.set_ylim((zmin, zmax))" + "pcs.ax.set_ylim((zmin, zmax));" ] }, { @@ -173,7 +186,7 @@ "dcs = DatasetCrossSection(ds, line=line, zmin=-200, zmax=10, ax=ax)\n", "colors = nlmod.read.regis.get_legend()\n", "dcs.plot_layers(colors=colors, min_label_area=1000)\n", - "dcs.plot_grid(vertical=False, linewidth=0.5)" + "dcs.plot_grid(vertical=False, linewidth=0.5);" ] }, { diff --git a/docs/examples/14_stromingen_example.ipynb b/docs/examples/14_stromingen_example.ipynb index ee4e32e6..7b825a83 100644 --- a/docs/examples/14_stromingen_example.ipynb +++ b/docs/examples/14_stromingen_example.ipynb @@ -68,7 +68,7 @@ "outputs": [], "source": [ "# where in the world are we?\n", - "nlmod.plot.get_map(extent, background=True);" + "nlmod.plot.get_map(extent, backgroundmap=True);" ] }, { @@ -291,8 +291,12 @@ "outputs": [], "source": [ "# plot on map\n", - "f, ax = nlmod.plot.get_map(extent, background=True)\n", - "nlmod.plot.data_array(head.sel(layer=\"PZWAz3\").mean(dim=\"time\"), ds, alpha=0.25, ax=ax);" + "ax = nlmod.plot.map_array(\n", + " head.sel(layer=\"PZWAz3\").mean(dim=\"time\"),\n", + " ds,\n", + " alpha=0.25,\n", + " backgroundmap=True,\n", + ")" ] }, { @@ -312,9 +316,7 @@ "gxg = nlmod.gwf.calculate_gxg(head.sel(layer=\"HLc\"))\n", "\n", "# plot on map\n", - "f, ax = nlmod.plot.get_map(extent)\n", - "pc = nlmod.plot.data_array(gxg[\"ghg\"], ds)\n", - "nlmod.plot.colorbar_inside(pc);" + "pc = nlmod.plot.map_array(gxg[\"ghg\"], ds)" ] }, { diff --git a/nlmod/cache.py b/nlmod/cache.py index d50569e6..4eebb708 100644 --- a/nlmod/cache.py +++ b/nlmod/cache.py @@ -352,8 +352,8 @@ def _get_modification_time(func): def _update_docstring_and_signature(func): """Add function arguments 'cachedir' and 'cachename' to the docstring and signature - of a function. - + of a function. + The function arguments are added before the "Returns" header in the docstring. If the function has no Returns header in the docstring, the function arguments are not added to the docstring. diff --git a/nlmod/dims/grid.py b/nlmod/dims/grid.py index dad4d96b..6985fa00 100644 --- a/nlmod/dims/grid.py +++ b/nlmod/dims/grid.py @@ -897,7 +897,7 @@ def da_to_reclist( Returns ------- reclist : list of tuples - every row consist of ((layer,icell2d), col1, col2, col3). + every row consists of ((layer, icell2d), col1, col2, col3). """ if "layer" in mask.dims: if only_active_cells: diff --git a/nlmod/gwt/output.py b/nlmod/gwt/output.py index d08f4a40..b7af3d66 100644 --- a/nlmod/gwt/output.py +++ b/nlmod/gwt/output.py @@ -135,6 +135,10 @@ def get_concentration_at_gw_surface(conc, layer="layer"): top_layer = np.take(top_layer, 0, axis=layer) coords["layer"] = (dims, conc_da.layer.data[top_layer]) ctop = xr.DataArray(ctop, dims=dims, coords=coords) + # to not confuse this coordinate with the default layer coord in nlmod + # this source_layer has dims (time, cellid) or (time, y, x) + # indicating the source layer of the concentration value for each time step + ctop = ctop.rename({"layer": "source_layer"}) return ctop diff --git a/nlmod/plot/dcs.py b/nlmod/plot/dcs.py index c7f6ba9e..3ca0cbfc 100644 --- a/nlmod/plot/dcs.py +++ b/nlmod/plot/dcs.py @@ -6,8 +6,8 @@ import xarray as xr from matplotlib.collections import LineCollection, PatchCollection from matplotlib.patches import Rectangle -from shapely.geometry import LineString, MultiLineString, Point, Polygon from shapely.affinity import affine_transform +from shapely.geometry import LineString, MultiLineString, Point, Polygon from ..dims.grid import modelgrid_from_ds from ..dims.resample import get_affine_world_to_mod diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index 86121e41..b0353e76 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -296,8 +296,12 @@ def _get_figure(ax=None, da=None, ds=None, figsize=None, rotated=True): # try to ensure pixel size is divisible by 2 figsize = (figsize[0], np.round(figsize[1] / 0.02, 0) * 0.02) - base = 10 ** int(np.log10(extent[1] - extent[0])) - f, ax = get_map(extent, base=base, figsize=figsize, tight_layout=False) + base = 10 ** int(np.log10(extent[1] - extent[0])) / 2 + if base < 1000: + fmt = "{:.1f}" + else: + fmt = "{:.0f}" + f, ax = get_map(extent, base=base, figsize=figsize, tight_layout=False, fmt=fmt) ax.set_aspect("equal", adjustable="box") return f, ax @@ -336,10 +340,10 @@ def map_array( try: nlay = da["layer"].shape[0] except IndexError: - nlay = 1 # only one layer + nlay = 0 # only one layer except KeyError: nlay = -1 # no dim layer - if nlay > 1: + if nlay >= 1: layer = da["layer"].isel(layer=ilay).item() da = da.isel(layer=ilay) elif nlay < 0: @@ -353,10 +357,14 @@ def map_array( try: nper = da["time"].shape[0] except IndexError: - nper = 1 - if nper > 1: + nper = 0 # only one timestep + except KeyError: + nper = -1 # no dim time + if nper >= 1: t = pd.Timestamp(da["time"].isel(time=iper).item()) da = da.isel(time=iper) + elif nper < 0: + iper = None else: iper = 0 t = pd.Timestamp(ds["time"].item()) diff --git a/nlmod/plot/plotutil.py b/nlmod/plot/plotutil.py index dffb6970..c5462ade 100644 --- a/nlmod/plot/plotutil.py +++ b/nlmod/plot/plotutil.py @@ -84,11 +84,12 @@ def get_map( nrows=1, ncols=1, base=1000.0, + fmt_base=1000.0, fmt="{:.0f}", sharex=False, sharey=True, crs=28992, - background=False, + backgroundmap=False, alpha=0.5, tight_layout=True, ): @@ -106,8 +107,9 @@ def get_map( ncols : int, optional The number of columns. The default is 1. base : float, optional - The interval for ticklabels on the x- and y-axis. The default is 1000. - m. + The interval for ticklabels on the x- and y-axis. The default is 1000 m. + fmt_base : float, optional + divide ticklabels by this number, by default 1000, so units become km. fmt : string, optional The format of the ticks on the x- and y-axis. The default is "{:.0f}". sharex : bool, optional @@ -116,7 +118,7 @@ def get_map( sharey : bool, optional Only display the ticks on the left y-axes, when ncols > 1. The default is True. - background : bool or str, optional + backgroundmap : bool or str, optional Draw a background using contextily when True or when background is a string. When background is a string it repesents the map-provider. Use nlmod.plot._list_contextily_providers().keys() to show possible map-providers. @@ -141,8 +143,8 @@ def get_map( f, axes = plt.subplots( figsize=figsize, nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey ) - if isinstance(background, bool) and background is True: - background = "nlmaps.standaard" + if isinstance(backgroundmap, bool) and backgroundmap is True: + backgroundmap = "nlmaps.standaard" def set_ax_in_map(ax): ax.axis("scaled") @@ -153,8 +155,8 @@ def set_ax_in_map(ax): ax.set_yticks([]) else: rd_ticks(ax, base=base, fmt=fmt) - if background: - add_background_map(ax, crs=crs, map_provider=background, alpha=alpha) + if backgroundmap: + add_background_map(ax, crs=crs, map_provider=backgroundmap, alpha=alpha) if nrows == 1 and ncols == 1: set_ax_in_map(axes) diff --git a/nlmod/read/__init__.py b/nlmod/read/__init__.py index 4b9ed651..0a9e9729 100644 --- a/nlmod/read/__init__.py +++ b/nlmod/read/__init__.py @@ -1,6 +1,7 @@ from . import ( ahn, bgt, + boundaries, brp, geotop, jarkus, @@ -11,7 +12,6 @@ rws, waterboard, webservices, - boundaries, ) from .geotop import get_geotop from .regis import get_regis diff --git a/nlmod/read/boundaries.py b/nlmod/read/boundaries.py index 48e6ade4..a01456db 100644 --- a/nlmod/read/boundaries.py +++ b/nlmod/read/boundaries.py @@ -1,5 +1,4 @@ -from . import webservices -from . import waterboard +from . import waterboard, webservices def get_municipalities(source="cbs", drop_water=True, **kwargs): diff --git a/nlmod/read/jarkus.py b/nlmod/read/jarkus.py index a8c98649..66f319c6 100644 --- a/nlmod/read/jarkus.py +++ b/nlmod/read/jarkus.py @@ -18,7 +18,7 @@ import xarray as xr from .. import cache -from ..dims.resample import fillnan_da, structured_da_to_ds, get_extent +from ..dims.resample import fillnan_da, get_extent, structured_da_to_ds from ..util import get_da_from_da_ds, get_ds_empty logger = logging.getLogger(__name__) @@ -105,7 +105,7 @@ def get_dataset_jarkus(extent, kind="jarkus", return_tiles=False, time=-1): ---------- extent : list, tuple or np.array extent (xmin, xmax, ymin, ymax) of the desired grid. Should be RD-new - coördinates (EPSG:28992) + coordinates (EPSG:28992) kind : str, optional The kind of data. Can be "jarkus", "kusthoogte" or "vaklodingen". The default is "jarkus". @@ -173,7 +173,7 @@ def get_jarkus_tilenames(extent, kind="jarkus"): ---------- extent : list, tuple or np.array extent (xmin, xmax, ymin, ymax) of the desired grid. Should be RD-new - coördinates (EPSG:28992) + coordinates (EPSG:28992) Returns ------- diff --git a/nlmod/sim/sim.py b/nlmod/sim/sim.py index 38233139..b0df986b 100644 --- a/nlmod/sim/sim.py +++ b/nlmod/sim/sim.py @@ -36,7 +36,7 @@ def write_and_run(sim, ds, write_ds=True, script_path=None, silent=False): if True the model dataset is cached to a NetCDF-file (.nc) with a name equal to its attribute called "model_name". The default is True. script_path : str or None, optional - full path of the Jupyter Notebook (.ipynb) or the module (.py) with the + full path of the Jupyter Notebook (.ipynb) or the module (.py) with the modelscript. The default is None. Preferably this path does not have to be given manually but there is currently no good option to obtain the filename of a Jupyter Notebook from within the notebook itself. diff --git a/nlmod/util.py b/nlmod/util.py index 1d95711f..763c6c97 100644 --- a/nlmod/util.py +++ b/nlmod/util.py @@ -82,7 +82,6 @@ def get_exe_path(exe_name="mf6"): return exe_path - def get_ds_empty(ds, keep_coords=None): """Get a copy of a dataset with only coordinate information. diff --git a/tests/test_012_plot.py b/tests/test_012_plot.py index 23d14271..e139ce4c 100644 --- a/tests/test_012_plot.py +++ b/tests/test_012_plot.py @@ -28,4 +28,4 @@ def test_plot_data_array_vertex(): def test_plot_get_map(): - nlmod.plot.get_map([100000, 101000, 400000, 401000], background=True, figsize=3) + nlmod.plot.get_map([100000, 101000, 400000, 401000], backgroundmap=True, figsize=3) From 1cf219a75aa6757d3a60e34974e6f136dd4511d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Fri, 25 Aug 2023 09:56:25 +0200 Subject: [PATCH 2/5] update gwt nb --- docs/examples/16_groundwater_transport.ipynb | 31 ++++++++++++++------ nlmod/read/webservices.py | 9 +++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/examples/16_groundwater_transport.ipynb b/docs/examples/16_groundwater_transport.ipynb index 5903fcac..0cc320ab 100644 --- a/docs/examples/16_groundwater_transport.ipynb +++ b/docs/examples/16_groundwater_transport.ipynb @@ -22,6 +22,7 @@ "source": [ "# import packages\n", "import nlmod\n", + "import pandas as pd\n", "import xarray as xr\n", "import flopy as fp\n", "import matplotlib.pyplot as plt\n", @@ -82,7 +83,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = nlmod.plot.get_map(extent_hbossche, background=\"OpenStreetMap.Mapnik\")" + "fig, ax = nlmod.plot.get_map(extent_hbossche, backgroundmap=\"OpenStreetMap.Mapnik\")" ] }, { @@ -487,7 +488,7 @@ "outputs": [], "source": [ "# plot using flopy\n", - "fig, ax = nlmod.plot.get_map(extent_hbossche, background=\"OpenStreetMap.Mapnik\")\n", + "fig, ax = nlmod.plot.get_map(extent_hbossche, backgroundmap=\"OpenStreetMap.Mapnik\")\n", "pmv = fp.plot.PlotMapView(model=gwf, layer=0, ax=ax)\n", "# pc = pmv.plot_array(c.isel(time=0), cmap=\"Spectral_r\")\n", "pmv.plot_bc(\"GHB\", plotAll=True, alpha=0.1, label=\"GHB\")\n", @@ -532,11 +533,13 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = nlmod.plot.get_map(extent_hbossche)\n", - "nlmod.plot.data_array(ctop.isel(time=-1), ds=ds, ax=ax, cmap=\"Spectral_r\")\n", - "municipalities.plot(edgecolor=\"k\", facecolor=\"none\", ax=ax)\n", - "ax.set_xlabel(\"x [km RD]\")\n", - "ax.set_ylabel(\"y [km RD]\");" + "ax = nlmod.plot.map_array(\n", + " ctop.isel(time=-1),\n", + " ds,\n", + " ilay=0,\n", + " cmap=\"Spectral_r\",\n", + ")\n", + "municipalities.plot(edgecolor=\"k\", facecolor=\"none\", ax=ax)\n" ] }, { @@ -571,7 +574,8 @@ " ax.set_ylim(bottom=-100)\n", " ax.set_xlabel(\"x [m]\")\n", " ax.set_ylabel(\"elevation [m NAP]\")\n", - " ax.set_title(f\"time = {c.time.isel(time=time_idx).values}\");" + " # convert to pandas timestamp for prettier printing\n", + " ax.set_title(f\"time = {pd.Timestamp(c.time.isel(time=time_idx).values)}\");" ] }, { @@ -589,8 +593,17 @@ "outputs": [], "source": [ "hf = nlmod.gwt.output.freshwater_head(ds, h, c)\n", - "hp = nlmod.gwt.output.pointwater_head(ds, hf, c)" + "hp = nlmod.gwt.output.pointwater_head(ds, hf, c)\n", + "\n", + "xr.testing.assert_allclose(h, hp)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/nlmod/read/webservices.py b/nlmod/read/webservices.py index 02d75c88..c18969b0 100644 --- a/nlmod/read/webservices.py +++ b/nlmod/read/webservices.py @@ -28,7 +28,14 @@ def arcrest( timeout=120, **kwargs, ): - """Download data from an arcgis rest FeatureServer.""" + """Download data from an arcgis rest FeatureServer. + + Note + ---- + The sr argument is left as 28992 and not converted to the EPSG_28992 constant + in the epsg28992.py file in nlmod. Data is probably already picked up in 28992, + and projection issue occurs only when converting to this CRS from another CRS. + """ params = { "f": f, "outFields": "*", From 8839d06a276656791818dc7ed44be804ea846237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Fri, 25 Aug 2023 10:01:07 +0200 Subject: [PATCH 3/5] codacy, pass on fmt_base kwarg black formatting --- nlmod/plot/plotutil.py | 2 +- nlmod/read/rws.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nlmod/plot/plotutil.py b/nlmod/plot/plotutil.py index f95b050d..a32fff00 100644 --- a/nlmod/plot/plotutil.py +++ b/nlmod/plot/plotutil.py @@ -154,7 +154,7 @@ def set_ax_in_map(ax): ax.set_xticks([]) ax.set_yticks([]) else: - rd_ticks(ax, base=base, fmt=fmt) + rd_ticks(ax, base=base, fmt=fmt, fmt_base=fmt_base) if backgroundmap: add_background_map(ax, crs=crs, map_provider=backgroundmap, alpha=alpha) diff --git a/nlmod/read/rws.py b/nlmod/read/rws.py index c6e61bcf..a745871f 100644 --- a/nlmod/read/rws.py +++ b/nlmod/read/rws.py @@ -5,8 +5,8 @@ import logging import os -import numpy as np import geopandas as gpd +import numpy as np import xarray as xr import nlmod @@ -212,11 +212,11 @@ def calculate_sea_coverage( When true, dtm-values are connected diagonally as well (to determine the level the sea will reach). The default is False. method : str, optional - The method used to scale the dtm to ds. The default is "mode" (mode means that - if more than half of the (not-nan) cells are wet, the cell is classified as + The method used to scale the dtm to ds. The default is "mode" (mode means that + if more than half of the (not-nan) cells are wet, the cell is classified as sea). nodata : int or float, optional - The value for model cells outside the coverage of the dtm. + The value for model cells outside the coverage of the dtm. Only used internally. The default is -1. return_filled_dtm : bool, optional When True, return the filled dtm. The default is False. From 5d52ce21fae2187d847d78e72dea26879f096feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20Calj=C3=A9?= Date: Fri, 25 Aug 2023 10:27:58 +0200 Subject: [PATCH 4/5] Remove last empty cell again --- docs/examples/16_groundwater_transport.ipynb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/examples/16_groundwater_transport.ipynb b/docs/examples/16_groundwater_transport.ipynb index 0cc320ab..123908c5 100644 --- a/docs/examples/16_groundwater_transport.ipynb +++ b/docs/examples/16_groundwater_transport.ipynb @@ -597,13 +597,6 @@ "\n", "xr.testing.assert_allclose(h, hp)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 4fa08c8005f452d0b2942ca51be47b23ba3a29c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Fri, 25 Aug 2023 10:49:16 +0200 Subject: [PATCH 5/5] rename backgroundmap to background everywhere --- docs/examples/14_stromingen_example.ipynb | 12 +++++++++--- docs/examples/16_groundwater_transport.ipynb | 4 ++-- nlmod/plot/flopy.py | 16 ++++++++-------- nlmod/plot/plot.py | 10 +++++----- nlmod/plot/plotutil.py | 16 ++++++++-------- tests/test_012_plot.py | 2 +- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/docs/examples/14_stromingen_example.ipynb b/docs/examples/14_stromingen_example.ipynb index 7b825a83..b7098431 100644 --- a/docs/examples/14_stromingen_example.ipynb +++ b/docs/examples/14_stromingen_example.ipynb @@ -68,7 +68,7 @@ "outputs": [], "source": [ "# where in the world are we?\n", - "nlmod.plot.get_map(extent, backgroundmap=True);" + "nlmod.plot.get_map(extent, background=True);" ] }, { @@ -295,7 +295,7 @@ " head.sel(layer=\"PZWAz3\").mean(dim=\"time\"),\n", " ds,\n", " alpha=0.25,\n", - " backgroundmap=True,\n", + " background=True,\n", ")" ] }, @@ -330,8 +330,14 @@ } ], "metadata": { + "kernelspec": { + "display_name": "artesia", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "name": "python", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/docs/examples/16_groundwater_transport.ipynb b/docs/examples/16_groundwater_transport.ipynb index 123908c5..e3828855 100644 --- a/docs/examples/16_groundwater_transport.ipynb +++ b/docs/examples/16_groundwater_transport.ipynb @@ -83,7 +83,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = nlmod.plot.get_map(extent_hbossche, backgroundmap=\"OpenStreetMap.Mapnik\")" + "fig, ax = nlmod.plot.get_map(extent_hbossche, background=\"OpenStreetMap.Mapnik\")" ] }, { @@ -488,7 +488,7 @@ "outputs": [], "source": [ "# plot using flopy\n", - "fig, ax = nlmod.plot.get_map(extent_hbossche, backgroundmap=\"OpenStreetMap.Mapnik\")\n", + "fig, ax = nlmod.plot.get_map(extent_hbossche, background=\"OpenStreetMap.Mapnik\")\n", "pmv = fp.plot.PlotMapView(model=gwf, layer=0, ax=ax)\n", "# pc = pmv.plot_array(c.isel(time=0), cmap=\"Spectral_r\")\n", "pmv.plot_bc(\"GHB\", plotAll=True, alpha=0.1, label=\"GHB\")\n", diff --git a/nlmod/plot/flopy.py b/nlmod/plot/flopy.py index b3934734..a3ad93f2 100644 --- a/nlmod/plot/flopy.py +++ b/nlmod/plot/flopy.py @@ -51,7 +51,7 @@ def map_array( colorbar_label="", plot_grid=False, add_to_plot=None, - backgroundmap=False, + background=False, figsize=None, animate=False, ): @@ -96,7 +96,7 @@ def map_array( tuple or list of plotting functions that take ax as the only argument, by default None. Use to add features to plot, e.g. plotting shapefiles, or other data. - backgroundmap : bool, optional + background : bool, optional add background map, by default False figsize : tuple, optional figure size, by default None @@ -135,7 +135,7 @@ def map_array( qm = pmv.plot_array(arr, cmap=cmap, norm=norm, alpha=alpha) # bgmap - if backgroundmap: + if background: add_background_map(ax, map_provider="nlmaps.water", alpha=0.5) # add other info to plot @@ -183,7 +183,7 @@ def contour_array( label_kwargs=None, plot_grid=False, add_to_plot=None, - backgroundmap=False, + background=False, figsize=None, animate=False, **kwargs, @@ -226,7 +226,7 @@ def contour_array( tuple or list of plotting functions that take ax as the only argument, by default None. Use to add features to plot, e.g. plotting shapefiles, or other data. - backgroundmap : bool, optional + background : bool, optional add background map, by default False figsize : tuple, optional figure size, by default None @@ -265,7 +265,7 @@ def contour_array( ax.clabel(cs, **label_kwargs) # bgmap - if backgroundmap: + if background: add_background_map(ax, map_provider="nlmaps.water", alpha=0.5) # add other info to plot @@ -309,7 +309,7 @@ def animate_map( colorbar_label="", plot_grid=True, add_to_plot=None, - backgroundmap=False, + background=False, figsize=(9.24, 10.042), save=False, fname=None, @@ -347,7 +347,7 @@ def animate_map( colorbar_label=colorbar_label, plot_grid=plot_grid, add_to_plot=add_to_plot, - backgroundmap=backgroundmap, + background=background, figsize=figsize, animate=True, ) diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index b0353e76..9af3acb9 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -328,7 +328,7 @@ def map_array( plot_grid=True, rotated=True, add_to_plot=None, - backgroundmap=False, + background=False, figsize=None, animate=False, ): @@ -387,7 +387,7 @@ def map_array( ax.axis(extent) # bgmap - if backgroundmap: + if background: add_background_map(ax, map_provider="nlmaps.water", alpha=0.5) # add other info to plot @@ -444,7 +444,7 @@ def animate_map( colorbar_label="", plot_grid=True, rotated=True, - backgroundmap=False, + background=False, figsize=None, ax=None, add_to_plot=None, @@ -491,7 +491,7 @@ def animate_map( Whether to plot the model grid. Default is True. rotated : bool, optional Whether to plot rotated model, if applicable. Default is True. - backgroundmap : bool, optional + background : bool, optional Whether to add a background map. Default is False. figsize : tuple, optional figure size in inches, default is None. @@ -553,7 +553,7 @@ def animate_map( plot_grid=plot_grid, rotated=rotated, add_to_plot=add_to_plot, - backgroundmap=backgroundmap, + background=background, figsize=figsize, animate=True, ) diff --git a/nlmod/plot/plotutil.py b/nlmod/plot/plotutil.py index a32fff00..47778ab4 100644 --- a/nlmod/plot/plotutil.py +++ b/nlmod/plot/plotutil.py @@ -89,7 +89,7 @@ def get_map( sharex=False, sharey=True, crs=28992, - backgroundmap=False, + background=False, alpha=0.5, tight_layout=True, ): @@ -118,11 +118,11 @@ def get_map( sharey : bool, optional Only display the ticks on the left y-axes, when ncols > 1. The default is True. - backgroundmap : bool or str, optional - Draw a background using contextily when True or when background is a string. + background : bool or str, optional + Draw a background map using contextily when True or when background is a string. When background is a string it repesents the map-provider. Use nlmod.plot._list_contextily_providers().keys() to show possible map-providers. - THe defaults is False. + The defaults is False. alpha: float, optional The alpha value of the background. The default is 0.5. tight_layout : bool, optional @@ -143,8 +143,8 @@ def get_map( f, axes = plt.subplots( figsize=figsize, nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey ) - if isinstance(backgroundmap, bool) and backgroundmap is True: - backgroundmap = "nlmaps.standaard" + if isinstance(background, bool) and background is True: + background = "nlmaps.standaard" def set_ax_in_map(ax): ax.axis("scaled") @@ -155,8 +155,8 @@ def set_ax_in_map(ax): ax.set_yticks([]) else: rd_ticks(ax, base=base, fmt=fmt, fmt_base=fmt_base) - if backgroundmap: - add_background_map(ax, crs=crs, map_provider=backgroundmap, alpha=alpha) + if background: + add_background_map(ax, crs=crs, map_provider=background, alpha=alpha) if nrows == 1 and ncols == 1: set_ax_in_map(axes) diff --git a/tests/test_012_plot.py b/tests/test_012_plot.py index e139ce4c..23d14271 100644 --- a/tests/test_012_plot.py +++ b/tests/test_012_plot.py @@ -28,4 +28,4 @@ def test_plot_data_array_vertex(): def test_plot_get_map(): - nlmod.plot.get_map([100000, 101000, 400000, 401000], backgroundmap=True, figsize=3) + nlmod.plot.get_map([100000, 101000, 400000, 401000], background=True, figsize=3)