Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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