Skip to content

Instantly share code, notes, and snippets.

View gist:9085520
/** 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'] {
View hansen.py
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 Aug 29, 2015
n-obs: wrapper for Cascalog's "first-n" operation. Returns N observations of all fields for a given source.
View gist:9625937
(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 Aug 29, 2015
regenerate test data converting CDM to table driving website
View cdm_test.csv
x y z p
50064 72706 17 71
50064 72705 17 72
View gist:9800089
(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 Aug 29, 2015
EcoHackSF 2014 project results
View gist:bb239562aa3194b88030

Rainforest Connection

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

WattTime.com

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 Aug 29, 2015
working with rasterio and Apache Spark
View tifs.txt
>>> '''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 Aug 29, 2015
Extracting polygons from GEE
View ee_poly_export.py
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 Aug 5, 2014
precache images for crowdsourcing app
View cacher.py
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 Aug 29, 2015
revised GFW queries for UMD loss/gain data
View gist:05205edbd978de84873c
# 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