Note
Click here to download the full example code
Compute quality index from confusion matrix¶
Compute different quality index (OA, Kappa and F1) directly from confusion matrix.
Import librairies¶
import numpy as np
from museotoolbox.stats import zonal_stats
from museotoolbox.datasets import load_historical_data
Load dataset¶
raster,vector = load_historical_data()
Compute mean and variance per polygon¶
mean,var = zonal_stats(raster,vector,'uniquefid',stats=['mean','var'])
print(mean.shape)
Out:
(17, 3)
Show mean value
print('For polygon 1 : ')
for band_idx,band in enumerate(['blue','green','red']):
print('Mean value in {} band is : {}'.format(band,mean[0,band_idx]))
Out:
For polygon 1 :
Mean value in blue band is : 117.72113436866982
Mean value in green band is : 109.81769074949358
Mean value in red band is : 79.69952734638757
Show variance value
print('For polygon 1 : ')
for band_idx,band in enumerate(['blue','green','red']):
print('Variance value in {} band is : {}'.format(band,var[0,band_idx]))
Out:
For polygon 1 :
Variance value in blue band is : 1303.9553197125313
Variance value in green band is : 1253.072772790252
Variance value in red band is : 1011.7105264477675
You can put in stats, every numpy function
For example here : mean, median, max, min
mean,median,amax,amin = zonal_stats(raster,vector,'uniquefid',stats=['mean','median','max','min'])
print('For polygon 1 : ')
for band_idx,band in enumerate(['blue','green','red']):
print('Min value in {} band is : {}'.format(band,amin[0,band_idx]))
print('Max value in {} band is : {}'.format(band,amax[0,band_idx]))
Out:
For polygon 1 :
Min value in blue band is : 32.0
Max value in blue band is : 196.0
Min value in green band is : 24.0
Max value in green band is : 187.0
Min value in red band is : 1.0
Max value in red band is : 155.0
Total running time of the script: ( 0 minutes 0.079 seconds)