Build a Earthquake Early Warning Alert Map Node-RED Dashboard using OpenEEW data
Learn how to build an Earthquake Early Warning system using live OpenEEW sensor data and visualize historical seismic datasets in Node-RED Dashboards.
These example flows and Node-RED Dashboards might be useful as part of an Earthquake Early Warning system. Join the Call for Code challenge and contribute to open source projects.
- Install Node-RED and the prerequistes required to build the dashboards
- Learn how to program an algorithm to detect seismic shaking
- Construct a dashboard that displays live Earthquake Early Warning Sensor Alerts on a map and sends a SMS warning if a possible earthquake is detected
- Construct a dashboard that plots real time seismic activity sensor graphs in a chart by subscribing to a MQTT broker
- Construct a dashboard that plots the historical seismic activity from an OpenEEW dataset
- Install Node-RED on your system or in the cloud
- Alternatively, this flow can be deployed to IBM Cloud by creating a Node-RED Starter Application
- Add the following nodes to your Node-RED palette
npm install node-red-dashboard node-red-contrib-web-worldmap node-red-node-twilio node-red-node-ui-table
- Instead of adding the additional packages via Manage Palette, use the IBM Cloud Toolchain and the git repository in IBM Cloud to add the following packages to the package.json. Commit the change and the CI/CD toolchain will restage the CF application.
"node-red-dashboard":"2.x",
"node-red-contrib-web-worldmap":"2.x",
"node-red-node-twilio":"0.x",
"node-red-node-ui-table":"0.x",
One simplistic approach to detecting seismic activity is to measure large accelerations from the openeew accelerometer sensors, based on a set threshold that is above the typical noise floor of the accelerometer. Wikipedia defines a gal (unit) as a unit of acceleration used extensively in the science of gravimetry. The gal is defined as 1 centimeter per second squared (1 cm/s2). Seismic activity of interest might exceed 3 gals (3 cm/sec2).
These Node-RED flows observe the real-time openeew accelerometer data and calculate if the sensor might be experiencing seismic activity using the following algorithm. Each second this function receives x/y/z arrays of subsecond vibration data. The data arrays are passed into the function inside msg.payload.traces[0]
The javascript function loops through the vibration data looking for acceleration exceeding 3 cm/sec2
// The simplest way to detect changes :
// "not earthquake" vs "possible earthquake"
// For each tuple x,y,z take the
// square root of sum of the squared of each components:
// (x**2 + y**2 + z**2)**(1/2)
// square rooting gives back positive values
// Loop through all of the subsecond arrays of data
// Most of this is noise
// 1 cm/sec2 == 1 gal
// +/- 0.3 gals is jitter
var alert = false;
var gals = 0.0;
var x,y,z;
for( i=0; i<msg.payload.traces[0].x.length;i++){
x = msg.payload.traces[0].x[i];
y = msg.payload.traces[0].y[i];
z = msg.payload.traces[0].z[i];
gals = Math.sqrt( Math.pow(x,2) + Math.pow(y,2) + Math.pow(z,2) );
if( gals > 3 ) {
// whoa - maybe an earthquake
alert = true
}
}
if( alert ) {
return msg;
} else {
return null ;
}
Learn how to implement OpenEEW Node-RED dashboards using these example flows.
Four examples are provided in the flows folder.
This flow plots the OpenEEW sensors on a map of Mexico and displays their seismic activity status. The flow subscribes to the live data feed of the sensors using MQTT. If any of the sensors have not checked in for 30 seconds mark the sensor offline. If the seismic algorithm detects shaking, mark the sensor in red and send a Twilio SMS alert to warn residents to seek safety.
Get the Code: Node-RED flow for OpenEEW Alerts
This flow has four sections:
- The One time - Add Sensor pins to Map section drops pins on the terrain map at the latitude / longitude locations of the Grillo OpenEEW Earthquake Early Warning System sensor network.
- The Report Sensor Status section periodically checks if the sensors have recently reported, via MQTT, a seismic reading. If a sensor has not been seen during the last cycle, mark the device offline by changing the dropped pin to black with a warning symbol. When the sensor reconnects and comes back online, mark the device green on the map.
- The Subscribe to OpenEEW Sensor Network / Monitor Sensor Status section subscribes to the MQTT broker and records the timestamps of the devices as they report seismic readings. Details about the MQTT broker credentials need to be acquired in the Slack workspace.
- The Listen for possible Earthquakes section runs the seismic activity shake algorithm described above. If a possible earthquake is detected, send a Twilio alert and mark the dropped pin red on the map. You will need to configure the Twilio SMS node with your Twilio account details.
This flow subscribes to the live data feed (available via MQTT) of a selected sensor and plots the seismic activity in a set of X / Y / Z graphs.
Get the Code: Node-RED flow for OpenEEW Sensor graphs
This flow has three sections:
- The Enable / Disable Seismic Sensor Charts section saves the state of the Switch node that determines if the sensor data should be plotted.
- The Select an OpenEEW Sensor Network sensor to plot section loads a table of OpenEEW sensors and allows the investigator to choose which sensor to plot.
- The Plot selected real-time sensor data section subscribes to a MQTT broker and filters data from the selected sensor. It then splits the live sensor data into X / Y / Z coordinates and plots 15 accelerometer readings per second to the Node-RED Dashboard chart nodes. For performance reasons, depending on the sensitivity of the sensor, it discards the remaining accelerometer data.
Example 3 : Select a Sensor and time range, plot the historical seismic activity from a OpenEEW dataset
This flow displays a Node-RED dashboard which presents the investigator / seismologist with a calendar, time interval options and a list of OpenEEW sensors. The investigator selects an interesting sensor and time period to study and queries the OpenEEW dataset. The flow then plots the historical sensor data in a set of graphs.
The flow constructs a URL for the selected sensor and time interval and retrieves the historical sensor data from the OpenEEW dataset and plays it back into a graph in a Node-RED Dashboard.
The "Next" button in the Historical Quake Playback Node-RED dashboard is incredibly insightful. The focus is often on the big earthquakes, and their specific timestamp / dataset. The "Next" button lets the investigator explore the numerous aftershocks. Start with the Mexico 7.2 magnitude earthquake on Feb 16 2018 23:35 and its data set and then click the Next button to watch (in 5 minute increments) the aftershocks that occurred over the next several hours. Watch the animated gif of the earthquake and aftershock activity.
You can also observe the seismic activity by using the AutoPlay feature. Turn on the AutoPlay switch and select the number of minutes of playback.
The screenshot is of a magnitude 7.2 earthquake in Mexico on 2018-02-16 23:43:00.
Here is another screenshot of a magnitude 4.1 earthquake in Puerto Rico on 2020-06-01 12:05:51
Get the Code: Node-RED flow for OpenEEW Historical Playback
This flow has six sections:
- The Select a Historical Date section displays a Node-RED Dashboard which allows the earthquake investigator to select a date from a Calendar widget, drop down widgets to select the hour and 5 minute segment, an option to AutoPlay the data for several minutes. These selections are stored in flow variables.
- The Build / Display OpenEEW dataset to retrieve section takes the selected dates and constructs the dataset file to be downloaded / plotted.
- The Select a Sensor to plot section lists a table of sensors and their location coordinates.
- The Next dataset section provides a Next button and AutoPlay option to cycle through a timeseries of adjacent datasets. It calculates the name of the next dataset to be retrieved (handling all edge cases and leap years)
- The Plot the seismic graphs section ingests the dataset and builds X / Y / Z graphs of the sensor and seismic activity.
- The Download a historical sensor data set section retrieves the OpenEEW dataset using an http request node (no credentials required). Error messages are displayed if insufficient selections have been made or if the dataset is not available.
I created many Node-RED flows during my OpenEEW seismic graphing learning journey. Here is one of my beginning / simplistic iterations. This flow reads a file from a bucket of historical sensor data from the OpenEEW dataset using an AWS cloud object storage node (you would need credentials to reproduce it). The Node-RED flow plays the data back into a graph in a Node-RED Dashboard. The screenshot is of a magnitude 7.2 earthquake in Mexico on 2018-02-16 23:43:00.
Now that you have completed these examples, you are ready to modify these example flows and your own Node-RED Dashboard to build an OpenEEW Earthquake Early Warning data visualization solution. There are several OpenEEW GitHub project repositories that you can contribute to.
Join the cutting-edge community and build open source projects to fight back against the most pressing issues of our time. See your code deployed to help those in need.
Get free access to the IBM Cloud
Brush up on your cloud skills while making a real difference and get involved with these open source projects supported by the Linux Foundation.
- Another Node-RED Earthquake map example which plots USGS earthquake data can be found here
Enjoy! Give us feedback if you have suggestions on how to improve this tutorial.
The community welcomes your involvement and contributions to this project. Please read the OpenEEW contributing document for details on our code of conduct, and the process for submitting pull requests to the community.
This tutorial is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.