Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 16, 2021 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/7debeae40f45db918bfc4d0da1b82113 to your computer and use it in GitHub Desktop.
Save amankharwal/7debeae40f45db918bfc4d0da1b82113 to your computer and use it in GitHub Desktop.
from glob import glob
import earthpy as et
import earthpy.spatial as es
import earthpy.plot as ep
import rasterio as rio
from rasterio.plot import plotting_extent
from rasterio.plot import show
from rasterio.plot import reshape_as_raster, reshape_as_image
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap
import plotly.graph_objects as go
np.seterr(divide='ignore', invalid='ignore')
S_sentinel_bands = glob("/content/drive/MyDrive/Satellite_data/sundarbans_data/*B?*.tiff")
S_sentinel_bands.sort()
l = []
for i in S_sentinel_bands:
with rio.open(i, 'r') as f:
l.append(f.read(1))
arr_st = np.stack(l)
ep.plot_bands(arr_st, cmap = 'gist_earth', figsize = (20, 12), cols = 6, cbar = False)
plt.show()
rgb = ep.plot_rgb(arr_st,
rgb=(3,2,1),
figsize=(10, 16),
# title='RGB Composite Image'
)
plt.show()
ep.plot_rgb(
arr_st,
rgb=(3, 2, 1),
stretch=True,
str_clip=0.2,
figsize=(10, 16),
# title="RGB Composite Image with Stretch Applied",
)
plt.show()
colors = ['tomato', 'navy', 'MediumSpringGreen', 'lightblue', 'orange', 'blue',
'maroon', 'purple', 'yellow', 'olive', 'brown', 'cyan']
ep.hist(arr_st,
colors = colors,
title=[f'Band-{i}' for i in range(1, 13)],
cols=3,
alpha=0.5,
figsize = (12, 10)
)
plt.show()
ndvi = es.normalized_diff(arr_st[7], arr_st[3])
ep.plot_bands(ndvi, cmap="RdYlGn", cols=1, vmin=-1, vmax=1, figsize=(10, 14))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment