Initial commit based on common repo commit ffeb9c9b
This commit is contained in:
114
examples/python/raw2caps.py
Normal file
114
examples/python/raw2caps.py
Normal file
@ -0,0 +1,114 @@
|
||||
############################################################################
|
||||
# Copyright (C) 2021 gempa GmbH #
|
||||
# #
|
||||
# All Rights Reserved. #
|
||||
# #
|
||||
# NOTICE: All information contained herein is, and remains #
|
||||
# the property of gempa GmbH and its suppliers, if any. The intellectual #
|
||||
# and technical concepts contained herein are proprietary to gempa GmbH #
|
||||
# and its suppliers. #
|
||||
# Dissemination of this information or reproduction of this material #
|
||||
# is strictly forbidden unless prior written permission is obtained #
|
||||
# from gempa GmbH. #
|
||||
############################################################################
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import signal
|
||||
|
||||
import numpy as np
|
||||
|
||||
from gempa import CAPS
|
||||
|
||||
|
||||
usage_info = """
|
||||
raw2caps - pushes raw samples into CAPS.
|
||||
|
||||
Usage: capstool [options]
|
||||
|
||||
Options:
|
||||
-H, --host host to connect to
|
||||
-h, --help display this help message and exit
|
||||
"""
|
||||
|
||||
|
||||
def usage(exitcode=0):
|
||||
sys.stderr.write(usage_info)
|
||||
return exitcode
|
||||
|
||||
|
||||
output = CAPS.Plugin("raw2caps")
|
||||
|
||||
def signal_handler(sig, frame): #pylint: disable=W0613
|
||||
print('Caught Ctrl+C!')
|
||||
output.quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
opts, _ = getopt.getopt(sys.argv[1:], "hH:d:n:",
|
||||
["help", "host=", "directory=", "network="])
|
||||
except getopt.GetoptError as err:
|
||||
# print help information and exit:
|
||||
print(str(err)) # will print something like "option -a not recognized"
|
||||
return usage(2)
|
||||
|
||||
addr = None
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
for o, a in opts:
|
||||
if o in ["-h", "--help"]:
|
||||
return usage()
|
||||
|
||||
if o in ["-H", "--host"]:
|
||||
addr = a
|
||||
else:
|
||||
assert False, "unhandled option"
|
||||
|
||||
if addr:
|
||||
try:
|
||||
host, port = addr.split(":")
|
||||
except BaseException:
|
||||
sys.stderr.write("invalid host address given: %s\n" % addr)
|
||||
return 1
|
||||
else:
|
||||
host = None
|
||||
port = None
|
||||
|
||||
if port:
|
||||
try:
|
||||
port = int(port)
|
||||
except BaseException:
|
||||
sys.stderr.write("invalid port given: %s\n" % port)
|
||||
return 1
|
||||
else:
|
||||
port = 18003
|
||||
|
||||
if not host:
|
||||
host = "localhost"
|
||||
|
||||
output.setHost(host)
|
||||
output.setPort(port)
|
||||
output.setBufferSize(1 << 30)
|
||||
output.enableLogging()
|
||||
|
||||
startTime = CAPS.Time.GMT()
|
||||
|
||||
x = np.array([1, 2], dtype=np.int32)
|
||||
res = output.push("AB", "HMA", "", "BHZ", startTime, 1, 1, "m", x,
|
||||
CAPS.DT_INT32)
|
||||
if res != CAPS.Plugin.Success:
|
||||
sys.stderr.write("failed to send packet\n")
|
||||
|
||||
output.close()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
Reference in New Issue
Block a user