Skip to content

Instantly share code, notes, and snippets.

View robintw's full-sized avatar

Robin Wilson robintw

View GitHub Profile
@robintw
robintw / gist:4634668
Created January 25, 2013 14:01
Getis statistic code (IDL) (This is an extract of the code, so some variables aren't properly defined etc - but it should give you an idea of what I am doing.)
; Get the global mean
GlobMean = MEAN(WholeBand, /NAN)
; Get the global variance
GlobVariance = VARIANCE(WholeBand, /NAN)
; Get the number of values in the whole image
GlobNumber = (NumRows * NumCols - CountOfNAN)
; Converts a distance to the length of each side of the square
@robintw
robintw / gist:5918148
Created July 3, 2013 14:07
Adapative iteration code that is running v slowly. The main function is run_all(), which then calls adaptive_iteration() which then calls the other functions.
def make_ellipse(x, x0, y, y0, theta, a, b):
c = np.cos(theta)
s = np.sin(theta)
a2 = a**2
b2 = b**2
xnew = x - x0
ynew = y - y0
ellipse = (xnew * c + ynew * s)**2/a2 + (xnew * s - ynew * c)**2/b2 <= 1
return ellipse
@robintw
robintw / gist:6644601
Created September 20, 2013 22:11
Full error for Processing plugin on QGis 2.0, OS X
Couldn't load plugin 'processing' from ['/Applications/QGIS.app/Contents/MacOS/../Resources/python', '/Users/robin/.qgis2/python', '/Users/robin/.qgis2/python/plugins', '/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins', '/Library/Frameworks/SQLite3.framework/Versions/B/Python/2.7', '/Library/Frameworks/GDAL.framework/Versions/1.10/Python/2.7/site-packages', '/Library/Frameworks/cairo.framework/Versions/1/Python/2.7', '/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages', '/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/F
### WSGI for Web6S app
WSGIScriptAlias /web6s /usr/local/www/wsgi-scripts/Web6S/web6s.wsgi
<Directory /usr/local/www/wsgi-scripts/Web6S>
WSGIApplicationGroup %{GLOBAL}
AllowOverride None
Require all granted
</Directory>
@robintw
robintw / osm_to_shapefile.py
Last active June 20, 2017 08:16
Code to convert OSM XML files with waypoints defining polygons into a shapefile with those polygons in it
import xml.etree.cElementTree as ET
from shapely.geometry import mapping, Polygon
import fiona
import os
input_filename = "villages.osm"
output_filename = "villages.shp"
# Parse the XML from the OSM file
tree = ET.ElementTree(file=input_filename)
@robintw
robintw / gist:9713069
Created March 22, 2014 19:38
RIOS code which leads to strange offset
import numpy as np
from rios import applier
import tempfile
import subprocess
# Set up the function to be applied
def doMask(info, inputs, outputs, args):
if np.isnan(args.no_data):
outputs.outimage = np.isfinite(inputs.image)
from modulefinder import ModuleFinder
f = ModuleFinder()
# Run the main script
f.run_script('run.py')
# Get names of all the imported modules
names = list(f.modules.keys())
# Get a sorted list of the root modules imported
@robintw
robintw / gist:d0a2ed285da634688682
Last active August 29, 2015 14:01
Comparison of ARCSI code with/without parallelisation
# Simple test of method used in current ARCSI code (old_method)
# and Py6S parallelisation (new_method)
# Results from running it on my (relatively old, dual-core) MacBook Pro:
# old_method: 21.1s
# new_method: 10.6s
#
# We get roughly the 2x speed up that you'd expect with two cores.
#
# Running on my work machine which has 8 cores I get:
Process: Python [13682]
Path: /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: 2.7.6 (2.7.6)
Code Type: X86-64 (Native)
Parent Process: zsh [2073]
User ID: 501
Date/Time: 2014-06-04 22:21:46.058 +0100
OS Version: Mac OS X 10.8.5 (12F45)
Description Resource Path Location Type
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 40 Java Problem
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 40 Java Problem
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 59 Java Problem
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 63 Java Problem
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 74 Java Problem
Bookmark cannot be resolved to a type BookmarkTransfer.java /org.integratedmodelling.thinkcap/src/org/integratedmodelling/thinkcap/ui line 80 Java Problem
Bookmark cannot be resolved to a type ContextView.java