ObsPy
  •  GitHub
  •  Documentation 
    • Getting Started
    • Tutorial
    • Gallery
    • API Documentation (latest release)
    • General Packages
      • obspy.core
      • obspy.imaging
      • obspy.realtime
      • obspy.signal
      • obspy.station
      • obspy.taup
      • obspy.xseed
    • Waveform Import/Export
      • obspy.css
      • obspy.datamark
      • obspy.gse2
      • obspy.mseed
      • obspy.sac
      • obspy.seisan
      • obspy.seg2
      • obspy.segy
      • obspy.sh
      • obspy.wav
      • obspy.y
    • Database and Web Service Clients
      • obspy.arclink
      • obspy.db
      • obspy.earthworm
      • obspy.fdsn
      • obspy.iris
      • obspy.neic
      • obspy.neries
      • obspy.pde
      • obspy.seedlink
      • obspy.seishub
    • API Documentation (current master)
    • General Packages
      • obspy.core
      • obspy.imaging
      • obspy.realtime
      • obspy.signal
      • obspy.station
      • obspy.taup
      • obspy.xseed
    • Waveform Import/Export
      • obspy.css
      • obspy.datamark
      • obspy.gse2
      • obspy.mseed
      • obspy.sac
      • obspy.seisan
      • obspy.seg2
      • obspy.segy
      • obspy.sh
      • obspy.wav
      • obspy.y
    • Event Data Import/Export
      • obspy.core.quakeml
      • obspy.ndk
      • obspy.pde
    • Database and Web Service Clients
      • obspy.arclink
      • obspy.db
      • obspy.earthworm
      • obspy.fdsn
      • obspy.iris
      • obspy.neic
      • obspy.neries
      • obspy.seedlink
      • obspy.seishub
  •  Mailing Lists 
    • Announcements Mailing List (public)
    •  Subscribe
    •  Archive
    • Users Mailing List (public)
    •  Subscribe
    •  Archives
    •  Post a message
  •  Developer Resources 
    • How to contribute
    • Coding Style Guide
    • All Releases
    • Code Analysis
    • PEP8
    • Python Coverage
    • C Coverage
    • Coveralls
    • Continuous Integration
    • Test Reports
    •  Travis CI
index| modules| next| previous
  1. ObsPy Documentation (0.7.x-3222-g79df757179)
  2. ObsPy Tutorial

32. Connecting to a SeedLink Server¶

The obspy.seedlink module provides a Python implementation of the SeedLink client protocol. The obspy.seedlink.easyseedlink submodule contains a high-level interface to the SeedLink implementation that facilitates the creation of a SeedLink client.

32.1. The create_client function¶

The easiest way to connect to a SeedLink server is using the obspy.seedlink.easyseedlink.create_client() function to create a new instance of the EasySeedLinkClient class. It accepts as an argument a function that handles new data received from the SeedLink server, for example:

def handle_data(trace):
    print('Received the following trace:')
    print(trace)
    print()

This function can then be passed to create_client() together with a SeedLink server URL to create a client instance:

client = create_client('geofon.gfz-potsdam.de', on_data=handle_data)

The client immediately connects to the server when it is created.

32.1.1. Sending INFO requests to the server¶

The client instance can be used to send SeedLink INFO requests to the server:

# Send the INFO:ID request
client.get_info('ID')

# Returns:
# <?xml version="1.0"?>\n<seedlink software="SeedLink v3.2 (2014.071)" organization="GEOFON" started="2014/09/01 14:08:37.4192"/>\n

The responses to INFO requests are in XML format. The client provides a shortcut to retrieve and parse the server’s capabilities (via an INFO:CAPABILITIES request):

>>> client.capabilities
['dialup', 'multistation', 'window-extraction', 'info:id', 'info:capabilities', 'info:stations', 'info:streams']

The capabilities are fetched and parsed when the attribute is first accessed and are cached after that.

32.1.2. Streaming data from the server¶

In order to start receiving waveform data, a stream needs to be selected. This is done by calling the select_stream() method:

client.select_stream('BW', 'MANZ', 'EHZ')

Multiple streams can be selected. SeedLink wildcards are also supported:

client.select_stream('BW', 'ROTZ', 'EH?')

After having selected the streams, the client is ready to enter streaming mode:

client.loop()

This starts streaming data from the server. Upon every complete trace that is received from the server, the function defined above is called with the trace object:

Received new data:
BW.MANZ..EHZ | 2014-09-04T19:47:25.625000Z - 2014-09-04T19:47:26.770000Z | 200.0 Hz, 230 samples

Received new data:
BW.ROTZ..EHZ | 2014-09-04T19:47:22.685000Z - 2014-09-04T19:47:24.740000Z | 200.0 Hz, 412 samples

Received new data:
BW.ROTZ..EHZ | 2014-09-04T19:47:24.745000Z - 2014-09-04T19:47:26.800000Z | 200.0 Hz, 412 samples

Received new data:
BW.ROTZ..EHN | 2014-09-04T19:47:20.870000Z - 2014-09-04T19:47:22.925000Z | 200.0 Hz, 412 samples

Received new data:
BW.ROTZ..EHN | 2014-09-04T19:47:22.930000Z - 2014-09-04T19:47:24.985000Z | 200.0 Hz, 412 samples

The create_client() function also accepts functions to be called when the connection terminates or when a SeedLink error is received. See the documentation for details.

32.2. Advanced usage: subclassing the client¶

For advanced use cases, subclassing the EasySeedLinkClient class allows for finer control over the instance. Implementing the same client as above:

class DemoClient(EasySeedLinkClient):
    """
    A custom SeedLink client
    """
    def on_data(self, trace):
        """
        Override the on_data callback
        """
        print('Received trace:')
        print(trace)
        print()

The documentation has more details about the client.

By the ObsPy Development Team and many Awesome Contributors™  |  Built with Bootstrap and Glyphicons  |  Copyright 2008-2014

Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

Contributors

  • Adolfo Inza
  • Alessia Maggi
  • Anthony Lomax
  • Bernhard Morgenstern
  • Charles J. Ammon
  • Christian Sippl
  • Conny Hammer
  • Elliott Sales de Andrade
  • Fabian Engels
  • Gaute Hope
  • Joachim Saul
  • Lars Krieger
  • Lion Krischer
  • Marius Isken
  • Moritz Beyreuther
  • Paul Käufl
  • Philippe Lesage
  • Sebastian Heimann
  • Simon Kremers
  • Sven Egdorf
  • Thomas Lecocq
  • Tom Richter
  • Victor Kress
  • Ólafur St. Arnarsson
  • Alberto Michelini
  • Andreas Köhler
  • Arthur Snoke
  • Chad Trabant
  • Chris Scheingraber
  • Claudio Satriano
  • David Ketchum
  • Emiliano Russo
  • Felix Bernauer
  • Heiner Igel
  • Joachim Wassermann
  • Leonardo Uieda
  • Marcus Walther
  • Martin van Driel
  • Nathaniel C. Miller
  • Peter Danecek
  • Robert Barsch
  • Seyed Kasra Hosseini Zad
  • Stefan Stange
  • Sébastien Bonaimé
  • Tobias Megies
  • Tommaso Fabbri
  • Yannik Behr

Funds

ObsPy was partially funded by the

  • German Science Foundation (DFG) via grant DFG IG 16/9-1
  • German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
  • NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
  • Leibniz Institute for Applied Geophysics (LIAG)