Last active
August 29, 2015 13:57
-
-
Save sgillies/9676184 to your computer and use it in GitHub Desktop.
Stats on rasters subsampled by rasterio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rasterio | |
import numpy as np | |
src = rasterio.open('/Users/sean/code/decloud/envs/1_16/output/0_q.tif') | |
# Fraction of elements with value > 100 at full resolution. | |
q = src.read_band(1) | |
ones = np.ones(q.shape) | |
print "Full, %d pixels" % (q.shape[0]*q.shape[1]) | |
print sum(ones[q>100])/(q.shape[0]*q.shape[1]) | |
# Fraction of elements with value > 100, sampling only 1 in 16. | |
shape = (q.shape[0]/4, q.shape[1]/4) | |
q = np.zeros(shape, dtype=np.uint8) | |
q = src.read_band(1, out=q) | |
ones = np.ones(q.shape) | |
print "Subsampled, %d pixels" % (q.shape[0]*q.shape[1]) | |
print sum(ones[q>100])/(q.shape[0]*q.shape[1]) | |
# Output | |
Full, 6806881 pixels | |
1683126000.0 m^2 | |
Subsampled, 425104 pixels | |
1681646400.0 m^2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment