Skip to content

Instantly share code, notes, and snippets.

@davidvhill
davidvhill / gdal_mmap.py
Last active July 14, 2016 18:31 — forked from jleinonen/gdal_mmap.py
GDAL in memory results
# also: https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#load-data-to-memory
# another, maybe better approach to this is to use the gdal 'MEM' driver and then use
# sds.ReadRaster() and sds.WriteRaster() to get at the bytes.
# >>> from osgeo import gdal
# >>> driver = gdal.GetDriverByName('MEM')
# >>> sds = driver.Create('', 200, 300, 4)
# >>> sds.ReadRaster()
# If specifying gzip encoding and transferring the image results via body this way,
@davidvhill
davidvhill / docker-super-clean
Created December 8, 2016 21:37
Remove all docker containers and images
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@davidvhill
davidvhill / Partition
Created April 5, 2017 18:21
partition code in python
""" Functions to drive algorithm execution in Apache Spark.
All coordinates are handled according to GeoJSON specifications.
http://geojson.org/geojson-spec.html"""
import geojson
import itertools
import math
def bbox(multipoint):
@davidvhill
davidvhill / apply.py
Last active September 6, 2017 06:55
Some structure.
from datetime import datetime
import d2d.user
import d2d.user.search
import d2d.notifications.send
####################################################################
# Method 1, detach interface from implementation
# Indirectly reference dependencies from vals
####################################################################
@davidvhill
davidvhill / ants.clj
Created February 2, 2018 00:41 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@davidvhill
davidvhill / firebird.py
Last active March 16, 2018 20:23
A Function I Am Proud Of
@entrypoint.command()
@click.option('--x', '-x', required=True)
@click.option('--y', '-y', required=True)
@click.option('--acquired', '-a', required=True)
@click.option('--number', '-n', required=False, default=2500)
def changedetection(x, y, acquired, number=2500):
"""Run change detection for a tile over a time range and save results to Cassandra.
Args:
x (int): tile x coordinate
@davidvhill
davidvhill / compounding.py
Last active September 11, 2018 20:01
Compound interest function
""" Compute compound interest given a rate, period and periodic rate increase
Args:
start: starting number
periods: compounding period
rate_growth: compounding rate growth rate
rate: starting compounding rate
Returns:
Final compounded value
@davidvhill
davidvhill / changedetection.clj
Last active May 21, 2019 13:50
Spec'd beginning of Clojure based change detection
(ns tmpclj.changedetection
(:require [clojure.spec.alpha :as s])
(:gen-class))
(s/def ::dates (s/coll-of int?))
(s/def ::reds (s/coll-of float?))
(s/def ::greens (s/coll-of float?))
(s/def ::blues (s/coll-of float?))
(s/def ::nirs (s/coll-of float?))
(s/def ::swir1s (s/coll-of float?))
@davidvhill
davidvhill / davidvhill.clj
Last active May 20, 2019 20:51
Determine if all sequences are the same length
(ns davidvhill)
(defn same-length?
[seqs]
(->> seqs (map count)
(into #{})
count
(= 1)))
@davidvhill
davidvhill / numberize.clj
Created December 6, 2019 19:11
Numerizing Made Simple
(require '[clojure.edn :as edn])
;; props to didibus https://clojuredocs.org/clojure.core/num
(defn numberize
[value]
(edn/read-string value))