aws_session = AWSSession(boto3.Session(), requester_pays=True)with rio.Env(aws_session):
with rio.open('s3://sentinel-s2-l1c/tiles/10/T/FK/2019/1/10/0/B04.jp2') as src1:
red = src1.read()
with rio.open('s3://sentinel-s2-l1c/tiles/10/T/FK/2019/1/10/0/B08.jp2') as src2:
nir = src2.read()
ndvisample = (nir.astype(float)-red.astype(float))/(nir.astype(float)+red.astype(float))
#ep.plot_bands(ndvisample, cmap="RdYlGn", vmin=-1, vmax=1);
ndvi_density_class = np.digitize(ndvisample, ndvi_class_bins)
# Apply the nodata mask to the newly classified NDVI data
ndvi_density_class = np.ma.masked_where(
np.ma.getmask(ndvisample), ndvi_density_class
)
np.unique(ndvi_density_class)
# Get list of classes
classes = np.unique(ndvi_density_class)
classes = classes.tolist()
# The mask returns a value of none in the classes. remove that
classes = classes[0:5]
# Plot your data
fig, (ax1) = plt.subplots(1, figsize=(12, 12),num=1, clear=True)
im1 = ax1.imshow(np.squeeze(ndvi_density_class), cmap=nbr_cmap)
ep.draw_legend(im_ax=im1, classes=classes, titles=ndvi_cat_names)
ax1.set_title(
"Sentinel2 - Normalized Difference Vegetation Index (NDVI) Classes",
fontsize=14,
)
ax1.set_axis_off()
plt.tight_layout()