Earthquakes Data Visualization

animations with Python and Plotly

Earthquakes Data Visualization

Introduction

An earthquake is the result of a sudden release of stored energy in the Earth's crust that creates seismic waves. According to USGS, an earthquake is what happens when two blocks of the earth suddenly slip past one another. The surface where the two blocks slip is known as the fault or fault plane. USGS tracks the data of the hazards and updates it every minute. The data is stored in CSV format.

In this blog, we will learn how to visualize the seismic data on the basis of the world or specific area. We will also learn to animate the visualization process based on the time factor.

Credits of Cover Image - Photo by Cédric Dhaenens on Unsplash

Data Source

USGS is the main source of data. It is well known for various disaster management systems including Earthquakes, Floods, Volcanoes, etc. The seismic data is recorded in four categories.

  • Hourly → updated every minute

  • Daily → updated every minute

  • Weekly → updated every minute

  • Monthly → updated every minute

For the project, we will only consider Daily, Weekly, and Monthly data.

Source - USGS Spreadsheet Format. In this link, you can find additional details like column names, and column descriptions.

Using this live-streaming data we can develop a live-updating dashboard (maybe I will cover that next time).

Implementation

If you would like to get the video explanation, you can watch the below video with some additional details.

import Packages

As always we begin with importing the packages that are essential for this project.

Data Manipulation

In the data, there are almost 22 columns in which most of them are NaN. There are few columns only a seismic researcher knows the importance of that. For the visualization, we will only consider 5 columns.

  1. time → useful for animating the visualization process.

    • Monthly → If monthly data is fetched, we shall extract the dates from the time column.
    • Weekly → If weekly data is fetched, we shall extract the weekdays from the time column.
    • Daily → If daily data is fetched, we shall extract the hours (numbers) from the time column.

  2. latitude → useful for plotting the earthquake location on the map.

  3. longitude → useful for plotting the earthquake location on the map.
  4. mag → useful to represent marker size as based on the magnitude of the earthquake.
  5. place → useful to visualize the data either worldwide or specific area.

    • The place column consists of both sub area and the main area. This has to be split in order to visualize the data pertaining to a specific area (main area).

Data Fetching & Preprocessing

The below is the function to obtain the preprocessed data after performing the above operations. By default, it fetches the data worldwide.

The function takes 3 parameters such as -

  • manner → the value of the parameter should be either of these daily, weekly, and monthly. By default, the value is daily.

  • bbox → is actually a bounding box parameter with which the data is filtered pertaining to the value that is passed. By default, the value is Worldwide.

  • mag_thresh → the value is a magnitude threshold that takes integer or float values. Based on this, the data is filtered. By default, it is 2.

Data Visualization

Once the data is fetched, we shall visualize to observe data patterns. The data shall be plotted on the map (stamen-terrain). We will be using Plotly to ease the visualization process.

Hence the below function.


Worldwide

Let's look at the animations for the Worldwide data.

Daily Basis

The animation is created on the basis of hours (numbers). Feel free to zoom in and zoom out the map.

Weekly Basis

The animation is created on the basis of the weekdays. Feel free to zoom in and zoom out the map.

Monthly Basis

The animation is created on the basis of the dates. Feel free to zoom in and zoom out the map.

Area Specific

Let's look at the animations for the Area based data.

Daily Basis

The animation is created on the basis of hours (only pertaining to the bbox value that is passed). Feel free to zoom in and zoom out the map.

Weekly Basis

The animation is created on the basis of the weekdays (only pertaining to the bbox value that is passed). Feel free to zoom in and zoom out the map.

Monthly Basis

The animation is created on the basis of the dates (only pertaining to the bbox value that is passed). Feel free to zoom in and zoom out the map.


Well, that's it for this article. You can find my work in the below links.

You can also subscribe to my newsletter for such exclusive content. Thanks all.

End