Looking at the outliers in the crowdsourced postcodes

Posted on 07 Sep 2013

A few weeks ago, I published some data on the accuracy of crowdsourced postcode data.

This weekend had a brief quiet moment, so I thought I'd try out a few visualisations to see if there was any particular grouping around the inaccuracies. Doesn't seem to be anything systematic.

The chart shows the npe sourced data, the OS sourced data and an arrow between them, coloured according to its magnitude.

In :
import csv
from multiprocessing import Pool
import itertools

distances = []
arrow_loc = []
arrow_vec = []
dist = []

# minimum distance difference we care about
min_dist = 1000

def get_vector(row):
return [row - row, row - row]

with open('distances.csv', 'rb') as csvfile:
for row in reader:
new_row = (row, map(int, row[1:3]), map(int, row[4:6]), float(row))
vector = get_vector(new_row)
if new_row > min_dist:
arrow_loc.append(new_row)
arrow_vec.append(vector)
dist.append(new_row)
distances.append(new_row + (vector,))
csvfile.close()

distances = filter(lambda x: x > min_dist, distances)

limit = len(distances)
distances = distances[:limit]
arrow_loc = arrow_loc[:limit]
arrow_vec = arrow_vec[:limit]
dist = dist[:limit]

o = zip(*zip(*distances))
In :
import matplotlib
import matplotlib.pylab as pylab
from matplotlib import cm
import numpy as np
import math
import matplotlib.pyplot as plt

%matplotlib inline

a = zip(*arrow_loc)
b = zip(*arrow_vec)
c = []

dist /= np.max(np.abs(dist),axis=0)
def norm(v, min, max):
return np.abs(v) * (max - min) + min

for i in dist:
#c.append(norm(i, 0.5,1))
#c.append(scalarMap.to_rgba(i))
c.append(norm(i, 0.5,1))

#heatmap, xedges, yedges = np.histogram2d(a, a, bins=50)
#extent = [np.min(xedges), np.min(xedges), yedges, yedges[-1]]
xlim = 700000
ylim = 1200000
width = 20

pylab.rcParams['figure.figsize'] = width, ylim/xlim * width

plt.xlim(0,xlim)
plt.ylim(0,ylim)

#plt.imshow(heatmap, interpolation='bicubic')
plt.scatter(a, a, color=(0.9,0.9,0.9))
plt.scatter(o, o, color=(0.6,0.7,0.6))
plt.quiver(a, a, b, b, c, width=0.001, cmap='Blues',angles='xy',scale_units='xy',scale=1)

#plt.ylabel('northing (m)')
#plt.xlabel('easting (m)') StackOverflow Flair 