Skip to content

Instantly share code, notes, and snippets.

View danhammer's full-sized avatar

Dan danhammer

View GitHub Profile
#! /usr/bin/env python
"""
This script updates our MODIS data archive stored on S3 based on what's
available on NASA's MODIS data FTP server (e4ftl01u.ecs.nasa.gov)
The MODIS FTP server is organized by product then date, in the format
/MODIS_Composites/MOLT/MOD13A3.005/2000-02-01. This corresponds to the Terra
(MOLT) vegetation indices product at 1000m resolution, 32-day composites,
for the month of February 2000.
@danhammer
danhammer / _.md
Created June 20, 2013 22:26
uk geo hackery
import datetime
import urllib
import csv
from shapely.geometry import Point
from shapely.prepared import prep
import ee
import os
import ee.mapclient
import requests, zipfile, StringIO
import Image
@danhammer
danhammer / draft-gee.py
Last active December 25, 2015 22:29
Draft workflow for loading FORMA hits to CartoDB from GEE
import pandas as pd
import forma
import ee
from bbox_tiler import bbox
from globalmaptiles import GlobalMercator
def coordsToTiles(lon, lat):
# Convert the supplied latitude and longitude coordinates to
# mercator tiles at zoom level 16, ready for upload to CartoDB.
@danhammer
danhammer / gist:7160839
Created October 25, 2013 19:51
A very quick example of how to construct the query that will eventually be linked to on the country pages.
import requests
def construct_query(iso, fmt = 'shp'):
# Builds the API call to download FORMA in various formats Other
# acceptable formats are 'csv', 'GeoJSON', 'JSON', 'kml', or 'svg'
base = "http://wri-01.cartodb.com/api/v2"
var = "x,y,date_array"
sql = "SELECT %s FROM gfw2_forma WHERE iso = '{%s}'" % (var, iso)
query = "%s/sql?format=%s&q=%s" % (base, fmt, sql)
library(zoo)
library(stats)
library(dtw)
library(timeDate)
library(lubridate)
library(reshape)
library(randomForest)
clean.pixels <- function(filename, dir) {
## accepts output from Pavel's script and returns a data frame with
def formatPolygon(coords):
"""Accepts a set of coordinates, in sequence, and checks that they
are formatted counter-clockwise; returns an Earth Engine polygon.
Works for non-convex polygons."""
def _edger(c0, c1):
# anonymous function to generate the edge value between
# coordinate tuples `c0` and `c1`
x0, y0 = c0
x1, y1 = c1
@danhammer
danhammer / convert.py
Created March 22, 2014 03:04
Grab information on forest cover loss for the supplied shapefile
import os
import requests
import json
import pandas as pd
# Go from JSON to a measurement of UMD deforestation by year. If you
# have a shapefile, you will have to convert and simplify the
# polygons, preserving topology. The Earth Engine API does not
# support long, long requests. You can convert the shapefile using
# OGR within the data subdirectory:
@danhammer
danhammer / grab_ngos.py
Created April 8, 2014 22:01
Grab the NGO coordinates from bettermap.org
import requests
import pandas
from BeautifulSoup import BeautifulSoup
def _grab_data():
url = 'http://www.bettermap.org/json'
x = requests.get(url)
return x.json()['features']
def _process_entry(entry):
from bs4 import BeautifulSoup
import json
import pandas as pd
# Process information on Caltrans projects. Convert this file to
# GeoJSON:
# wget https://dot.ca.gov/hq/construc/cons.kml
# ogr2ogr -f GeoJSON cons.json cons.kml