Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
landsat_path.sort()
arr_st, meta = es.stack(landsat_path)
###############################################################################
# Calculate Normalized Difference Vegetation Index (NDVI)
# -------------------------------------------------------
# You can calculate NDVI for your dataset using the
# ``normalized_diff`` function from the ``earthpy.spatial`` module.
# Math will be calculated (b1-b2) / (b1 + b2).
# Landsat 8 red band is band 4 at [3]
# Landsat 8 near-infrared band is band 5 at [4]
ndvi = es.normalized_diff(arr_st[4], arr_st[3])
###############################################################################
# Plot NDVI With Colorbar Legend of Continuous Values
# ----------------------------------------------------
# You can plot NDVI with a colorbar legend of continuous values using the
# ``plot_bands`` function from the ``earthpy.plot`` module.
titles = ["Landsat 8 - Normalized Difference Vegetation Index (NDVI)"]
# Turn off bytescale scaling due to float values for NDVI
ep.plot_bands(
ndvi, cmap="RdYlGn", cols=1, title=titles, scale=False, vmin=-1, vmax=1
)
ep.plot_bands(array_stack[4], cbar=False)
plt.show()
##################################################################################
# Turn Off Scaling
# -----------------
#
# ``ep.plot_bands()`` scales the imagery to a 0-255 scale by default. This range
# of values makes it easier for matplotlib to plot the data. To turn off
# scaling, set the scale parameter to ``False``. Below you
# plot NDVI with scaling turned off in order for the proper range of values
# (-1 to 1) to be displayed. You can use the ``cmap=`` parameter to adjust
# the colormap for the plot
NDVI = es.normalized_diff(array_stack[4], array_stack[3])
ep.plot_bands(NDVI, scale=False, cmap="RdYlGn")
plt.show()
##################################################################################
# Adjust the Number of Columns for a Multi Band Plot
# ---------------------------------------------------
#
# The number of columns used while plotting multiple bands can be changed in order
# to change the arrangement of the images overall.
ep.plot_bands(array_stack, cols=2)
plt.show()
)
landsat_path.sort()
arr_st, meta = es.stack(landsat_path)
###############################################################################
# Calculate Normalized Difference Vegetation Index (NDVI)
# -------------------------------------------------------
#
# You can calculate NDVI for your dataset using the
# ``normalized_diff`` function from the ``earthpy.spatial`` module.
# Math will be calculated (b1-b2) / (b1 + b2).
# Landsat 8 red band is band 4 at [3]
# Landsat 8 near-infrared band is band 5 at [4]
ndvi = es.normalized_diff(arr_st[4], arr_st[3])
###############################################################################
# Plot NDVI With Colorbar Legend of Continuous Values
# ----------------------------------------------------
#
# You can plot NDVI with a colorbar legend of continuous values using the
# ``plot_bands`` function from the ``earthpy.plot`` module.
titles = ["Landsat 8 - Normalized Difference Vegetation Index (NDVI)"]
# Turn off bytescale scaling due to float values for NDVI
ep.plot_bands(
ndvi, cmap="RdYlGn", cols=1, title=titles, scale=False, vmin=-1, vmax=1
)