Using USGS data, I visualize the magnitude and location of earthquakes that have occurred on a particular day. Disclaimer: This data includes ‘quarry blasts’ and ‘explosions’ that can be easily filtered out.
The first steps in this process are: create a new Processing sketch; download and clean the data; then import the cleaned data into the sketch. Pretty straightforward.
CREATE A NEW PROCESSING SKETCH
The main sketch starts with two functions: setup and draw. The setup() block runs once and is used for initializing the sketch by setting the screen size (this must be the first function inside the setup block), or applying color to the background. The draw() block runs repeatedly and is used for animation. Save the sketch as earthquake_viz.
def setup(): size(1200, 600); def draw(): background(44, 62, 80)
DOWNLOAD AND CLEAN THE DATA
Download “All Earthquakes” from the “Past Day” on the USGS Earthquake Hazard Program website. It will be in csv format. Create a data folder inside the earthquake_viz sketch and save the csv as earthquakes.csv. Create a new Google Sheet and open the earthquakes.csv file. Freeze the header row and delete any rows that have empty cells in the 'mag' (earthquake magnitude) column.
IMPORT CLEANED DATA INTO SKETCH
Using Python's core library for handling csv files, include the import statement at the very top of the sketch file. Add the following with block to open the csv file.
with open("earthquakes.csv") as f: reader = csv.reader(f) header = reader.next() # Skip the header row. print header