Skip to content

Instantly share code, notes, and snippets.

@ldodds
Created November 2, 2015 20:35
Show Gist options
  • Save ldodds/2bfe914c5bd9efcfde32 to your computer and use it in GitHub Desktop.
Save ldodds/2bfe914c5bd9efcfde32 to your computer and use it in GitHub Desktop.
Quick hack to explore creating Joy Division style album cover from LIDAR data
#Bath Unchained
#
#based on original: http://matplotlib.org/examples/animation/unchained.html
#
#pass the script a path to a ASC file, e.g after unpacking the EA data I ran
#
#python bath-unchained.py LIDAR-DSM-1M-ST76/st7465_DSM_1m.asc
#
#output: https://twitter.com/ldodds/status/661279776292929536
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from osgeo import gdal
# Create new Figure with black background
fig = plt.figure(figsize=(8, 8), facecolor='black')
# Add a subplot with no frame
ax = plt.subplot(111, frameon=False)
# Read LIDAR data
file = sys.argv[1]
layer = gdal.Open(file)
gt = layer.GetGeoTransform()
bands = layer.RasterCount
data = []
for i in range(500, 1000, 8):
lidar_values = layer.GetRasterBand(1).ReadAsArray(i, 500, 1, 500)
flattened = np.array( [item for sublist in lidar_values for item in sublist] )
flattened[flattened < 0] = 0
data.append( flattened )
#normalise
data = np.array(data)
#this normalises to zero
#data = data / data.max(axis=0)
#this looks better for st7465_DSM_1m.asc
data = data * 0.05
X = np.linspace(-1, 1, data.shape[-1])
G = 1.5 * np.exp(-4 * X * X)
#plot lines
for i in range(len(data)):
# Small reduction of the X extents to get a cheap perspective effect
xscale = 1 - i / 200.
# Same for linewidth (thicker strokes on bottom)
lw = 1.5 - i / 100.0
#print data[i]
line, = ax.plot(xscale * X, i+G+data[i], color="w", lw=lw)
# Set y limit (or first line is cropped because of thickness)
ax.set_ylim(-1, 70)
# No ticks
ax.set_xticks([])
ax.set_yticks([])
# 2 part titles to get different font weights
ax.text(0.5, 1.0, "BATH LIDAR ", transform=ax.transAxes,
ha="right", va="bottom", color="w",
family="sans-serif", fontweight="light", fontsize=16)
ax.text(0.5, 1.0, "UNCHAINED", transform=ax.transAxes,
ha="left", va="bottom", color="w",
family="sans-serif", fontweight="bold", fontsize=16)
plt.draw()
plt.savefig('bath-unchained')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment