easyseedlink questions

Dear all,

Could you help me understand some of the functions of the easyseedlink (https://docs.obspy.org/packages/autogen/obspy.clients.seedlink.easyseedlink.html) package?
As far as I understand the on_data() function is running on a loop after the call of run() function. How am I suppose to close() the connection? How can I also use the on_seedlink_error() and the on_terminate()? Could you provide me a very simple example like this one (https://docs.obspy.org/packages/autogen/obspy.clients.seedlink.easyseedlink.EasySeedLinkClient.html#obspy.clients.seedlink.easyseedlink.EasySeedLinkClient)?

Thank you in advance,

Nikos

Hi Nikos,

I'm guessing you have you seen the corresponding chapter in the tutorial
[1]?

As far as I understand the on_data() function is running on a loop after
the call of run() function. How am I suppose to close() the connection?

As I see it there is currently no convenient way to break the loop from
the client. You do have access to the underlying SeedLinkConnection
object through client.conn though, so calling the connection's
terminate() method from another thread should also terminate the run()
loop and trigger the on_terminate() callback:

client.conn.terminate()

How can I also use the on_seedlink_error() and the on_terminate()? Could
you provide me a very simple example like this one
(obspy.clients.seedlink.easyseedlink.EasySeedLinkClient — ObsPy 1.4.0 documentation)?

The two methods provide callbacks for when either the SLTERMINATE or the
SLERROR packets were received. You can check the source of the
EasySeedLinkClient class [2] to see that they get called without any
arguments. So here is an extended example:

class MyClient(EasySeedLinkClient):

    def on_data(self, trace):
        print('Received trace:')
        print(trace)

    def on_terminate(self):
        print('Terminated. Doing some kind of cleanup or reconnect...')

    def on_seedlink_error(self):
        # inspect self.conn or self.conn.state or ...
        pass

Hope that helps,
Bernhard

[1] Connecting to a SeedLink Server — ObsPy 1.4.0 documentation
[2]
obspy.clients.seedlink.easyseedlink — ObsPy 1.4.0 documentation

Dear all,

Thank you Bernhard! I appreciate your help!

I tried the bellow code, but I got the error:
ERROR: obspy.clients.seedlink [150.140.182.6:18000]:response: DATA/FETCH/TIME command is not accepted
ERROR: obspy.clients.seedlink [150.140.182.6:18000]:negotiation with remote SeedLink failed: u'no stations accepted'

(check issue here: https://github.com/bonaime/seedlink_plotter/issues/25)

################## CODE #########################################
#!/usr/bin/env python
from obspy import UTCDateTime
import obspy.clients.seedlink.basic_client as sl

host='150.140.182.6'
net='HP'
sta='GBT1'
cha='BHN'
client = sl.Client(host, port=18000, timeout=60, debug=True)
t = UTCDateTime() - 5 #sec
st = client.get_waveforms(net,sta, "",cha, t, t + 3)
st = st.sort(reverse=True)
print(st)

At GEOFON the time window requests are currently disabled. You can also notice the missing "window-extraction" when looking at the capabilities:

$ slinktool -i CAPABILITIES geofon.gfz-potsdam.de
<?xml version="1.0"?>
<seedlink software="SeedLink v3.2 (2014.071)" organization="GEOFON" started="2016/07/15 12:59:08.5527">
   <capability name="dialup"/>
   <capability name="multistation"/>
   <capability name="info:id"/>
   <capability name="info:capabilities"/>
   <capability name="info:stations"/>
   <capability name="info:streams"/>
</seedlink>

If you need a time window t..t+3, would FDSNWS dataselect be a viable alternative?

Regards,
Andres.

Hi Nikolaos

I think you are experiencing the same issue I had 2 weeks ago (thread: "seedlink protocol 3.1 vs. 3.2 and obspy SLClient")

The short explanation is what you just got from Andres Heinloo, although strictly the server seems to be yours and not GEOFON's (judging from your email and the ip-address of the server)

Now, if the server is yours then it should be a (simple?) matter of enabling time window requests in the server settings.

The longer explanation is that obspy.clients.seedlink.basic_client is not meant to be used to retrieve data streams but rather specific finite chunks of data (see: http://docs.obspy.org/packages/autogen /obspy.clients.seedlink.basic_client.Client.html#obspy.clients.seedlink.basic_client.Client)

For realtime data streams you can either use the highlevel obspy.clients.seedlink.easyseedlink.EasySeedLinkClient or you can use the more basic obspy.clients.seedlink.slclient.SLClient which will give you greater control

regP

Thank you both for your quick answers!

Andres, as far as I know, FDSNWS dataselect is disabled to the current server. I thought, though that FDSNWS was an alternative to the Arclink and not the Seedlink protocol?!

Peter, could you provide a sample code usage with this module (obspy.clients.seedlink.slclient.SLClient)?

Best Regards,
Nikos

Yes, but Seedlink is optimized for real-time transfer, not for time window requests.

In case you are trying to access archive data, this would not work with Seedlink anyway. Aren't you transferring the HP stations to Athens in real time already?

Regards,
Andres.

Hi Nikolaos,

attached is some commented simplistic example code that accesses your server (let me know if attachments don't make it through and I'll send it to you directly given that you give me your email).

Note that the code assumes ObsPy 1.0 or later (for earlier versions you need to change slpack.get_trace() -> slpack.getTrace() and slc.slconn.set_sl_address -> slc.slconn.setSLAddress)

regP

exampleSLClient.py (2.34 KB)

Hi,

Is there a way to control the order of the returned traces objects -I'm referring to the on_data(trace) function-? Is it possible to retrieve a stream with all its traces in one call?

Thank you in advance,

Best Regards,
Nikos Triantafyllis