Skip to content

Instantly share code, notes, and snippets.

View perrygeo's full-sized avatar

Matthew Perry perrygeo

View GitHub Profile
@perrygeo
perrygeo / build_grass7.sh
Last active August 29, 2015 14:01
Build GRASS 7 from source on Ubuntu 14.04
sudo apt-get build-dep grass
svn checkout https://svn.osgeo.org/grass/grass/trunk grass7_trunk
cd grass7_trunk
sh configure_grass71.sh
make
sudo make install
r.external input=/home/mperry/Desktop/landsat_test/LC80470282013287LGN00_B5.TIF \
output=LC80470282013287LGN00_B5 -e -o
r.external input=/home/mperry/Desktop/landsat_test/LC80470282013287LGN00_B6.TIF \
output=LC80470282013287LGN00_B6 -e -o
r.external input=/home/mperry/Desktop/landsat_test/LC80470282013287LGN00_B7.TIF \
output=LC80470282013287LGN00_B7 -e -o
r.external input=/home/mperry/Desktop/landsat_test/LC80470282013287LGN00_B8.TIF \
output=LC80470282013287LGN00_B8 -e -o
r.external input=/home/mperry/Desktop/landsat_test/LC80470282013287LGN00_B9.TIF \
output=LC80470282013287LGN00_B9 -e -o
testlist = [6.300000190734863, 61.0, 1.0, 560.0, 390.0, 12.0, 363.0, 18.0, 11.0]
test = np.array(test)
rf.predict(test) # 19
# Find the training data corresponding to this class
xs19 = train_xs[train_y == 19]
centroid19 = xs19.mean(axis=0)
# Look at the range of training data
lower = xs19.min(axis=0)
@perrygeo
perrygeo / test_django_email.py
Last active August 29, 2015 14:01
Django email test
import sys
from django.core.management import setup_environ
appdir = '/usr/local/apps/blah'
sys.path.append(appdir)
import settings
setup_environ(settings)
##############################
from django.core import mail
print "Sending mail to someone@internal.example.com...",

Intro

Matt Perry, Ecotrust Portland OR

Software Developer/Data Analyst by way of Natural Resource Planning and GIS

Ecotrust: ecosystem resilience but also resilient cultures and economies

Climate change resilience

Start with two datagframes, one point, one polygon

ipdb> polydf
   BoroCode       BoroName    Shape_Area     Shape_Leng  \
0         5  Staten Island  1.623847e+09  330454.175933   
1         3       Brooklyn  1.937810e+09  741227.337073   
2         4         Queens  3.045079e+09  896875.396449   
3         1      Manhattan  6.364308e+08  358400.912836   
4         2          Bronx  1.186822e+09  464475.145651   
If your image tests are failing and the images look fine, it's due to the tolerance of the comparison function.
Slight differences in platforms or image libs might generate subtly different images.
First, copy the tests/baseline_images/test_plotting/*_plot.png to a temp directory to look at later
Change GENERATE_BASELINE in tests/test_plotting.py to True
Run tests
Visually compare the new images to the old to make sure they are basically the same
<!doctype><html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Cool Satelite Imagery</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="http://cartodb.github.io/odyssey.js/sandbox/favicon.png">
<link rel="icon" type="image/png" href="http://cartodb.github.io/odyssey.js/sandbox/favicon.png">
@perrygeo
perrygeo / mercator_scale.py
Last active August 29, 2015 14:05
Mercator math (deprecated, use mercantile)
"""
from http://msdn.microsoft.com/en-us/library/bb259689.aspx
ground resolution = cos(latitude * pi/180) * earth circumference / map width
ground resolution = (cos(latitude * pi/180) * 2 * pi * 6378137 meters) / (256 * 2^level pixels)
map scale = 1 : ground resolution * screen dpi / 0.0254 meters/inch
map scale = 1 : (cos(latitude * pi/180) * 2 * pi * 6378137 * screen dpi) / (256 * 2 level * 0.0254)
"""

If you get this error when trying to boot a vagrant/virtualbox machine:

[default] Mounting shared folders...
[default] -- /vagrant
Failed to mount folders in Linux guest. This is usually beacuse
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was: