Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# `es.stack()`.
os.chdir(os.path.join(et.io.HOME, "earth-analytics"))
band_paths_list = es.crop_all(
stack_band_paths, output_dir, crop_bound_utm13N, overwrite=True
)
#############################################################################
# Stack All Bands
# ---------------
# Once the data are cropped, you are ready to create a new stack.
os.chdir(os.path.join(et.io.HOME, "earth-analytics"))
cropped_array, array_raster_profile = es.stack(band_paths_list, nodata=-9999)
crop_extent = plotting_extent(
cropped_array[0], array_raster_profile["transform"]
)
# Plotting the cropped image
# sphinx_gallery_thumbnail_number = 5
fig, ax = plt.subplots(figsize=(12, 6))
crop_bound_utm13N.boundary.plot(ax=ax, color="red", zorder=10)
ep.plot_rgb(
cropped_array,
ax=ax,
stretch=True,
extent=crop_extent,
title="Cropped Raster and Fire Boundary",
)
plt.show()
###############################################################################
# Import Example Data
# -------------------
#
# To get started, make sure your directory is set. Then, create a stack from all of
# the Landsat .tif files (one per band).
os.chdir(os.path.join(et.io.HOME, "earth-analytics"))
# Stack the Landsat 8 bands
# This creates a numpy array with each "layer" representing a single band
landsat_path = glob(
"data/cold-springs-fire/landsat_collect/LC080340322016072301T1-SC20180214145802/crop/*band*.tif"
)
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])
###############################################################################
# the Landsat .tif files (one per band).
# Get data for example
data = et.data.get_data("vignette-landsat")
# Set working directory
os.chdir(os.path.join(et.io.HOME, "earth-analytics"))
# Stack the Landsat 8 bands
# This creates a numpy array with each "layer" representing a single band
# You can use the nodata= parameter to mask nodata values
landsat_path = glob(
"data/vignette-landsat/LC08_L1TP_034032_20160621_20170221_01_T1_sr_band*_crop.tif"
)
landsat_path.sort()
array_stack, meta_data = es.stack(landsat_path, nodata=-9999)
###############################################################################
# Plot All Bands in a Stack
# --------------------------
#
# When you give ``ep.plot_bands()`` a three dimensional numpy array,
# it will plot all layers in the numpy array. You can create unique titles for
# each image by providing a list of titles using the ``title=`` parameter.
# The list must contain the same number of strings as there are bands in the stack.
titles = ["Ultra Blue", "Blue", "Green", "Red", "NIR", "SWIR 1", "SWIR 2"]
# sphinx_gallery_thumbnail_number = 1
ep.plot_bands(array_stack, title=titles)
plt.show()
##################################################################################
#
# To get started, make sure your directory is set. Then, create a stack from all
# of the Landsat .tif files (one per band).
# Get data for example
data = et.data.get_data("vignette-landsat")
# Set working directory
os.chdir(os.path.join(et.io.HOME, "earth-analytics"))
# Stack the Landsat 8 bands
# This creates a numpy array with each "layer" representing a single band
# You can use the nodata parameter to mask nodata values
landsat_path = glob(os.path.join("data", "vignette-landsat", "*band*.tif"))
landsat_path.sort()
array_stack, meta_data = es.stack(landsat_path, nodata=-9999)
###############################################################################
# Plot All Histograms in a Stack With Custom Titles and Colors
# -------------------------------------------------------------
#
# You can create histograms for each band with unique colors and titles by
# first creating a list of colors and titles that will be provided to the
# ep.hist() function. The list for titles must contain the same number of
# strings as there are bands in the stack. You can also modify the colors for
# each image with a list of Matplotlib colors. If one color is provided in
# the list, every band will inherit that color. Otherwise, the list must
# contain the same number of strings as there are bands in the stack.
# Create the list of color names for each band
colors_list = [
"midnightblue",