Skip to content

Instantly share code, notes, and snippets.

View v0lat1le's full-sized avatar

Gregory Raevski v0lat1le

View GitHub Profile
@v0lat1le
v0lat1le / boost.py
Created October 27, 2017 03:04
LLDB boost::variant data formatter
import lldb
import lldb.formatters.Logger
def templateParams(s):
depth = 0
start = s.find('<') + 1
result = []
for i, c in enumerate(s[start:], start):
if c == '<':
@v0lat1le
v0lat1le / gdal_ctypes.py
Created November 30, 2015 21:52
GDAL ctypes shenanigans
import rasterio
import ctypes
_gdal = ctypes.cdll.LoadLibrary('libgdal.so.1')
OSRNewSpatialReference = _gdal.OSRNewSpatialReference
OSRIsGeographic = _gdal.OSRIsGeographic
OSRIsGeographic.restype = ctypes.c_bool
OSRGetSemiMajor = _gdal.OSRGetSemiMajor
OSRGetSemiMajor.restype = ctypes.c_double
@v0lat1le
v0lat1le / DataCubeV1DataStore.py
Created November 25, 2015 22:30
xray DataStore for geotiffs
class GeoTiffBandArrayWrapper(xray.core.utils.NdimSizeLenMixin):
def __init__(self, raster, band):
self._band = raster.GetRasterBand(band)
self.dtype = {gdalconst.GDT_Int16: numpy.int16}[self._band.DataType]
self.shape = (raster.RasterYSize, raster.RasterXSize)
def __array__(self, dtype=None):
return self._band.ReadAsArray()
def __getitem__(self, key):
@v0lat1le
v0lat1le / gdf.py
Created November 23, 2015 11:19
I Can Haz GDF
def get_descriptor(query=None):
# descriptor = {
# 'LS5TM': { # storage_type identifier
# 'dimensions': ['x', 'y', 't'],
# 'variables': { # These will be the variables which can be accessed as arrays
# 'B10': {
# 'datatype': 'int16',
# 'nodata_value': -999
# },
import re
from collections import namedtuple
MGRS = namedtuple('MGRS', ['zone', 'band', 'col', 'row', 'east', 'north'])
UTM = namedtuple('UTM', ['zone', 'band', 'east', 'north'])
def idx(ch):
idx = ord(ch)-ord('A')
if ch > 'O': idx -= 1 # skip 'O'
if ch > 'I': idx -= 1 # skip 'I'
import numpy
def argpercentile(a, q, axis=0):
"""
Compute the index of qth percentile of the data along the specified axis.
Returns the index of qth percentile of the array elements.
Parameters