The Blendy Blendy Quake #b3d

quakey0007

Australia may be an ancient and geologically stable island continent, after all the volcanos are long dead and the fault lines are minor. But we aren’t to far from the Pacific Ring of Fire! And we’re steadily moving north, towards Indonesia. This all means that Australia may be due for a significant earthquake, at some point, in the future… and it probably won’t be very big. But it could happen.

And we made a story about that!

Although we had some great drone shots of coastal Australia and some pretty great archival footage of past quakes, we still had the challenge of explaining where all of the quakes had occurred. So I suggested we get a map. The only drawback… there wasn’t one. Oh dear not again, what to do, what to do?

Make my own of course. I’ve got Blender and I’ve got the geological data from the Geoscience Australia Earthquake website. I specified a magnitude and date range for a list of suitable earthquakes.

quake-list

At first I had waaaay to many results so I increased the magnitude range until we had only the most serious quakes. Then I needed to get them in a useful format, but I didn’t want to spend days matching locations to a map of township names.

export-csv

I could export them as a simple CSV file (CSV stands for “comma-separated values”), its just a text file database. So I had scraped some data and discovered that the file included dates, magnitudes, location names and most importantly, earth coordinates. Good old latitude and longitude. Great, all done I thought.

The problem now was how to translate these ‘lat longs’ into coordinates on a flat map of Australia. So I posted a cleverly worded question on the greatest help site the Blender world has ever known (no its not twitter), thats right, Blender Stack Exchange. Although I did promote the question on twitter.

stackx

Ok so now I feel like I’m shining the Bat Signal into the clouds and waiting for a super hero to rescue me and my little python project…

bat-signal

He may not be the hero that Gotham needs but he sure was the one I needed. Enter @quollism again with some advice for my little python script. But due to my complete python ignorance his advice grew into a complete scripted solution which I really really appreciated.

# imports to make all the things work
from math import sin, cos, radians, pi, atan, tan
import csv
import bpy

# define some helpful functions for later

# a function to make, scale and rotate text objects into place
def makeathing(coords, scale, lat, long, date):
    rotation = (radians(lat - 270), pi, radians(long - 90))
    bpy.ops.object.text_add(location=(coords), rotation=(rotation))
    ob = bpy.context.object
    # set object properties here
    ob.data.body = "{:.1f}".format(float(scale))
    ob.data.align = 'CENTER'
    ob.rotation_mode = 'YXZ'
    ob.data.size = 0.03
    ob.data.extrude = 0.002
    ob.data.name = date
    ob.name = date

# a function to turn 3D polar coordinates into 3D cartesian coordinates
def latlonger(lat_deg, lon_deg):
    lat = radians(lat_deg)
    lon = radians(lon_deg)
    # see: http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
    alt = 0.01
    rad = 2                                     # radius of sphere in BUs
    f  = 0.0                                    # flattening
    ls = atan((1 - f)**2 * tan(lat))  # lambda
    x = rad * cos(lat) * cos(lon) + alt * cos(lat) * cos(lon)
    y = rad * cos(lat) * sin(lon) + alt * cos(lat) * sin(lon)
    z = rad * sin(lat) + alt * sin(lat)
    return (x, y, z)

# NB: no code has executed yet, we're just setting up functions we use further down

# read in the CSV file containing quake data
file = csv.reader(open('\\Users\mcsweend2c\Desktop\Bearthquakes 6-9.csv', newline=''), delimiter=',')

# make a blank dict variable to put quake data into
quakes = {}

# iterate through the CSV row by row and pull the data into variables
# then put the variables into a tuple and use a corrected date as the dict key
# see the last line of the for block for data order
# NB: could have used a dict instead of a tuple
# would have meant looking up e.g. quakes[x]['scale'] instead of quakes[x][0]
for idx, (scale, date, lat, lon) in enumerate(file):
    (yd, m, dy) = date.split("/")
    if int(yd) > int(dy):
        year = yd
        day = dy
    else:
        year = dy
        day = yd
    key = "{}-{:02g}-{:02g}".format( year, int(m), int(day) )
    quakes[key] = (scale, lat, lon)

# go through the sorted dates in the quakes dict
# get latitude and longitude and turn into x/y/z coords with latlonger function
# then send x/y/z coordinates to makeathing function to create them in 3D space
for k in sorted(quakes.keys()):
    latitude = float(quakes[k][1])
    longitude = float(quakes[k][2])
    coords = latlonger(latitude, longitude)
    makeathing(coords, quakes[k][0], latitude, longitude, k)

Anyway this created a bunch of data correctly located on a sphere, which I just had to create with an Earth texture from Nasa (thanks America). I spun it around until it lined up with the earthquake locations.

quakey0005

Although I should have automated the animated reveals of every quake, it would have taken me longer to debug than manually constructing it. Also I made a timeline scrolling date down the side.

With all the hard stuff out of the way I wanted to make an introduction to the Geoscience website. I grabbed some screen shots and built a series of textured planes ender a techy looking grid.

quakey0001

I used The Sniper addon from Jacques Lucke which is hosted at Blender Diploma. It let me quickly setup a camera animation over the images with a cool snapping effect.

quakey0002

Each image also had  a texture map of horizontal lines to give them more of a grungy tech look. In post production I added an old slide projector change noise to sell the mechanical nature of the move.

quakey0003

The finished result was so compelling to our audience that the Geosciences website made their own a couple weeks later! Check out my finished result here.

I must say that without Blender I’m really not sure how I could have achieved this in any other effects package. And hen I say Blender I’m referring to the software AND the community. The open nature of the application has tended to encourage artists to collaborate in a very useful collegiate manner which acts as an intellect multiplier for everyone involved. I just hope that I have given at least a little back to the community that has helped me so much in the past.

I’m looking at you Mr Bennett 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s