Lesson 6. Practice Opening and Plotting Landsat Data in Python Using Rasterio


Learning Objectives

After completing this lesson, you will be able to:

  • Practice your skills using Landsat data in Python.
import os
# Glob for file manipulation
from glob import glob
import matplotlib.pyplot as plt
import geopandas as gpd
import rasterio as rio
import earthpy as et
import earthpy.spatial as es
import earthpy.plot as ep

# Download data and set working directory
data = et.data.get_data('cold-springs-fire')
os.chdir(os.path.join(et.io.HOME, 'earth-analytics', 'data'))

Challenge 1: Open And Crop Your Data

Above, you opened up the landsat scene in the directory: LC080340322016072301T1-SC20180214145802. This data covers an area which a file occured near Nederland, Colorado. For this challenge, you will work with data that was collected before the fire for the same area. Do the following:

  1. Crop all of the bands (tif files with the word “band” in them, in the LC080340322016070701T1-SC20180214145604 directory using earthpy crop_all().
  2. Next stack the cropped tif files using es.stack().
  3. Finally plot the data using ep.plot_bands()
Plot of each individual Landsat 8 band collected by glob and cropped by crop all. This image is of the Cold Springs Fire shorly before the fire.
Plot of each individual Landsat 8 band collected by glob and cropped by crop all. This image is of the Cold Springs Fire shorly before the fire.

Challenge 2 (Optional): Plot CIR and RGB Images Using Landsat

In this lesson which introduces working with Landsat data in open source Python, you learn how to plot both a color RGB and Color Infrared (CIR) images using landsat data. Create a figure below that has:

  1. A color RGB image of the landsat data collected post fire
  2. A CIR image of the landsat data collected post fire.

HINT: You will need to set the correct band combinations for your plots to turn our properly.

  • For Regular color images use: rgb=[3, 2, 1]
  • For color infrared use: rgb=[4, 3, 2]
Plot of color RBG and CIR of the Cold Springs fire before the fire.
Plot of color RBG and CIR of the Cold Springs fire before the fire.

Leave a Comment