Skip to content

Instantly share code, notes, and snippets.

View sgillies's full-sized avatar

Sean Gillies sgillies

View GitHub Profile
>>> import numpy
>>> from scipy.ndimage.morphology import grey_dilation
>>> a = numpy.zeros((7, 7))
>>> a[3,3] = 1
>>> a
array([[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 1., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0.],
import rasterio
with rasterio.open('input.tif') as src:
source = src.read_band(1)
def window_transform(transform, offset):
result = transform[:]
result[3] = transform[3] + offset[0]*transform[5]
result[0] = transform[0] + offset[1]*transform[1]
return result
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
...
#GPX GPX Yes Yes Yes (read support needs libexpat)
("GPX", "raw"),
...
@sgillies
sgillies / subsample.py
Last active August 29, 2015 13:57
Stats on rasters subsampled by rasterio
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])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file has been truncated, but you can view the full file.
{
"@context": {
"@context": {
"Polygon": "http://example.com/vocab#Polygon",
"Feature": "http://example.com/vocab#Feature",
"datetime": "http://www.w3.org/2006/time#inXSDDateTime",
"MultiLineString": "http://example.com/vocab#MultiLineString",
"id": "http://example.com/vocab#id",
"features": {
"@id": "http://example.com/vocab#coordinates",