Skip to content

Commit

Permalink
update landlab notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Mar 7, 2023
1 parent 6197062 commit 8711181
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 852 deletions.
106 changes: 40 additions & 66 deletions lessons/landlab/landlab/bedrock_landslides_on_dems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,12 @@
"metadata": {},
"outputs": [],
"source": [
"import sys, time, os\n",
"from pathlib import Path\n",
"import copy\n",
"import numpy as np\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from landlab.components import (\n",
" FlowAccumulator,\n",
" PriorityFloodFlowRouter,\n",
" ChannelProfiler,\n",
" BedrockLandslider,\n",
")\n",
"from landlab.io.netcdf import read_netcdf\n",
"from landlab.utils import get_watershed_mask\n",
"from landlab import imshowhs_grid, imshow_grid\n",
"from landlab.io import read_esri_ascii, write_esri_ascii\n",
"from landlab import RasterModelGrid\n",
"\n",
"from bmi_topography import Topography"
"import numpy as np\n",
"from bmi_topography import Topography\n",
"from landlab import RasterModelGrid, imshow_grid, imshowhs_grid\n",
"from landlab.components import BedrockLandslider, PriorityFloodFlowRouter\n",
"from landlab.io import read_esri_ascii"
]
},
{
Expand Down Expand Up @@ -194,19 +180,15 @@
"metadata": {},
"outputs": [],
"source": [
"# Read DEM as Lanlab grid\n",
"# Read DEM as Landlab grid\n",
"grid_geog, elev = read_esri_ascii(fname, name=\"topographic__elevation\")\n",
"# Show dem\n",
"plt.figure()\n",
"cmap = copy.copy(mpl.cm.get_cmap(\"terrain\"))\n",
"imshow_grid(\n",
" grid_geog,\n",
"\n",
"grid_geog.imshow(\n",
" \"topographic__elevation\",\n",
" cmap=cmap,\n",
" cmap=\"terrain\",\n",
" grid_units=(\"deg\", \"deg\"),\n",
" colorbar_label=\"Elevation (m)\",\n",
")\n",
"plt.show()"
")"
]
},
{
Expand Down Expand Up @@ -245,9 +227,8 @@
"outputs": [],
"source": [
"# make a new grid with RasterModelGrid, use the dimensions of grid_geog\n",
"\n",
"# grid =\n",
"# grid.add_field(..."
"grid = RasterModelGrid(grid_geog.shape, xy_spacing=30.0)\n",
"grid.at_node[\"topographic__elevation\"] = grid_geog.at_node[\"topographic__elevation\"]"
]
},
{
Expand All @@ -257,7 +238,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Plot this one with imshowhs_grid"
"# Plot this one with imshowhs_grid\n",
"imshowhs_grid(grid, \"topographic__elevation\")"
]
},
{
Expand All @@ -272,7 +254,6 @@
" grid, topo=True, DA=True, hill_DA=False, flow_metric=\"D8\", hill_flow_metric=\"Quinn\"\n",
"):\n",
" if topo:\n",
" cmap = copy.copy(mpl.cm.get_cmap(\"terrain\"))\n",
" azdeg = 200\n",
" altdeg = 20\n",
" ve = 1\n",
Expand All @@ -283,7 +264,7 @@
" \"topographic__elevation\",\n",
" grid_units=(\"deg\", \"deg\"),\n",
" var_name=\"Topo, m\",\n",
" cmap=cmap,\n",
" cmap=\"terrain\",\n",
" plot_type=plot_type,\n",
" vertical_exa=ve,\n",
" azdeg=azdeg,\n",
Expand All @@ -309,13 +290,11 @@
" drape1 = plot_DA\n",
" thres_drape1 = None\n",
" alpha = 0.5\n",
" myfile1 = \"temperature.cpt\"\n",
" cmap1 = copy.copy(mpl.cm.get_cmap(\"terrain\"))\n",
" ax = imshowhs_grid(\n",
" grid,\n",
" \"topographic__elevation\",\n",
" grid_units=(\"deg\", \"deg\"),\n",
" cmap=cmap1,\n",
" cmap=\"terrain\",\n",
" plot_type=plot_type,\n",
" drape1=drape1,\n",
" vertical_exa=ve,\n",
Expand Down Expand Up @@ -351,7 +330,7 @@
" grid.at_node[\"hill_drainage_area\"][grid.at_node[\"hill_drainage_area\"] == 0] = (\n",
" grid.dx * grid.dx\n",
" )\n",
" plotDA = np.log10(grid.at_node[\"hill_drainage_area\"] * 111e3 * 111e3)\n",
" # plotDA = np.log10(grid.at_node[\"hill_drainage_area\"] * 111e3 * 111e3)\n",
" # plt.figure()\n",
" # imshow_grid(grid, plotDA,grid_units=(\"m\", \"m\"), var_name=\"Elevation (m)\", cmap='terrain')\n",
"\n",
Expand All @@ -361,13 +340,11 @@
" drape1 = np.log10(grid.at_node[\"hill_drainage_area\"])\n",
" thres_drape1 = None\n",
" alpha = 0.5\n",
" myfile1 = \"temperature.cpt\"\n",
" cmap1 = copy.copy(mpl.cm.get_cmap(\"terrain\"))\n",
" ax = imshowhs_grid(\n",
" grid,\n",
" \"topographic__elevation\",\n",
" grid_units=(\"deg\", \"deg\"),\n",
" cmap=cmap1,\n",
" cmap=\"terrain\",\n",
" plot_type=plot_type,\n",
" drape1=drape1,\n",
" vertical_exa=ve,\n",
Expand Down Expand Up @@ -460,7 +437,7 @@
"metadata": {},
"outputs": [],
"source": [
"_ = grid.add_zeros(\"soil__depth\", at=\"node\")"
"grid.add_zeros(\"soil__depth\", at=\"node\")"
]
},
{
Expand Down Expand Up @@ -495,7 +472,6 @@
"metadata": {},
"outputs": [],
"source": [
"plt.figure()\n",
"LS_size = np.array(ls.landslides_size) * grid.dx**2\n",
"counts, bins = np.histogram(np.log10(LS_size), 8)\n",
"plt.hist(np.log10(LS_size), log=True, bins=bins, density=True)\n",
Expand Down Expand Up @@ -524,29 +500,33 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e6d6b71c",
"id": "9d7a51ac",
"metadata": {},
"outputs": [],
"source": [
"# Landslide Erosion\n",
"cmap = copy.copy(mpl.cm.get_cmap(\"hot_r\"))\n",
"imshow_grid(\n",
" grid,\n",
" np.sqrt(grid.at_node[\"landslide__erosion\"]),\n",
" colorbar_label=\"SQRT( Landslide erosion, m) \",\n",
" cmap=cmap,\n",
")\n",
"plt.show()\n",
"\n",
" cmap=\"hot_r\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6d6b71c",
"metadata": {},
"outputs": [],
"source": [
"# Landslide Deposition\n",
"cmap = copy.copy(mpl.cm.get_cmap(\"winter_r\"))\n",
"imshow_grid(\n",
" grid,\n",
" np.sqrt(grid.at_node[\"landslide__deposition\"]),\n",
" colorbar_label=\"SQRT( Landslide deposition, m) \",\n",
" cmap=cmap,\n",
")\n",
"plt.show()"
" cmap=\"winter_r\",\n",
")"
]
},
{
Expand All @@ -557,7 +537,6 @@
"outputs": [],
"source": [
"# Show Landslide Erosion draped over the shaded topographic relief\n",
"cmap1 = copy.copy(mpl.cm.get_cmap(\"hot_r\"))\n",
"imshowhs_grid(\n",
" grid,\n",
" \"topographic__elevation\",\n",
Expand All @@ -566,15 +545,14 @@
" var_name=\"LS \\n erosion\",\n",
" var_units=r\"m\",\n",
" grid_units=(\"m\", \"m\"),\n",
" cmap=cmap1,\n",
" cmap=\"hot_r\",\n",
" ticks_km=False,\n",
" colorbar_label_y=-55,\n",
" add_label_bbox=True,\n",
" thres_drape1=0.01,\n",
")\n",
"plt.show()\n",
"# Show Landslide deposition draped over the shaded topographic relief\n",
"cmap1 = copy.copy(mpl.cm.get_cmap(\"winter_r\"))\n",
"imshowhs_grid(\n",
" grid,\n",
" \"topographic__elevation\",\n",
Expand All @@ -583,7 +561,7 @@
" var_name=\"LS \\n deposition\",\n",
" var_units=r\"m\",\n",
" grid_units=(\"m\", \"m\"),\n",
" cmap=cmap1,\n",
" cmap=\"winter_r\",\n",
" ticks_km=False,\n",
" colorbar_label_y=-55,\n",
" add_label_bbox=True,\n",
Expand All @@ -600,36 +578,32 @@
"outputs": [],
"source": [
"# Show Landslide erosion and deposition draped over the shaded topographic relief\n",
"cmap1 = copy.copy(mpl.cm.get_cmap(\"Blues\"))\n",
"thres_drape1 = 0.01\n",
"thres_drape2 = 0.01\n",
"alpha = 0.8\n",
"alpha2 = 0.8\n",
"drape1 = np.sqrt(grid.at_node[\"landslide__erosion\"])\n",
"drape2 = np.sqrt(grid.at_node[\"landslide__deposition\"])\n",
"cmap1 = copy.copy(mpl.cm.get_cmap(\"hot_r\"))\n",
"cmap2 = copy.copy(mpl.cm.get_cmap(\"winter_r\"))\n",
"plt.figure(figsize=(15, 15))\n",
"\n",
"imshowhs_grid(\n",
" grid,\n",
" \"topographic__elevation\",\n",
" plot_type=\"Drape2\",\n",
" drape1=drape1,\n",
" cmap=cmap1,\n",
" cmap=\"hot_r\",\n",
" thres_drape1=thres_drape1,\n",
" alpha=alpha,\n",
" drape2=drape2,\n",
" cmap2=cmap2,\n",
" cmap2=\"winter_r\",\n",
" thres_drape2=thres_drape2,\n",
" alpha2=alpha2,\n",
" add_double_colorbar=True,\n",
" cbar_tick_size=8,\n",
" cbar_label_color=\"red\",\n",
" cbar_label_fontweight=\"normal\",\n",
" add_label_bbox=True,\n",
")\n",
"\n",
"plt.show()"
")"
]
},
{
Expand Down Expand Up @@ -668,7 +642,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
36 changes: 23 additions & 13 deletions lessons/landlab/landlab/fault-scarp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"%matplotlib inline"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -156,8 +154,13 @@
"\n",
"In Part 3 we will use the HexagonalModelGrid. \n",
"\n",
"In Part 4 we will use the LinearDiffuser component. \n",
"\n",
"In Part 4 we will use the LinearDiffuser component. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 2: 2D version using Landlab's Model Grids\n",
"\n",
"The Landlab model grids are data structures that represent the model domain (the variable `x` in our prior example). Here we will use `RasterModelGrid` which creates a grid with regularly spaced square grid elements. The RasterModelGrid knows how the elements are connected and how far apart they are.\n",
Expand Down Expand Up @@ -251,7 +254,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### *Exercises for section 2a*\n",
"#### Exercises for section 2a\n",
"\n",
"(2a.1) Create an instance of a `RasterModelGrid` with 5 rows and 7 columns, with a spacing between nodes of 10 units. Plot the node layout, and identify the ID number of the center-most node."
]
Expand Down Expand Up @@ -560,7 +563,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### *Exercises for section 2b*\n",
"#### Exercises for section 2b\n",
"\n",
"(2b .1) Create an instance of a `RasterModelGrid` called `mygrid`, with 16 rows and 25 columns, with a spacing between nodes of 5 meters. Use the `plot` function in the `matplotlib` library to make a plot that shows the position of each node marked with a dot (hint: see the plt.plot() example above)."
]
Expand Down Expand Up @@ -752,7 +755,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### *Exercises for section 2c*\n",
"#### Exercises for section 2c\n",
"\n",
"(2c.1) Make a 3x3 `RasterModelGrid` called `tinygrid`, with a cell spacing of 2 m. Use the `plot_graph` function to display the nodes and their ID numbers."
]
Expand Down Expand Up @@ -937,7 +940,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### *Exercises for section 3*\n",
"#### Exercises for section 3\n",
"\n",
"(3.1-6) Repeat the exercises from section 2c, but this time using a hexagonal tiny grid called `tinyhex`. Your grid should have 7 nodes: one core node and 6 perimeter nodes. (Hints: use `node_layout = 'hex'`, and make a grid with 3 rows and 2 base-row columns.)"
]
Expand Down Expand Up @@ -1085,7 +1088,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### *Exercises for section 4*\n",
"### Exercises for section 4\n",
"\n",
"(4.1) Repeat the steps above that instantiate and run a `LinearDiffuser` component, but this time give it a `RasterModelGrid`. Use `imshow_grid` to display the topography below."
]
Expand Down Expand Up @@ -1167,7 +1170,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### *SOLUTION (derivation)*\n",
"#### SOLUTION (derivation)\n",
"\n",
"##### Derivation of the original governing equation\n",
"\n",
Expand Down Expand Up @@ -1302,8 +1305,15 @@
"source": [
"Congratulations on making it to the end of this tutorial!\n",
"\n",
"### Click here for more <a href=\"https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html\">Landlab tutorials</a>"
"**Click here for more** <a href=\"https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html\">Landlab tutorials</a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -1323,7 +1333,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8711181

Please sign in to comment.