{
"cells": [
{
"cell_type": "markdown",
"id": "c479317b-62b4-4310-8273-258285511739",
"metadata": {
"id": "c479317b-62b4-4310-8273-258285511739"
},
"source": [
"\n",
"\n",
"\n",
"\n",
"# Sensing the Earth II \n",
"## 11/18/22 - Haskell Indian Nations University\n",
"### Nate Quarderer ([ESIIL](https://esiil.org/)/[Earth Lab](https://earthlab.colorado.edu)/[CIRES](https://cires.colorado.edu)/[CU Boulder](https://www.colorado.edu))\n",
"\n",
"![Colored Bar](https://drive.google.com/uc?export=view&id=1WL0ur5SQc5ijCvXc6MvWUeoWOIVS_rQ9)\n",
"\n",
"\n",
"# Introduction to GIS in Open Source Python\n",
"Opening and plotting spatial data\n",
"\n",
"* Vector data (shapefiles, .shp)\n",
"\n",
"* Raster data (LiDAR, .tiff)\n",
"\n",
"Read more about [shapefiles](https://www.earthdatascience.org/courses/intro-to-earth-data-science/file-formats/use-spatial-data/use-vector-data/) and [LiDAR data](https://www.earthdatascience.org/courses/earth-analytics/lidar-raster-data-r/lidar-intro/) in our free, open, Earth Data Science Textbook [(www.earthdatascience.org).](https://www.earthdatascience.org/)\n",
"\n",
"![Colored Bar](https://drive.google.com/uc?export=view&id=1WL0ur5SQc5ijCvXc6MvWUeoWOIVS_rQ9)"
]
},
{
"cell_type": "markdown",
"id": "14e4e4c1-bb59-4fea-b356-c4069dc87d6b",
"metadata": {
"id": "14e4e4c1-bb59-4fea-b356-c4069dc87d6b"
},
"source": [
"\n",
"\n",
"\n",
"### Code of Conduct (borrowed from the [Carpentries](https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html))\n",
"\n",
"* Use welcoming and inclusive language\n",
"\n",
"* Be respectful of different viewpoints and experiences\n",
"\n",
"* Gracefully accept constructive criticism\n",
"\n",
"* Focus on what is best for the community\n",
"\n",
"* Show courtesy and respect towards other community members\n",
"\n",
"\n",
"\n",
"![Colored Bar](https://drive.google.com/uc?export=view&id=1WL0ur5SQc5ijCvXc6MvWUeoWOIVS_rQ9)\n"
]
},
{
"cell_type": "markdown",
"id": "a3a0a754-359d-4de0-becc-76e55c0f87fe",
"metadata": {
"id": "a3a0a754-359d-4de0-becc-76e55c0f87fe"
},
"source": [
"# Let's get started coding"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1dcdY070D0gH",
"metadata": {
"id": "1dcdY070D0gH"
},
"outputs": [],
"source": [
"# When using Colab un-comment the following lines and run this cell\n",
"# Otherwise, skip this cell and run the next cell.\n",
"\n",
"#%%capture \n",
"\n",
"# Install libraries not included w/ Colab\n",
"#%pip install geopandas\n",
"#%pip install rioxarray\n",
"#%pip install earthpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fbc8f363-04ac-4d85-bb2e-42fb194b336d",
"metadata": {
"id": "fbc8f363-04ac-4d85-bb2e-42fb194b336d"
},
"outputs": [],
"source": [
"# Import Python libraries\n",
"import os #for working with operating system\n",
"\n",
"import matplotlib.pyplot as plt #for general plotting\n",
"import geopandas as gpd #for opening and plotting geodataframes\n",
"import rioxarray as rxr #for opening raster data\n",
"import earthpy.plot as ep #for plotting raster data\n",
"import earthpy.spatial as es #for creating hillshade from DEM/DSM"
]
},
{
"cell_type": "markdown",
"id": "f3d8418d-eb9c-444c-a878-ecc928711c88",
"metadata": {
"id": "f3d8418d-eb9c-444c-a878-ecc928711c88"
},
"source": [
"## Vector data (shapefiles, .shp)\n",
"\n",
"Data are being brought in as a url from the U.S. Census Bureau and [data.gov](https://data.gov/), and opened using [geopandas](https://geopandas.org/en/stable/). Here we are working with the [The American Indian/Alaska Native/Native Hawaiian (AIANNH) Areas Shapefile](https://catalog.data.gov/dataset/tiger-line-shapefile-2018-nation-u-s-current-american-indian-alaska-native-native-hawaiian-area) which contains boundaries of all *Federally Recognized American Indian Reservations and Off-Reservation trust land areas.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7536d5a8-e8ea-437a-89a2-34001729c610",
"metadata": {
"id": "7536d5a8-e8ea-437a-89a2-34001729c610"
},
"outputs": [],
"source": [
"# Open and plot AIANNH areas\n",
"\n",
"# Land areas url\n",
"aiannh_url = \"https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_aiannh_500k.zip\"\n",
"\n",
"# Open land area boundaries\n",
"aiannh_boundary = gpd.read_file(aiannh_url)\n",
"print(aiannh_boundary)\n",
"\n",
"# Plot land area boundaries\n",
"fig, ax = plt.subplots(figsize=(20,12))\n",
"aiannh_boundary.plot(color='gold',\n",
" edgecolor='purple',\n",
" ax=ax)\n",
"ax.set_title(\"Map of Federally Recognized American Indian \\nReservations and Off-Reservation Trust Land Areas\", fontsize=30)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab35a418-7dd4-4a0b-a09a-bd157688c65a",
"metadata": {
"id": "ab35a418-7dd4-4a0b-a09a-bd157688c65a"
},
"outputs": [],
"source": [
"# Select and plot specified AIANNH boundaries (KS)\n",
"\n",
"# Kickapoo (KS)\n",
"kickapoo_bndry = aiannh_boundary.loc[aiannh_boundary['NAME'] == 'Kickapoo (KS)']\n",
"kickapoo_bndry.plot(color='gold',\n",
" edgecolor='purple')\n",
"\n",
"# Prairie Band Potawatomi Nation\n",
"pbpn_bndry = aiannh_boundary.loc[aiannh_boundary['NAME'] == 'Prairie Band of Potawatomi Nation']\n",
"pbpn_bndry.plot(color='gold',\n",
" edgecolor='purple')\n",
"\n",
"# Sac and Fox Nation\n",
"sfn_bndry = aiannh_boundary.loc[aiannh_boundary['NAME'] == 'Sac and Fox Nation']\n",
"sfn_bndry.plot(color='gold',\n",
" edgecolor='purple')\n",
"\n",
"# The Iowa Tribe of Kansas and Nebraska (KS-NE)\n",
"ikn_bndry = aiannh_boundary.loc[aiannh_boundary['NAME'] == 'Iowa (KS-NE)']\n",
"ikn_bndry.plot(color='gold',\n",
" edgecolor='purple')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "263f64f7-4902-455e-a7c1-2ded4f871aaf",
"metadata": {
"id": "263f64f7-4902-455e-a7c1-2ded4f871aaf"
},
"outputs": [],
"source": [
"# Define urls to state boundaries\n",
"states_url = \"https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_500k.zip\"\n",
"\n",
"# Open state boundary data\n",
"states_shp = gpd.read_file(states_url)\n",
"states_shp\n",
"\n",
"# Select specified states (KS)\n",
"ks_bndry = states_shp.loc[states_shp['NAME'] == 'Kansas']\n",
"\n",
"# Plot selected AIANNH boundaries & KS boundary\n",
"fig, ax = plt.subplots(figsize=(20,12))\n",
"ks_bndry.plot(ax=ax, \n",
" color='whitesmoke',\n",
" edgecolor='purple',\n",
" linewidth=2)\n",
"kickapoo_bndry.plot(ax=ax,\n",
" color='gold',\n",
" edgecolor='purple',\n",
" linewidth=1.5)\n",
"pbpn_bndry.plot(ax=ax,\n",
" color='gold',\n",
" edgecolor='purple',\n",
" linewidth=1.5)\n",
"sfn_bndry.plot(ax=ax,\n",
" color='gold',\n",
" edgecolor='purple',\n",
" linewidth=1.5)\n",
"ikn_bndry.plot(ax=ax,\n",
" color='gold',\n",
" edgecolor='purple',\n",
" linewidth=1.5)\n",
"ax.set_title(\"Federally Recognized American Indian Reservations \\nand Off-Reservation Trust Land Areas (KS)\", fontsize=30)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "6fb159b1-b5cb-4d75-95cc-9193112ded68",
"metadata": {
"id": "6fb159b1-b5cb-4d75-95cc-9193112ded68"
},
"source": [
"## Raster data (LiDAR, .tiff)\n",
"\n",
"Data were downloaded prior to the workshop from the Equator Studios web portal and saved within the CyVerse public file sharing environment. \n",
"\n",
"**Bonus Challenge:** Click [here](https://maps.equatorstudios.com/tab/Site%20Builder) to explore the Equator Studios website and try to download some data for a location that is important to you and your students.\n",
"\n",
"**NOTE:** The National Ecological Observatory Network [(NEON)](https://www.neonscience.org/) also collects and hosts lidar and other spatial and ecological data through their [data portal](https://www.neonscience.org/data)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0204085-4731-4de8-88f9-00d69f867614",
"metadata": {
"id": "c0204085-4731-4de8-88f9-00d69f867614"
},
"outputs": [],
"source": [
"# Bring in Equator Studio's Hillshade Data\n",
"!wget https://data.cyverse.org/dav-anon/iplant/commons/community_released/earthlab/haskell/2022-11-07-A9CE8-equator-surface.tiff"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f90a1cb0-dd8c-4915-817b-e9891515767f",
"metadata": {
"id": "f90a1cb0-dd8c-4915-817b-e9891515767f"
},
"outputs": [],
"source": [
"# Set path to data\n",
"lidar_path = os.path.join(\"2022-11-07-A9CE8-equator-surface.tiff\")\n",
"print(\"the path to the lidar data is:\", lidar_path)\n",
"\n",
"# Open data using rioxarray\n",
"haskell_lidar = rxr.open_rasterio(lidar_path, masked=True).squeeze()\n",
"haskell_lidar"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0660f155-b1db-439b-b636-677956a5d6fc",
"metadata": {
"id": "0660f155-b1db-439b-b636-677956a5d6fc"
},
"outputs": [],
"source": [
"# Plot data using earthpy.plot\n",
"f, ax = plt.subplots(figsize=(30,18))\n",
"ep.plot_bands(haskell_lidar,\n",
" #alpha=.6,\n",
" cbar=False,\n",
" ax=ax,\n",
" cmap='viridis')\n",
"ax.set_title(\"LiDAR/Hillshade Image of Haskell Indian Nations University (0.5m)\", fontsize=50)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "94d352bd-2ce2-4811-81fe-65b01faa341d",
"metadata": {
"id": "94d352bd-2ce2-4811-81fe-65b01faa341d"
},
"source": [
"# Processing DEM/DSM to Hillshade Using Earthpy\n",
"\n",
"## Opening and plotting Digital Elevation Model (DEM)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "029c975c-359a-47b6-b42e-fd9af2bc6107",
"metadata": {
"id": "029c975c-359a-47b6-b42e-fd9af2bc6107"
},
"outputs": [],
"source": [
"# Bring in Equator Studio's DEM data\n",
"!wget https://data.cyverse.org/dav-anon/iplant/commons/community_released/earthlab/haskell/2022-11-08-8B53E-equator-digital.tiff"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cafa59db-ee2e-45e8-adc4-ba258c3711a7",
"metadata": {
"id": "cafa59db-ee2e-45e8-adc4-ba258c3711a7"
},
"outputs": [],
"source": [
"# Processing DEM to hillshade \n",
"\n",
"# Set path to DEM data\n",
"dem_path = os.path.join(\"2022-11-08-8B53E-equator-digital.tiff\")\n",
"dem_path\n",
"\n",
"# Open DEM data using rioxarray\n",
"haskell_dem = rxr.open_rasterio(dem_path, masked = True).squeeze()\n",
"haskell_dem\n",
"\n",
"# Plot using earthpy.plot\n",
"# Add code to plot the DEM\n",
"fig, ax = plt.subplots(figsize=(20,20))\n",
"\n",
"ep.plot_bands(haskell_dem,\n",
" ax=ax,\n",
" cmap=\"gist_earth\",\n",
" cbar=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30f2580b-a2a0-4800-b835-410f970f725a",
"metadata": {
"id": "30f2580b-a2a0-4800-b835-410f970f725a"
},
"outputs": [],
"source": [
"# Create hillshade from DEM with es.hillshade()\n",
"haskell_dem_hillshade = es.hillshade(haskell_dem)\n",
"haskell_dem_hillshade"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f7e7363-9e7a-41ef-9c41-72960d619f6c",
"metadata": {
"id": "8f7e7363-9e7a-41ef-9c41-72960d619f6c"
},
"outputs": [],
"source": [
"# Add code to plot the hillshade made from DEM\n",
"fig, ax = plt.subplots(figsize=(20,20))\n",
"\n",
"ep.plot_bands(haskell_dem_hillshade,\n",
" ax=ax,\n",
" cmap='viridis',\n",
" cbar=False)\n",
"ax.set_title(\"Haskell Indian Nations University (DEM>Hillshade)\", \n",
" fontsize=30)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"source": [
"## Opening and plotting Digital Surface Model (DSM)"
],
"metadata": {
"id": "7ZBa29M3XvTj"
},
"id": "7ZBa29M3XvTj"
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b327487-0fbb-4cf8-8837-f967fb018129",
"metadata": {
"id": "3b327487-0fbb-4cf8-8837-f967fb018129"
},
"outputs": [],
"source": [
"# Bring in Equator Studio's DSM data\n",
"!wget https://data.cyverse.org/dav-anon/iplant/commons/community_released/earthlab/haskell/2022-11-08-B4BB7-equator-digital.tiff"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b47eb970-ffe2-463f-bfb6-05f9e54d7b76",
"metadata": {
"id": "b47eb970-ffe2-463f-bfb6-05f9e54d7b76"
},
"outputs": [],
"source": [
"# Processing DSM to hillshade \n",
"\n",
"# Set path to data\n",
"dsm_path = os.path.join(\"2022-11-08-B4BB7-equator-digital.tiff\")\n",
"dsm_path\n",
"\n",
"# Open data using rioxarray\n",
"haskell_dsm = rxr.open_rasterio(dsm_path, masked = True).squeeze()\n",
"haskell_dsm\n",
"\n",
"# Plot using earthpy.plot\n",
"# Add code to plot the DEM overlaid by the hillshade\n",
"fig, ax = plt.subplots(figsize=(20,20))\n",
"\n",
"ep.plot_bands(haskell_dsm,\n",
" ax=ax,\n",
" cmap=\"gist_earth\",\n",
" scale=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0e81566-716c-4509-907e-b53a4f8c4983",
"metadata": {
"id": "f0e81566-716c-4509-907e-b53a4f8c4983"
},
"outputs": [],
"source": [
"# Create hillshade from DSM with es.hillshade()\n",
"haskell_dsm_hillshade = es.hillshade(haskell_dsm)\n",
"haskell_dsm_hillshade"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "678174d4-4392-4873-add3-c6779b5ba7a8",
"metadata": {
"id": "678174d4-4392-4873-add3-c6779b5ba7a8"
},
"outputs": [],
"source": [
"# Add code to plot the hillshade from DSM\n",
"fig, ax = plt.subplots(figsize=(20,20))\n",
"\n",
"ep.plot_bands(haskell_dsm_hillshade,\n",
" ax=ax,\n",
" cmap='viridis',\n",
" cbar=False)\n",
"ax.set_title(\"Haskell Indian Nations University (DSM>Hillshade)\", \n",
" fontsize=30)\n",
"plt.show()"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}