Skip to content

Commit

Permalink
update some notebooks and documentation for imshow
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed May 25, 2022
1 parent fccc3d5 commit 9567548
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 152 deletions.
7 changes: 3 additions & 4 deletions notebooks/tutorials/boundary_conds/set_BCs_from_xy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"source": [
"from landlab import RasterModelGrid\n",
"import numpy as np\n",
"from landlab.plot.imshow import imshow_grid_at_node\n",
"from matplotlib.pyplot import show\n",
"\n",
"%matplotlib inline"
Expand Down Expand Up @@ -118,7 +117,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid_at_node(mg, z)"
"mg.imshow(z, at=\"node\")"
]
},
{
Expand All @@ -131,7 +130,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -145,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
"outputs": [],
"source": [
"from landlab import RasterModelGrid\n",
"from landlab.plot.imshow import imshow_grid\n",
"import numpy as np\n",
"\n",
"%matplotlib inline"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -90,7 +87,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(mg, mg.status_at_node)"
"mg.imshow(mg.status_at_node)"
]
},
{
Expand All @@ -99,7 +96,7 @@
"source": [
"Now let's choose one node on the perimeter to be closed. \n",
"\n",
"Note that `imshow_grid` by default does not illustrate values for closed nodes, so we override that below and show them in blue."
"Note that `imshow` by default does not illustrate values for closed nodes, so we override that below and show them in blue."
]
},
{
Expand All @@ -109,7 +106,7 @@
"outputs": [],
"source": [
"mg.status_at_node[2] = mg.BC_NODE_IS_CLOSED\n",
"imshow_grid(mg, mg.status_at_node, color_for_closed=\"blue\")"
"mg.imshow(mg.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand Down Expand Up @@ -141,7 +138,7 @@
")\n",
"# the same thing could be done as ...\n",
"# mg.set_status_at_node_on_edges(right=4, top=1, left=4, bottom=1)\n",
"imshow_grid(mg, mg.status_at_node, color_for_closed=\"blue\")"
"mg.imshow(mg.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand All @@ -166,7 +163,7 @@
"source": [
"mg1 = RasterModelGrid((4, 4), 1.0)\n",
"mg1.set_closed_boundaries_at_grid_edges(True, False, True, False)\n",
"imshow_grid(mg1, mg1.status_at_node, color_for_closed=\"blue\")"
"mg1.imshow(mg1.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand All @@ -188,7 +185,7 @@
"source": [
"mg2 = RasterModelGrid((4, 4), 1.0)\n",
"mg2.set_looped_boundaries(True, False)\n",
"imshow_grid(mg2, mg2.status_at_node)"
"mg2.imshow(mg2.status_at_node)"
]
},
{
Expand All @@ -207,7 +204,7 @@
"outputs": [],
"source": [
"mg2.set_closed_boundaries_at_grid_edges(True, False, True, False)\n",
"imshow_grid(mg2, mg2.status_at_node, color_for_closed=\"Blue\")"
"mg2.imshow(mg2.status_at_node, color_for_closed=\"Blue\")"
]
},
{
Expand All @@ -229,7 +226,7 @@
"mg3 = RasterModelGrid((4, 4), 1.0)\n",
"mg3.status_at_node[mg3.y_of_node == 0] = mg.BC_NODE_IS_FIXED_GRADIENT\n",
"mg3.status_at_node[mg3.y_of_node == 3] = mg.BC_NODE_IS_FIXED_GRADIENT\n",
"imshow_grid(mg3, mg3.status_at_node, color_for_closed=\"Blue\")\n",
"mg3.imshow(mg3.status_at_node, color_for_closed=\"Blue\")\n",
"# there are no closed boundaries so we didn't need the color_for_closed option,\n",
"# but no problem if you accidentally include it!"
]
Expand All @@ -244,7 +241,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -258,7 +255,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
21 changes: 8 additions & 13 deletions notebooks/tutorials/boundary_conds/set_BCs_on_voronoi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
"outputs": [],
"source": [
"from landlab import VoronoiDelaunayGrid\n",
"from landlab.plot.imshow import imshow_grid\n",
"import numpy as np\n",
"\n",
"%matplotlib inline"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -92,7 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(vg, vg.status_at_node, cmap=\"cool\", show_elements=True)"
"vg.imshow(vg.status_at_node, cmap=\"cool\", show_elements=True)"
]
},
{
Expand All @@ -113,8 +110,7 @@
"vg.status_at_node[\n",
" vg.status_at_node == vg.BC_NODE_IS_FIXED_GRADIENT\n",
"] = vg.BC_NODE_IS_CLOSED\n",
"imshow_grid(\n",
" vg,\n",
"vg.imshow(\n",
" vg.status_at_node,\n",
" cmap=\"cool\",\n",
" limits=(-0.01, 4),\n",
Expand Down Expand Up @@ -159,15 +155,15 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(vg2, vg2.at_node[\"topographic__elevation\"], cmap=\"cool\", show_elements=True)\n",
"vg2.imshow(vg2.at_node[\"topographic__elevation\"], cmap=\"cool\", show_elements=True)\n",
"vg2.at_node[\"topographic__elevation\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can illustrate the grid and see at least some of the closed elements by using the imshow_grid option color_for_closed. Again remember that some of the nodes that are plotting in white areas are closed as well - that is, the ones that have an x value less than 0.5 are closed."
"Now we can illustrate the grid and see at least some of the closed elements by using the `imshow` option color_for_closed. Again remember that some of the nodes that are plotting in white areas are closed as well - that is, the ones that have an x value less than 0.5 are closed."
]
},
{
Expand All @@ -177,8 +173,7 @@
"outputs": [],
"source": [
"vg2.set_nodata_nodes_to_closed(vg2.at_node[\"topographic__elevation\"], -1.0)\n",
"imshow_grid(\n",
" vg2,\n",
"vg2.imshow(\n",
" vg2.status_at_node,\n",
" color_for_closed=\"red\",\n",
" cmap=\"cool\",\n",
Expand All @@ -205,7 +200,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -219,7 +214,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
25 changes: 11 additions & 14 deletions notebooks/tutorials/boundary_conds/set_watershed_BCs_raster.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
"outputs": [],
"source": [
"from landlab import RasterModelGrid\n",
"import numpy as np\n",
"from landlab.plot.imshow import imshow_grid\n",
"\n",
"%matplotlib inline"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -88,7 +85,7 @@
"metadata": {},
"source": [
"- Check to see that node status were set correctly.\n",
"- imshow_grid will default to not plot the value of BC_NODE_IS_CLOSED nodes, which is why we override this below with the option color_for_closed"
"- `imshow` will default to not plot the value of BC_NODE_IS_CLOSED nodes, which is why we override this below with the option color_for_closed"
]
},
{
Expand All @@ -97,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(mg1, mg1.status_at_node, color_for_closed=\"blue\")"
"mg1.imshow(mg1.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand Down Expand Up @@ -152,7 +149,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(mg2, mg2.status_at_node, color_for_closed=\"blue\")"
"mg2.imshow(mg2.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand Down Expand Up @@ -206,7 +203,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(mg3, mg3.status_at_node, color_for_closed=\"blue\")"
"mg3.imshow(mg3.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand Down Expand Up @@ -243,7 +240,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid_bijou, z_bijou)"
"grid_bijou.imshow(z_bijou)"
]
},
{
Expand Down Expand Up @@ -276,7 +273,7 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid_bijou, grid_bijou.status_at_node, color_for_closed=\"blue\")"
"grid_bijou.imshow(grid_bijou.status_at_node, color_for_closed=\"blue\")"
]
},
{
Expand All @@ -285,7 +282,7 @@
"source": [
"- This looks sensible.\n",
"- Now that the boundary conditions ae set, we can also look at the topography. \n",
"- imshow_grid will default to show boundaries as black, as illustrated below. But that can be overwridden as we have been doing all along."
"- `imshow` will default to show boundaries as black, as illustrated below. But that can be overwridden as we have been doing all along."
]
},
{
Expand All @@ -294,13 +291,13 @@
"metadata": {},
"outputs": [],
"source": [
"imshow_grid(grid_bijou, z_bijou)"
"grid_bijou.imshow(z_bijou)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -314,7 +311,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,16 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from landlab.plot import imshow_grid\n",
"import matplotlib as mpl\n",
"\n",
"cmap = mpl.colors.ListedColormap([\"green\", \"red\", \"black\", \"white\", \"red\", \"black\"])\n",
"bounds = [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]\n",
"norm = mpl.colors.BoundaryNorm(bounds, cmap.N)\n",
"description = \"green: grass; red: shrub; black: tree; white: bare\"\n",
"plt.figure(101)\n",
"imshow_grid(\n",
" grid,\n",
"grid.imshow(\n",
" \"vegetation__plant_functional_type\",\n",
" values_at=\"cell\",\n",
" at=\"cell\",\n",
" cmap=cmap,\n",
" grid_units=(\"m\", \"m\"),\n",
" norm=norm,\n",
Expand Down Expand Up @@ -491,7 +489,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -505,7 +503,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,16 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from landlab.plot import imshow_grid\n",
"import matplotlib as mpl\n",
"\n",
"cmap = mpl.colors.ListedColormap([\"green\", \"red\", \"black\", \"white\", \"red\", \"black\"])\n",
"bounds = [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]\n",
"norm = mpl.colors.BoundaryNorm(bounds, cmap.N)\n",
"description = \"green: grass; red: shrub; black: tree; white: bare\"\n",
"plt.figure(101)\n",
"imshow_grid(\n",
" grid1,\n",
"grid1.imshow(\n",
" \"vegetation__plant_functional_type\",\n",
" values_at=\"cell\",\n",
" at=\"cell\",\n",
" cmap=cmap,\n",
" grid_units=(\"m\", \"m\"),\n",
" norm=norm,\n",
Expand Down Expand Up @@ -494,7 +492,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -508,7 +506,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 9567548

Please sign in to comment.