Skip to content

Instantly share code, notes, and snippets.

@skylander86
skylander86 / fleiss kappa.py
Created April 7, 2016 02:08
Compute Fleiss' kappa using numpy.
def fleiss_kappa(M):
"""
See `Fleiss' Kappa <https://en.wikipedia.org/wiki/Fleiss%27_kappa>`_.
:param M: a matrix of shape (:attr:`N`, :attr:`k`) where `N` is the number of subjects and `k` is the number of categories into which assignments are made. `M[i, j]` represent the number of raters who assigned the `i`th subject to the `j`th category.
:type M: numpy matrix
"""
N, k = M.shape # N is # of items, k is # of categories
n_annotators = float(np.sum(M[0, :])) # # of annotators
@perrygeo
perrygeo / zonal_stats.py
Last active March 22, 2023 05:01
Python implementation of zonal statistics function. Optimized for dense polygon layers, uses numpy, GDAL and OGR to rival the speed of starspan.
"""
Zonal Statistics
Vector-Raster Analysis
Copyright 2013 Matthew Perry
Usage:
zonal_stats.py VECTOR RASTER
zonal_stats.py -h | --help
zonal_stats.py --version
#!/usr/bin/env python
"""
Code extracts MODIS derived products (1km) from the HDF, rescales them, checks values against
acceptable QA and outputs to a binary file. Code seems generic enough that one can just
add another method for a new MODIS product. Currently works on LAI, NDVI/EVI and LST. Code
also writes out an ENVI .hdr file...nice.
*** NOTE...I don't vouch for the reliability of the default QA, please supply your own on
the cmd line.