Skip to content

Instantly share code, notes, and snippets.

@robinkraft
robinkraft / start.clj
Created July 8, 2011 18:44
BytesWritable error storing data using elephant-tap
(ns eleph.start
(:use [cascalog api])
(:require [elephantdb.cascalog.core :as e])
(:import [elephantdb.persistence JavaBerkDB]))
(def data [
[1 "dan"]
[2 "sam"]
[3 "robin"]
[4 "david"]
@robinkraft
robinkraft / gist:1413347
Created December 1, 2011 03:41
the easy way to install GDAL 1.8.0 on Ubuntu
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get -y install python-gdal
@robinkraft
robinkraft / sam.clj
Created January 25, 2012 17:53
first macro!
(defmacro sam [expr pos neg zero]
`(cond (pos? ~expr) ~pos
(neg? ~expr) ~neg
:else ~zero))
@robinkraft
robinkraft / Stata_monthly_replace.do
Created February 10, 2012 01:36
Replacing monthly values in Stata
forvalues year = 2005/2011 {
forvalues month = 1/12 {
if `month' < 10 {
local mo_str = "0`month'"
}
else {
local mo_str = "`month'"
}
local yearmo = "`year'`mo_str'"
di "`yearmo'"
@robinkraft
robinkraft / precl_loader.py
Created February 10, 2012 17:40
Load PRECL data, print min, max, sample vals
import numpy as np
for i in range(2000, 2013):
rain = np.fromfile("precl_mon_v1.0.lnx.%i.gri0.5m" % i, dtype="f", count=-1)
print "year:", i
print "max:", rain.max()
print "min:", rain.min()
print "first 100:", rain[:100]
@robinkraft
robinkraft / forma2csv.do
Created February 10, 2012 22:52
Export FORMA csv
outsheet modh modv sample line hansen prob$start_datestr-prob$end_datestr using "/Users/robin/code/forma-analysis/data/$iso$underscore$bboxname.csv" if prob$end_datestr !=. & lat <= $top & lat >= $bottom & lon >= $left & lon <= $right, comma replace
@robinkraft
robinkraft / forma_reshape.do
Created February 10, 2012 22:53
Reshaping FORMA data in Stata
* Snippit is a useful reminder of how Stata does reshapes
reshape long prob, string i(yearmo)
reshape long prob, string
reshape long i, string i(iso) j(yo)
reshape long prob, string i(id2) j(yearmo)
replace yearmo = dotm(yearmo)
@robinkraft
robinkraft / move_modis.sh
Created February 10, 2012 23:04
Move MODIS files between s3 buckets
s3cmd cp --recursive s3://formastaging/MOD13A3/2011-10-01/ s3://modisfiles/MOD13A3/2011-10-01/
s3cmd cp --recursive s3://formastaging/MOD13A3/2011-11-01/ s3://modisfiles/MOD13A3/2011-11-01/
s3cmd cp --recursive s3://formastaging/MOD13A3/2011-12-01/ s3://modisfiles/MOD13A3/2011-12-01/
@robinkraft
robinkraft / load_hdf.py
Created February 10, 2012 23:48
Load hdf file with GDAL and Python, get NDVI
from osgeo import gdal
import os
layer_dict = {"reli":"reliability", "qual":"Quality", "ndvi":"NDVI", "evi":"EVI"}
def print_data(layer, data):
print data
print "data:", layer
print "type:", data.dtype
print "mean:", data.mean()
@robinkraft
robinkraft / replace_hansen_nodata.py
Created February 13, 2012 00:52
Replace Hansen missing values -9999 with 0
# gdal_translate -ot Byte -of GTiff -a_nodata 0 IDN_new.asc IDN.tif
fp = open("IDN.asc", "r")
fout = open("IDN_new.asc", "w")
n = 0
for line in fp:
# replace -9999 with zeros - much smaller file
newline = "0".join(line.split("-9999"))