Skip to content

Instantly share code, notes, and snippets.

@DanielJDufour
Created November 30, 2018 21:20
Show Gist options
  • Save DanielJDufour/9e15724b47ffa9296dc0902c42da3a81 to your computer and use it in GitHub Desktop.
Save DanielJDufour/9e15724b47ffa9296dc0902c42da3a81 to your computer and use it in GitHub Desktop.
hist.py
# get counts for raster using rio
from collections import Counter
import numpy as np
import rasterio as rio
from sys import argv
_, filepath = argv
with rio.open(filepath) as src:
bands = src.read()
height = len(bands[0])
width = len(bands[0][0])
print("height:", height, width)
counts = Counter()
for row in bands[0]:
counts.update(row)
print("counts:", counts.most_common(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment