I have two classified raster (snow cover % 10-100) one is prepared from coarse resolution and another is from finer resolution. I am doing accuracy assessment and matrix calculation of snow cover %. However, both classified raster has invalid classes like NoData (-9999), cloud (value=205), water (210), permanent ice(215).
Now both the raster has same pixel size after resampling and covering same area by using gdalwarp
These classes/values are effecting the accuracy assessment. I only want to comapre both raster in terms of snow cover %. How can I eliminate those value from both raster??
My code
#reading in array Snow cover % raster from true raster (finer resolution)
img= rasterio.open(filepath+'20020310_ndsi_reclass.tif')
img_r=img.read(1)
#Reading in array Snow cover % from prediction raster (coarser resolution)
img_pre= rasterio.open(filepath+ '20020310_ndsi_reclass_pred.tif')
img_pre_r=img_pre.read(1)
#making it 1dimesional
y_true= np.ravel(img_r)
y_pred= np.ravel(img_pre_r)
y_true = y_true.astype('int')
y_pred = y_pred.astype('int')
from sklearn import metrics
print(metrics.classification_report(y_true, y_pred))
Matrix calculation
from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_true, y_pred)
import seaborn as sn
ax= plt.subplot()
sns.heatmap(cm, annot=True, ax = ax); #annot=True to annotate cells
# labels, title and ticks
ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels');
ax.set_title('Confusion Matrix');
ax.xaxis.set_ticklabels(['nodata','0','10', '20', '30', '40', '50', '60', '70', '80', '90', '100', 'cloud', 'water', 'ice']); ax.yaxis.set_ticklabels(['nodata','0','10', '20', '30', '40', '50', '60', '70', '80', '90', '100', 'cloud', 'water', 'ice']);
How to exclude Nodata, cloud, water, and ice from both the report?