Hi Stomrchaser, thanks for the reply! I apologize in advance that I have very little knowledge about seismography. I’ve been tasked with pulling in the data into an existing ecology, and making it available for other devs to use. It does not need plotted or displayed in any graph form at the moment.
My understanding is that rsudp gets installed and setup on the shake? If so, then that is not ideal for us, as we don’t own the shake that is casting to us. I’m sure we could work with the owners, but I’d much rather own the code on our end.
I’m really looking for a server-side solution, as we might have multiple shakes installed at some point and I’d like to keep their setup simple. On the server that I’m casting to, I can get the byte-stream and pick it apart and pull it into our database, however the voltage counts don’t mean much. Ideally, I’d like to just massage the raw data after it comes in to make it useful as acceleration/velocity.
I’ve been using ObsPy to grab the data (via IP using Client get_waveforms) and apply an inventory file, and I believe the numbers look correct, but I’d rather still get accel/velocity via UDP.
This is my test code. Each piece works, but I would like to marry the two methods together. Is there a way to apply the inventory to UDP?
import socket as s
import statistics
from obspy.core import UTCDateTime, Stream
from obspy import read_inventory
from obspy.clients.earthworm import Client
import time
import os
def main():
IPGet()
# UDPGet()
def IPGet():
‘’’
This will constantly query the rshake for waveform data and filter out the device-specific noise on
the sensors. However, get_waveforms lowest read time is in 1-second intervals.
‘’’
rs = Client(<rshake>, 16032) # on obspy 1.2.0 and greater
inv = read_inventory('./R1A9C-no_location-dummyfile.xml')
stream = Stream()
channels = ['EHZ','ENN','ENE','ENZ']
while (True):
calcStart = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - 1))
start = UTCDateTime(calcStart)
calcEnd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
end = UTCDateTime(calcEnd)
for ch in channels:
trace = rs.get_waveforms('AM', 'R1A9C', '00', ch, start, end)
stream += trace
stream.attach_response(inv)
stream.remove_response(output='ACC')
for trace in stream:
print (end, trace.stats.channel, max(abs(trace.data)))
def UDPGet():
‘’’
This will read a broadcasted UDP stream and split the incoming byte stream into chewable unit-less pieces
'''
host = <host>
port =<port> # Port to bind to
HP = host + ":" + str(port)
print (" Opening socket on (HOST:PORT) ", HP)
sock = s.socket(s.AF_INET, s.SOCK_DGRAM | s.SO_REUSEADDR)
sock.bind((host, port))
print ("Waiting for data on (HOST:PORT) ", HP)
while (True): # loop forever
bData, addr = sock.recvfrom(1024) # wait to receive data
# corrected = bData
# corrected.attach_response(inv)
# corrected.remove_resp(output='ACC', taper=0.5)
# print(corrected)
sData = bData.decode("utf-8") # converting bytes to string
lsData = sData.strip('}{').split(', ') # converting string to list of strings
print ("Sensor = ", lsData[0].strip("'"))
print (" Time = ", lsData[1])
ilsData = lsData[2:27]
ilsData = [int(i) for i in ilsData] # converting list of strings to list of integers
print (" Max = ", max(ilsData))
print (" Min = ", min(ilsData))
print (" Median = ", int(statistics.median(ilsData)))
print (" Average = ", int(statistics.mean(ilsData)))
print (" Deviation = ", int(statistics.stdev(ilsData)))
if name == “main”:
main()