Skip to content

Instantly share code, notes, and snippets.

@ljwolf
ljwolf / extracting_amenityzones_from_images.ipynb
Last active February 9, 2018 15:15
A brief overview of one way you might extract the new "Amenity Zones" from Google Maps. I was intrigued by their presence, and wanted to see if there was a way to pull them out of the API for a given locale. This is very basic, and I'm sure they'll add better support to extract these areas in the future.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ljwolf
ljwolf / legendgrams.ipynb
Last active November 9, 2017 12:57 — forked from darribas/legendgrams.ipynb
Histograms as choropleth legends
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import scipy.stats as st
import copy
import numpy as np
import pysal as ps
def _estimate_kdes(y,z):
"""
estimate a kernel desnity for each group in z (classes) from y (data)
"""
z_unique = np.unique(z).tolist()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ljwolf
ljwolf / joyplot.py
Last active April 1, 2023 18:41
Joyplotting in python
def joyplot(data, ax=None,
flatten = .1, #rescale the height of each distribution to avoid overlap. If large, will flatten out each of the KDEs
linecolor='k',
shadecolor='w',
alpha=1,
shade=True,
line_kws = None,
kde_kws=None,
fig_kws=None,
shade_kws=None):
@ljwolf
ljwolf / disparity & boundary analysis.ipynb
Last active May 9, 2017 17:22
Notebook on disparity and boundary analysis
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ljwolf
ljwolf / gist:d9f8b19704c8443c0f4d8a5145c0080d
Created February 21, 2017 09:28
sql query for queen adjacency, given a table with geometry in the_geom and an index in geom_uid
select
t1.geom_uid as geom_uid,
t2.geom_uid as neighbor_uid
from
geo6311 as t1,
geo6311 as t2
where
st_touches(t1.the_geom, t2.the_geom);
@ljwolf
ljwolf / short_exploration.ipynb
Created November 29, 2016 05:02
This is a short exploration of the potential spatial structure of the 2012-2016 electoral swing. You'll need pandas, numpy, cenpy, pysal, and seaborn installed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ljwolf
ljwolf / precision_sampling.ipynb
Created November 22, 2016 20:55
This details what should be a method to sample from a multivariate normal in a spatial error model using only the precision matrix, instead of the covariance matrix.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ljwolf
ljwolf / retrodesign.py
Created October 13, 2016 20:00
retrodesign.py, from Gelman & Carlin (2014), Beyond Power Calculations.
import numpy as np
import scipy.stats as st
import warnings
def retrodesign(theta, se, alpha=.05 , df=1, n_sims = 10000):
"""
Implements the "retrodesign" function from Gelman \& Carlin (2014).
This computes the power, Sign error rate, and exaggeration ratio.