Apply a mask based on NDSI to another set or independent values

29 views Asked by At

I am trying apply a mask based on the Normalized difference Snow Index (NDSI) to filter another set of independent values that calculate the red green normalized ratio (rgnd).

The problem is whenever I try to apply a mask based on the ndsi condition for the rgnd, my rgnd values are altered.

here is my code so far

#Calculate and visualize RGND

red = data["B03"].astype("float")
green = data["B04"].astype("float")
swir = data["B11"].astype("float")
rgnd = (green - red) / (green + red)

#create a mask based on the condition of NDSI>0.7
NDSI = (green - swir) / (green + swir)
ndsi_mask = NDSI > 0.7

# Create a masked array for visualization
rgnd_masked = np.ma.masked_array(rgnd, mask=~ndsi_mask)


# Apply the mask to the RGND values
fig, ax = plt.subplots(figsize=(10, 6))
im = ax.imshow(rgnd_masked, cmap="Reds", vmin=0, vmax=1)
ax.set_title("RDNG with condition");
plt.colorbar(im, ax=ax)
0

There are 0 answers