Viewing Images

Viewing Images#

Read in Datasets#

  1. Subset of an AVIRIS image

import rasterio
# Import example AVIRIS data
with rasterio.open('./data/subset_f180628t01p00r02_corr_v1k1_img') as src:
    metadata = src.meta
    bands = src.read()

Viewing images#

You’ll notice because it’s visualizing a numpy array not a rasterio geospatial object that the axis isn’t in lat/long, it’s in pixel number.

Choosing a colormap (with a list of color map names a quarter of the way down)

import matplotlib.pyplot as plt
# plt.imshow() hands only one band at a time (or 3 bands, in the case of rgb images)
plt.imshow(bands[100])
<matplotlib.image.AxesImage at 0x7f3b5ef37e90>
../../_images/2b9709e459b815590b9d8fb300fe0b94d4a08fbd36f59524454fe8ff90621433.png
# make the plot bigger
plt.rcParams["figure.figsize"] = (10,10)
plt.imshow(bands[100])
<matplotlib.image.AxesImage at 0x7f3b5ef599d0>
../../_images/46b1dd1288e86c46a92a30ac679c8b8437b0fb0e09fd97c5a82e426f2514057b.png
# Change the color, add a color bar
plt.imshow(bands[100], cmap='GnBu')
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f3b56dbd2d0>
../../_images/dd4008fe3100a7866fb1a89fa08a5c055b05fca108569e66bd8bcfd1b5807cd8.png
import numpy.ma as ma
# Mask out invalid numbers, (but be sure to make sure this is scientifically sound first!)
bands_masked = ma.masked_where(bands < 0, bands )
plt.imshow(bands_masked[100])
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7f3b54f1ab10>
../../_images/bb3dea11e6df1cc23d2e32ec177421b49e2b900a8c0166fab9b978cf0d2050cf.png