Tutorial/help: Download waveforms and save as image file with ObsPy!

994 views
Skip to first unread message

Emily Wolin

unread,
Aug 16, 2017, 1:05:29 PM8/16/17
to raspber...@googlegroups.com
Hi all,
Seems there is a lot of interest in being able to download waveforms from your Shake and save them to an image file.  
Here is a short tutorial on how to do this with the Python package ObsPy.  I'll leave the thread open for help with Python/ObsPy installations and troubleshooting too.

NOTE: These instructions are for Mac/Linux systems.  I have not installed Python or ObsPy on a Windows machine, but I'll try to help if I can.
Anything in fixed width font is a command you should type, exactly as written, into the terminal.

The ObsPy developers recommend using the Anaconda Python installation: https://github.com/obspy/obspy/wiki/Installation-via-Anaconda.  I use this package for research because it comes with lots of scientific libraries already installed, and the Conda package manager makes it easy to install or upgrade packages (like ObsPy!).  

Step 1: Install the Anaconda Python package.  
Download your operating system's installer for Python 3 at this site: https://www.continuum.io/downloads and follow the instructions to install.

Step 2: Install ObsPy.  
Open a terminal window.
First you will need to configure your Anaconda installation so it can find the "channel" where ObsPy is hosted:
conda config --add channels conda-forge
Then install obspy:
conda install obspy

Step 3: Run script to request and plot waveform data
I've attached a Python script that you can run to download and plot the last 15 minutes of data from your station of choice.
In your terminal, go to the directory where you downloaded the script.  For example, if you saved it to your Desktop folder, you would type
cd ~/Desktop
Then run the script: 
python get-last-15.py
Change the name of the station and the start/end times to whatever you like. (You could also launch an interactive IPython terminal by typing ipython into a terminal.  Then you can type commands one by one and see the output.)  

Please comment with questions, issues, and/or waveform images!

Emily

get-last-15.py

Emily Wolin

unread,
Aug 16, 2017, 4:02:14 PM8/16/17
to RaspberryShake
Hi everyone--
@blazvicic on Twitter pointed out an error regarding UTC times in the script.  I have fixed this in the script attached to the original post. Thanks for catching that, Blaž!  
Also, note that Raspberry Shake data is delayed by about 30 min (you can see this in SWARM also), so the most recent data available from the server is actually 30 min before "now".  The updated script looks for data between 45 and 30 min before "now" from your Shake of choice.  Of course you can feel free to set the window to however long you like.

Emily

WMXZ

unread,
Aug 17, 2017, 3:59:10 AM8/17/17
to RaspberryShake
opened script from spyder
worked
thanks
Water
As all-time matlab user I "hate" Py, but maybe sometime I will get used to it.

Ben Orchard

unread,
Aug 17, 2017, 4:32:38 PM8/17/17
to RaspberryShake
Emily and All,

Thanks so much for all your code samples over many posts, I have tinkered with them and found them very helpful.

I already had Python 3 (and a few key packages like numpy) installed on a Windows 10 laptop, so here is roughly how I got Obspy installed;
(I did not want to use Anaconda because reasons).

pip install sqlalchemy

pip install pyreadline ipython

pip install flake8 nose mock

pip install matplotlib

pip install SciPy Next, visit http://www.lfd.uci.edu/~gohlke/pythonlibs/ and search for obspy.

Download the wheel package to match your system and then pip install it.


Once I did that, all your code samples worked first time out of the box.
This leads me to your last comment...... personally the main reason I backed the RaspberryShake is to have live data.
The whole point of having my own seismograph in my backyard is to see the live (or very close to it) waveform from the large truck driving past my house, or seeing if I can see the vibrations from the low flying helicopter.
Having a 30 minute delay in seeing that data on my website really takes the fun out.

For now, I put together a bit of method to get my stations data to my website every minute.
1. Install Java on the RaspberryShake:
(I did the following, you may find other ways of doing it).

echo "deb http://http.debian.net/debian jessie-backports main" | \ sudo tee --append /etc/apt/sources.list.d/jessie-backports.list > /dev/null



sudo apt-get update


sudo apt-get install -t jessie-backports openjdk-8-jdk


2. Install Toms Java package as described in this post;

3. Make a crontab that will run the command to generate your preferred image. In my case;
crontab -e
Insert this line under whatever is already there.

*/1 * * * *  java -jar swarmPlotter.jar -p spectrogram --spectrogramWave -t -15i -c R7EE4_SHZ_AM_00 -s wws:192.168.1.80:16032 -z US/Pacific  spectro.png

Note, this is my station ID, my Pi's IP address on my network and my timezone, you will need to change those to match your raspberryshake.

How you move that image from your Pi's home directory to your website web server is up to you.
(I use another crontab job to scp it over).

The end result is I get the spectrogram updated every minute on mysite.
Not live, but pretty close.
Here is a screenshot from this morning when there was a little mag 1.27 roughly 60 miles from my house.


Thanks go to Emily and Tom for sharing their code and to everyone else in this wonderful community.
Could not have learned so much without you all.

Looking forward to exploring different ways to get closer to having real live data from my station on my website.

Ben.



Emily Wolin

unread,
Aug 25, 2017, 12:32:29 PM8/25/17
to RaspberryShake
Hi Ben,
Glad to hear the code has been useful!  
For anyone else who's interested in truly real-time data, you could definitely set up a cron job to copy over the latest data file from your Shake and use ObsPy's read command on the locally-stored data, instead of using the web client.  (Actually, I wonder if it might be possible to read data from your Shake directly if you know its IP address: see the first example in this ObsPy tutorial.) I can't test this out right now -- my Shake is on the other side of the world, on a network I can't SSH into -- but if someone else does, please let me know!

Emily

WMXZ

unread,
Aug 26, 2017, 11:13:56 AM8/26/17
to RaspberryShake
From GISMO, I use the same protocol that swarm is using (Winston, IP:16032) to access data directly from Rshake. Maybe this works also with ObsPy.

Branden Christensen

unread,
Aug 26, 2017, 11:18:31 AM8/26/17
to RaspberryShake
Hi mate:


With ObSpy, it would probably be best to connect via SeedLink on port 18000.


Yours, 


Branden Christensen
Director, OSOP & Gempa GeoServices
Director, Raspberry Shake project, Social Media: @raspishake

Get your very own personal seismograph on Kickstarter

--
Some useful links:
 
Manual: http://manual.raspberryshake.org/
Do It YourSelf Page: http://raspberryshake.org/do-it-yourself
Shop: https://shop.raspberryshake.org/
Website: http://raspberryshake.org/
 
Instagram: https://www.instagram.com/raspishake/
Facebook: https://www.facebook.com/raspishake/
Twitter: https://twitter.com/raspishake/
Hashtag: #rasperryshake
---
You received this message because you are subscribed to the Google Groups "RaspberryShake" group.
To unsubscribe from this group and stop receiving emails from it, send an email to raspberryshake+unsubscribe@googlegroups.com.
To post to this group, send email to raspberryshake@googlegroups.com.
Visit this group at https://groups.google.com/group/raspberryshake.
To view this discussion on the web visit https://groups.google.com/d/msgid/raspberryshake/961c5448-dcbf-4ba3-bdf2-f291bd7afa82%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Branden Christensen

unread,
Aug 26, 2017, 11:20:11 AM8/26/17
to RaspberryShake
Well, to qualify that response a bit:


SeedLink on port 18000: real-time data whatever is still in the buffer
OWS on port 16032: real-time data plus all data saved in the miniSEED (SDS) archive



Yours,


Branden Christensen
Director, OSOP & Gempa GeoServices
Director, Raspberry Shake project, Social Media: @raspishake

Get your very own personal seismograph on Kickstarter

To post to this group, send email to raspber...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages