I am trying to manually process UDP data that is being sent from a shake with obspy.
At first, I was not using UDP, and was polling the waveform directly, attaching an inventory file and removing the inventory file. This worked, but I do not want to request a pull each time, I want to passively accept the data via UDP.
In order to do this, I’m using this code:
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)
inv = read_inventory('./R1A9C-no_location-dummyfile.xml')
while (True): # loop forever
bData, addr = sock.recvfrom(1024) # wait to receive data
sData = bData.decode("utf-8") # converting bytes to string
lsData = sData.strip('}{').split(', ') # converting string to list of strings
ilsData = lsData[2:27]
ilsData = [int(i) for i in ilsData] # converting list of strings to list of integers
trace = Trace(data=numpy.array(ilsData))
trace.stats.channel = lsData[0].strip("'")
print (trace.stats.channel, trace.data)
trace.attach_response(inv)
trace.remove_response(output='ACC')
print (trace.stats.channel, max(abs(trace.data)))
The “data” looks identical to the output when get_waveform, i.e.:
However, when using get_waveform the response file works, but when manually populating the data, it does not. Please point me in the correct direction!
Note: I understand rsudp exists, but I just want to convert UDP control voltage to acceleration and write it to a database. I do not need all the other bells and whistles.