Skip to content

Instantly share code, notes, and snippets.

View carsonfarmer's full-sized avatar
🏖️
Remote working...

Carson Farmer carsonfarmer

🏖️
Remote working...
View GitHub Profile
@carsonfarmer
carsonfarmer / README.md
Last active August 29, 2015 14:01
Halton Sequence for Pseudo-random Points

Halton Sequence for Pseudo-random Points

May 18th, 2014 - Carson Farmer

The two point patterns here are the first 256 points from a 2, 3 Halton Sequence (left), and 256 points from a uniform random point process (right).

Halton sequences are often used to generate points in space for numerical methods such as Monte Carlo simulations. Although these sequences are deterministic they are of low discrepancy, which means they appear to be random for many purposes. A particularly useful property of Halton sequences (and some other pseudo-random sequences) is that they have have a better coverage of the underlying space than 'true' random sequences. This is particularly useful for creating things like dot density maps, where we want a random feel without leaving gaps across the space (which may arise with random numbers).

@carsonfarmer
carsonfarmer / README.md
Last active August 29, 2015 14:01
Problems Creating A Dot Density Map With D3

Problems Creating A Dot Density Map With D3

Here is the topojson call to create the topojson file:

topojson -o us_states.topo.json --projection='width=960, height=600, d3.geo.albersUsa().scale(1280).translate([width/2,height/2])' --simplyfy=.5 --filter=none --id-property='NAME,Geography' --external-properties=census_2010s.csv -p population=+2013 -- states=us_states.json

This could obviously be quite a bit more efficient (by using a canvas for example), but serves to illustrate the application.

Right now the points are randomly placed on the bounds of each individual state. What is the most efficient way to clip the points to the individual state polygons? Is there a 'point in polygon' js library compatible with D3.js? Are there more efficient 'approximations' for this? Any and all thoughts are welcome!

@carsonfarmer
carsonfarmer / batkid.geojson
Last active August 29, 2015 14:03 — forked from anonymous/corpus copy.geojson
Tweets about #batkid
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carsonfarmer
carsonfarmer / run_remote_code.py
Last active August 29, 2015 14:15
A simple function that fetches a remote (or local) python file and runs it inside an IPython Notebook
def run_remote_code(url):
"""Fetch and run remote Python code.
This is a custom function that fetches
and runs remote Python code inside of an
IPython Notebook.
Careful, this could be super bad stuff!
"""
from IPython.core.magics.code import CodeMagics
@carsonfarmer
carsonfarmer / data.csv
Created February 25, 2015 03:29
5000 Tweets in NYC over Thanksgiving
id x y
0 -73.992191 40.739449
1 -73.018136 40.87074
2 -73.946186 40.632716
3 -73.880039 40.998842
4 -72.165523 41.422617
5 -73.82308 40.990214
6 -73.070623 40.760706
7 -73.980833 40.77083
8 -73.530004 40.873758
@carsonfarmer
carsonfarmer / us-co2-codebook.txt
Last active September 3, 2015 22:05
Total CO2 emissions from fossil-fuels (1000 metric tons) for the United States
Total CO2 emissions from fossil-fuels (1000 metric tons) for the United States
Data source:
Source organization(s): CDIAC (Carbon Dioxide Information Analysis Center)
Link to source organization: http://cdiac.ornl.gov/
File name: nation.1751_2009.csv
Link to complete reference: http://cdiac.ornl.gov/ftp/ndp030/CSV-FILES/
Data attributes:
year:
@carsonfarmer
carsonfarmer / fuzzy.py
Created October 22, 2015 18:39
Problems with line merging geometries near the anti-meridian
from shapely import wkt
from shapely import ops
import matplotlib.pyplot as plt
%matplotlib inline
a = wkt.loads("LINESTRING (-180 68.96363636363637, -177.55 68.2, -174.92825 67.20589, -175.01425 66.58435, -174.33983 66.33556, -174.57182 67.06219, -171.85731 66.91307999999999, -169.89958 65.97723999999999, -170.89107 65.54139000000001, -172.53025 65.43791, -172.555 64.46079, -172.95533 64.25269, -173.89184 64.2826, -174.65392 64.63124999999999, -175.98353 64.92288000000001, -176.20716 65.35666999999999, -177.22266 65.52024, -178.35993 65.39052, -178.90332 65.74044000000001, -178.68611 66.11211, -179.88377 65.87456, -179.43268 65.40411, -180 64.97970870219837)")
b = wkt.loads("LINESTRING (180 64.97432999999999, 178.7072000000003 64.53493, 177.4112800000002 64.60821, 178.3130000000002 64.07593, 178.9082500000002 63.25197000000014, 179.37034 62.98262000000011, 179.48636 62.56894, 179.2282500000001 62.30410000000015, 177.3643 62.5219, 174.5692900000002 61.76915, 173.68013 61.65261, 172.15 60.95, 170.698500000000
@carsonfarmer
carsonfarmer / Iterative GeoJSON.ipynb
Created February 5, 2016 19:33
Some basic ideas for dealing with a 'stream' of GeoJSON features
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carsonfarmer
carsonfarmer / README.md
Last active February 8, 2016 03:56
CitiBike Trips

CitiBike trips by Neighborhood

Mouseover to focus on rides to or from a single neighborhood.

The thickness of links between neighborhoods encodes the relative frequency of rides between two neighborhoods: thicker links represent more frequent rides. Only flows that represent more than 1000 trips are represented here to avoid too many small flows.

Links are directed: for example, while 0.5% of rides go from Midtown to the Flatiron District, only 0.4% go in the opposite direction. Links are colored by the more frequent origin.

This may not be the best visualisation for this type of data, particularly given how dense the connectivity matrix is. However, it does present a quick and fun way to checkout the CitiBike data at an aggregate level.

@carsonfarmer
carsonfarmer / GSoc2016App.md
Created March 23, 2016 00:37 — forked from TaylorOshan/GSoc2016App.md
GSoC Proposal - Taylor Oshan- PySAL: Spatial Interaction Modeling

Python Software Foundation 2016 Google Summer of Code Application

Sub-organization Information

PySAL: Python Spatial Analysis Library

Student Information

  • Name: Taylor Oshan