Skip to content

Instantly share code, notes, and snippets.

/** simple visualization */
#imazon_clean [data_type='defor'] {
polygon-fill:#F69;
polygon-opacity: 1;
line-opacity:1;
line-color: #F69;
line-width: 2;
}
#imazon_clean [data_type='degrad'] {
@robinkraft
robinkraft / hansen.py
Last active August 29, 2015 13:56
sample script to download UMD forest cover loss data (untested) http://www.earthenginepartners.appspot.com/science-2013-global-forest/download.html
import os
import sys
import requests
basefname = 'Hansen_GFC2013_lossyear_%d%s_%03d%s.tif'
baseurl = 'http://commondatastorage.googleapis.com/earthenginepartners-hansen/GFC2013/%s'
def download(url, output):
@robinkraft
robinkraft / gist:9625937
Last active August 29, 2015 13:57
n-obs: wrapper for Cascalog's "first-n" operation. Returns N observations of all fields for a given source.
(use 'cascalog.api)
(require '[cascalog.ops :as c])
(defn field-parser
"Convert a string to a fieldname string. If string already
starts with `?` or `!`, return the string directly.
Usage:
(field-parser [\"a\" \"b\"])
;=> [\"?a\" \"?\"]"
@robinkraft
robinkraft / cdm_test.csv
Last active August 29, 2015 13:57
regenerate test data converting CDM to table driving website
x y z p
50064 72706 17 71
50064 72705 17 72
(defn sum-xyz
[]
(<- [?x ?y ?z ?period ?count :> ?x2i ?y2i ?z-new ?sum]
(/ ?x 2 :> ?x2)
(/ ?y 2 :> ?y2)
(math/floor ?x2 :> ?x2i)
(math/floor ?y2 :> ?y2i)
(dec ?z :> ?z-new)
(c/sum ?count :> ?sum)))
@robinkraft
robinkraft / gist:bb239562aa3194b88030
Last active August 29, 2015 14:01
EcoHackSF 2014 project results

Uses old Android phones to listen for chainsaws. EcoHack 2014 project added realtime SMS alerts & app for park rangers, as well as an impressive dramatization of intended usage.

Android apk
code

Shift your energy use to times when it's green. WattTime started at EcoHackSF 2013, and used EcoHack World to add support for water/carbon impact of energy generation.

@robinkraft
robinkraft / tifs.txt
Last active August 29, 2015 14:03
working with rasterio and Apache Spark
>>> '''launch python repl with ./bin/pyspark'''
'launch python repl with ./bin/pyspark'
>>> import rasterio as rio
>>>
>>> def img_size(path):
... with rio.drivers():
... with rio.open(path) as img:
... return [img.width, img.height]
...
>>>
@robinkraft
robinkraft / ee_poly_export.py
Last active August 29, 2015 14:03
Extracting polygons from GEE
import ee
# based on https://ee-api.appspot.com/cd2e21cd508327c5eb92ce57809f1360
def main():
# speciesData = ee.FeatureCollection(
# 'ft:14QQnwJVRPYXdhb4sRqaDblVRclbMxmew1rQCYig6')
# collection = ee.ImageCollection(
# 'MODIS/MOD13Q1').filterDate('2000-02-24', '2014-07-01')
@robinkraft
robinkraft / cacher.py
Created August 5, 2014 17:14
precache images for crowdsourcing app
import sys
import requests
import multiprocessing
URL = 'http://forma-cs-validation.elasticbeanstalk.com/api/alerts/next/cache'
def f(a):
try:
r = requests.get(URL)
@robinkraft
robinkraft / gist:05205edbd978de84873c
Last active August 29, 2015 14:06
revised GFW queries for UMD loss/gain data
# global sum of loss and gain by year
# note that the gain is the same each year (it is total gain / 12), so if you want total gain
# you need to add up all the gain values, or multiply one of them by 12
SELECT year,
Sum(loss) loss,
Sum(gain) gain
FROM umd_nat
WHERE thresh = 10
AND year > 2000
GROUP BY year