Skip to content

Commit

Permalink
Updated notebooks 2024-02-14 UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 14, 2024
1 parent 1d321f0 commit 6d39152
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 7 deletions.
64 changes: 64 additions & 0 deletions content/notebooks/49_split_control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"outputs": [],
"source": [
"import folium\n",
"import rioxarray\n",
"import xarray as xr\n",
"import leafmap.foliumap as leafmap"
]
},
Expand Down Expand Up @@ -129,6 +131,68 @@
"m.split_map(left_layer, right_layer)\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Using xarrays**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download a sample dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://open.gishub.org/data/raster/srtm90.tif\"\n",
"dem = leafmap.download_file(url, \"srtm90.tif\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use rioxarray to read the raster as a xarray DataArray and then classify the DEM into 2 elevation classes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dem_ds = rioxarray.open_rasterio(dem)\n",
"dem_class = xr.where(dem_ds<2000, 0, 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize the DEM and the elevation class image as a split map."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[37.6,-119], zoom=9)\n",
"m.split_map(dem_ds, dem_class,\n",
" left_args={\"layer_name\":\"DEM\", \"colormap\": \"terrain\"},\n",
" right_args={\"layer_name\":\"Classified DEM\",\"colormap\": \"coolwarm\"}\n",
" )\n",
"m"
]
}
],
"metadata": {
Expand Down
29 changes: 22 additions & 7 deletions content/notebooks/89_image_array_viz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@
"outputs": [],
"source": [
"transform = (30.0, 0.0, -13651650.0, 0.0, -30.0, 4576290.0)\n",
"ndvi_image = leafmap.array_to_image(ndvi, cellsize=30, crs=\"EPSG:3857\", transform=transform)"
"ndvi_image = leafmap.array_to_image(\n",
" ndvi, cellsize=30, crs=\"EPSG:3857\", transform=transform\n",
")"
]
},
{
Expand Down Expand Up @@ -232,7 +234,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Create an in-memory raster dataset from the elevation class array and use the projection and extent of the DEM."
"Visualize the DEM and the elevation class image on the same map."
]
},
{
Expand All @@ -241,14 +243,17 @@
"metadata": {},
"outputs": [],
"source": [
"image = leafmap.array_to_image(masked_array, source=dem)"
"m = leafmap.Map()\n",
"m.add_raster(dem, colormap=\"terrain\", layer_name=\"DEM\")\n",
"m.add_raster(masked_array, colormap=\"coolwarm\", layer_name=\"Classified DEM\")\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize the DEM and the elevation class image on the same map."
"Add a split map."
]
},
{
Expand All @@ -257,9 +262,19 @@
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_raster(dem, colormap=\"terrain\", layer_name=\"DEM\")\n",
"m.add_raster(image, colormap=\"coolwarm\", layer_name=\"Classified DEM\")\n",
"m = leafmap.Map(center=[37.6, -119], zoom=9)\n",
"m.split_map(\n",
" dem,\n",
" masked_array,\n",
" left_args={\n",
" \"layer_name\": \"DEM\",\n",
" \"colormap\": \"terrain\",\n",
" },\n",
" right_args={\n",
" \"layer_name\": \"Classified DEM\",\n",
" \"colormap\": \"coolwarm\",\n",
" },\n",
")\n",
"m"
]
}
Expand Down

0 comments on commit 6d39152

Please sign in to comment.