Repost#2 – Developing a real-time earthquake tracking web application

Hello,

This will be the last of the reposts for now from my old blog.

This post is my second post on Python Flask for web application development. You can check out my previous post on getting started with Flask here. In this post we dive into a simple build of a real time earthquake feed web application. The idea of building this application came a while back when I found a similar application while surfng through the web.

I was unable to get started with the build for the fact that I was clueless as to how to get this whole build started. After getting introduced to Flask, I decided to use Flask to build this application.

The ingredients you’ll need for this recipe are:

  • Python 2.7.x
  • mlleaflet package
  • flask
  • a dataset of earthquakes
  • matplotlib

After you’ve setup the development environment with all the dependencies met, we can start building this application. The build process is very simple, but before we go dive into the code, here’s a small introduction to the input dataset used.

The dataset is taken from the USGS-Earthquake GEOJSON feeds website. There are multiple options available with regard to the size of the dataset differentiated by the frequency of updates and the time interval between which the data has been acquired. For starters to test the code I used the 2.5 month dataset and the nal implementation was done with the 1 hour old updates. (All the data sources are marked as hyperlinks). The data is a GEOJSON object and the data we seek are available under the key: “features”.

As each data gets iterated in the program we extract the information like latitude,longitude, time of occurrence, the epicenter of the earthquake and the magnitude. The extracted information is wrapped up as a JSON string. The plotting is done in two stages. The first stage is:

  • The longitude and latitude (convention followed in lea et maps), are plotted with a marker, in this implementation, a red square.

matplotlib.pyplot.plot(longitude,latitude,’rs’)

  • This is done for all the latitude and longitude pairs available in the dataset

The second stage of the plotting is done with mlleaflet as:

mlleaflet.show()

And since this is web application developed in ask, we need to wrap the implementation within an app.route() to make the map accessible. When you execute the python script, a local server instance is created and you can access the map at http://127.0.0.1:5000/

The link to the code in Github is : https://github.com/ssharad/realtime-earthquake-feeds

I have enjoyed my brief and fruitful learning curve to develop web applications in Python, using the Flask, micro web framework. I do hope to build a few more applications with ask in the near future.

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