diff --git a/seedlink_plotter/config_drum.txt b/seedlink_plotter/config_drum.txt new file mode 100644 index 0000000..40f75c6 --- /dev/null +++ b/seedlink_plotter/config_drum.txt @@ -0,0 +1,133 @@ +--- Configuration File (Drum Plot) --- + + +---------------------------------------------------------------------------- +line_plot = False + # Regular real time plot for single station. +---------------------------------------------------------------------------- + +############################################################################ + +# All about the data: +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +seedlink_streams=GE_STU:BHZ + # The seedlink stream selector string. + ; Format:stream1[:selectors1],stream2[:selectors2],... + ; "stream" 'in "NETWORK"_"STATION" format + ; "selector" a space separated "list of "LOCATION""CHANNEL", +---------------------------------------------------------------------------- +seedlink_server=geofon.gfz-potsdam.de:18000 + # The seedlink server to connect to with port +---------------------------------------------------------------------------- +update_time = 10 + # 'time in seconds between each graphic update.' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +equal_scale = True + # Only relevant for multiple plots. + # Equal scale True: Multiple plots are all plotted with the same Plot scale, + # Equal scale False: Multiple plots are all plotted with an individuall scale. + ;If relative scale is False it both are the same. +relative_scale = True +scale=10 + # Only relevant for dayplots. + # Scale to apply on the data. + # Relative scale True: The plot scale is dynamiclly set to the standard deviation + ; and multiplied with the value of scale. + # Relative scale False: The plot scale is directly set to the scale value. +---------------------------------------------------------------------------- +backtrace_time = 12h + # The number of seconds to plot (3600=1h,86400=24h). + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +remove_response = True + # If true trys instrument response gets removed +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +# All about Events +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +events_criteria = 5,10,0,180;4,10,0,50;2,10,0,10 + # Plot events using obspy.neries, + ;Specify: event_criteria1; event_criteria2; ... + ;event_criteria1: Minimum_Magnitude, Maximum_magnitude, Minimum_Radius, Maximum_Radius + ;if no events should show up: None +---------------------------------------------------------------------------- +events_update_time = 10 + # Time in minutes between each event data update. + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +#All about Layout +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +x_scale= 60 + # The number of minute to plot per line' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours. +---------------------------------------------------------------------------- +x_position = 200 + # The x position of the graph +---------------------------------------------------------------------------- +y_position = 50 + # The y position of the graph +---------------------------------------------------------------------------- +x_size = 800 + # The x size of the graph +---------------------------------------------------------------------------- +y_size = 600 + # The y size of the graph +---------------------------------------------------------------------------- +title_size = 10 + # The title size of each station in multichannel' +---------------------------------------------------------------------------- +time_legend_size = 10 + # The size of time legend in multichannel +---------------------------------------------------------------------------- +tick_format = None + # The tick format of time legend +---------------------------------------------------------------------------- +time_tick_nb = 10 + # The number of time tick' +---------------------------------------------------------------------------- +without-decoration = False + # The graph window will have no decorations. that means the + # window is not controlled by the window manager and can only + # be closed by killing the respective process. +---------------------------------------------------------------------------- +rainbow = False + # Rainbow colours instead of red, vlue, green, back in drum plot +---------------------------------------------------------------------------- +nb_rainbow_colors = 10 + # Number of different rainbow colours +---------------------------------------------------------------------------- +fullscreen = False + # Set to full screen on startup +---------------------------------------------------------------------------- +verbose = False + # show verbose debugging output +---------------------------------------------------------------------------- +force = False + # Skip warning message and confirmation prompt + # when opening a window without decoration' + + diff --git a/seedlink_plotter/config_line.txt b/seedlink_plotter/config_line.txt new file mode 100644 index 0000000..195797c --- /dev/null +++ b/seedlink_plotter/config_line.txt @@ -0,0 +1,132 @@ +--- Configuration File (Line Plot) --- + + +---------------------------------------------------------------------------- +line_plot = True + # Regular real time plot for single station. +---------------------------------------------------------------------------- + +############################################################################ + +# All about the data: +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +seedlink_streams=GE_DSB:BHZ + # The seedlink stream selector string. + ; Format:stream1[:selectors1],stream2[:selectors2],... + ; "stream" 'in "NETWORK"_"STATION" format + ; "selector" a space separated "list of "LOCATION""CHANNEL", +---------------------------------------------------------------------------- +seedlink_server=geofon.gfz-potsdam.de:18000 + # The seedlink server to connect to with port +---------------------------------------------------------------------------- +update_time = 1 + # 'time in seconds between each graphic update.' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +equal_scale = True + # Only relevant for multiple plots. + # Equal scale True: Multiple plots are all plotted with the same Plot scale, + # Equal scale False: Multiple plots are all plotted with an individuall scale. + ;If relative scale is False it both are the same. +relative_scale = True +scale=10 + # Only relevant for dayplots. + # Scale to apply on the data. + # Relative scale True: The plot scale is dynamiclly set to the standard deviation + ; and multiplied with the value of scale. + # Relative scale False: The plot scale is directly set to the scale value. +---------------------------------------------------------------------------- +backtrace_time = 10m + # The number of seconds to plot (3600=1h,86400=24h). + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +remove_response = True + # If true trys instrument response gets removed +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +# All about Events +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +events_criteria = None + # Plot events using obspy.neries, + ;Specify: event_criteria1; event_criteria2; ... + ;event_criteria1: Minimum_Magnitude, Maximum_magnitude, Minimum_Radius, Maximum_Radius + ;if no events should show up: None +---------------------------------------------------------------------------- +events_update_time = 10 + # Time in minutes between each event data update. + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +#All about Layout +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +x_scale= 60 + # The number of minute to plot per line' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours. +---------------------------------------------------------------------------- +x_position = 200 + # The x position of the graph +---------------------------------------------------------------------------- +y_position = 50 + # The y position of the graph +---------------------------------------------------------------------------- +x_size = 800 + # The x size of the graph +---------------------------------------------------------------------------- +y_size = 600 + # The y size of the graph +---------------------------------------------------------------------------- +title_size = 10 + # The title size of each station in multichannel' +---------------------------------------------------------------------------- +time_legend_size = 10 + # The size of time legend in multichannel +---------------------------------------------------------------------------- +tick_format = None + # The tick format of time legend +---------------------------------------------------------------------------- +time_tick_nb = 10 + # The number of time tick' +---------------------------------------------------------------------------- +without-decoration = False + # The graph window will have no decorations. that means the + # window is not controlled by the window manager and can only + # be closed by killing the respective process. +---------------------------------------------------------------------------- +rainbow = False + # Rainbow colours instead of red, vlue, green, back in drum plot +---------------------------------------------------------------------------- +nb_rainbow_colors = 10 + # Number of different rainbow colours +---------------------------------------------------------------------------- +fullscreen = False + # Set to full screen on startup +---------------------------------------------------------------------------- +verbose = False + # show verbose debugging output +---------------------------------------------------------------------------- +force = False + # Skip warning message and confirmation prompt + # when opening a window without decoration' + diff --git a/seedlink_plotter/config_line_multiple.txt b/seedlink_plotter/config_line_multiple.txt new file mode 100644 index 0000000..9bee650 --- /dev/null +++ b/seedlink_plotter/config_line_multiple.txt @@ -0,0 +1,133 @@ +--- Configuration File (Multiple Line Plot) --- + + +---------------------------------------------------------------------------- +line_plot = True + # Regular real time plot for single station. +---------------------------------------------------------------------------- + +############################################################################ + +# All about the data: +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +seedlink_streams=G_FDF:00BHZ 00BHN 00BHE,G_SSB:00BHZ 00BHN 00BHE,G_MBO:00BHZ 00BHE 00BHN + # The seedlink stream selector string. + ; Format:stream1[:selectors1],stream2[:selectors2],... + ; "stream" 'in "NETWORK"_"STATION" format + ; "selector" a space separated "list of "LOCATION""CHANNEL", +---------------------------------------------------------------------------- +seedlink_server=rtserver.ipgp.fr:18000 + # The seedlink server to connect to with port +---------------------------------------------------------------------------- +update_time = 1 + # 'time in seconds between each graphic update.' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +equal_scale = True + # Only relevant for multiple plots. + # Equal scale True: Multiple plots are all plotted with the same Plot scale, + # Equal scale False: Multiple plots are all plotted with an individuall scale. + ;If relative scale is False it both are the same. +relative_scale = True +scale=10 + # Only relevant for dayplots. + # Scale to apply on the data. + # Relative scale True: The plot scale is dynamiclly set to the standard deviation + ; and multiplied with the value of scale. + # Relative scale False: The plot scale is directly set to the scale value. +---------------------------------------------------------------------------- +backtrace_time = 10m + # The number of seconds to plot (3600=1h,86400=24h). + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +remove_response = True + # If true trys instrument response gets removed +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +# All about Events +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +events_criteria = None + # Plot events using obspy.neries, + ;Specify: event_criteria1; event_criteria2; ... + ;event_criteria1: Minimum_Magnitude, Maximum_magnitude, Minimum_Radius, Maximum_Radius + ;if no events should show up: None +---------------------------------------------------------------------------- +events_update_time = 10 + # Time in minutes between each event data update. + ; The following suffixes can be used as well: + ; "m" for minutes + ; "h" for hours + ; "d" for days.' +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- + +############################################################################ + +#All about Layout +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +x_scale= 60 + # The number of minute to plot per line' + ; The following suffixes can be used as well: + ; "s" for seconds + ; "m" for minutes + ; "h" for hours. +---------------------------------------------------------------------------- +x_position = 200 + # The x position of the graph +---------------------------------------------------------------------------- +y_position = 50 + # The y position of the graph +---------------------------------------------------------------------------- +x_size = 800 + # The x size of the graph +---------------------------------------------------------------------------- +y_size = 600 + # The y size of the graph +---------------------------------------------------------------------------- +title_size = 10 + # The title size of each station in multichannel' +---------------------------------------------------------------------------- +time_legend_size = 10 + # The size of time legend in multichannel +---------------------------------------------------------------------------- +tick_format = None + # The tick format of time legend +---------------------------------------------------------------------------- +time_tick_nb = 10 + # The number of time tick' +---------------------------------------------------------------------------- +without-decoration = False + # The graph window will have no decorations. that means the + # window is not controlled by the window manager and can only + # be closed by killing the respective process. +---------------------------------------------------------------------------- +rainbow = False + # Rainbow colours instead of red, value, green, back in drum plot +---------------------------------------------------------------------------- +nb_rainbow_colors = 10 + # Number of different rainbow colours +---------------------------------------------------------------------------- +fullscreen = False + # Set to full screen on startup +---------------------------------------------------------------------------- +verbose = False + # show verbose debugging output +---------------------------------------------------------------------------- +force = False + # Skip warning message and confirmation prompt + # when opening a window without decoration' + + diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index b3093f8..e353e67 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -18,12 +18,21 @@ from matplotlib.patheffects import withStroke from matplotlib.dates import date2num import matplotlib.pyplot as plt + +import obspy +from obspy.taup import TauPyModel + from obspy import Stream, Trace from obspy import __version__ as OBSPY_VERSION from obspy.core import UTCDateTime from obspy.core.event import Catalog from obspy.core.util import MATPLOTLIB_VERSION -from argparse import ArgumentParser,ArgumentDefaultsHelpFormatter +from obspy.clients.fdsn import RoutingClient + +# get settings +import configargparse +from argparse import ArgumentDefaultsHelpFormatter + from math import sin import threading import time @@ -104,6 +113,13 @@ def get_trace(self): # add the function in the class setattr(SLPacket, 'get_trace', get_trace) +# to parse through all stations +from obspy.clients.fdsn.header import URL_MAPPINGS + +# to keep track if the server is still sending data +global last_trace +last_trace = UTCDateTime() + class SeedlinkPlotter(tkinter.Tk): @@ -118,7 +134,7 @@ def __init__(self, stream=None, events=None, myargs=None, lock=None, file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "favicon.gif")) self.tk.call('wm', 'iconphoto', self._w, favicon) - self.wm_title("seedlink-plotter {}".format(myargs.seedlink_server)) + self.wm_title("seedlink-plotter{}".format(myargs.seedlink_server)) self.focus_set() self._bind_keys() args = myargs @@ -152,7 +168,7 @@ def __init__(self, stream=None, events=None, myargs=None, lock=None, self.events = events self.drum_plot = drum_plot self.ids = trace_ids - + # Colors if args.rainbow: # Rainbow colors ! @@ -161,7 +177,7 @@ def __init__(self, stream=None, events=None, myargs=None, lock=None, else: # Regular colors: Black, Red, Blue, Green self.color = ('#000000', '#e50000', '#0000e5', '#448630') - + self.plot_graph() def _quit(self, event): @@ -178,7 +194,9 @@ def _toggle_fullscreen(self, event): self._geometry = g def plot_graph(self): + now = UTCDateTime() + if self.drum_plot: self.stop_time = UTCDateTime( now.year, now.month, now.day, now.hour, 0, 0) + 3600 @@ -205,6 +223,7 @@ def plot_graph(self): else: stream.merge(-1) stream.trim(starttime=self.start_time, endtime=self.stop_time) + if self.drum_plot: self.plot_drum(stream) else: @@ -222,6 +241,17 @@ def plot_drum(self, stream): title += ' - autoscale -' title += " without filtering" self.figure.clear() + + for tr in stream: + tr.stats.processing = [] + + + # adjust scale + if self.args.relative_scale: + scale = max(stream.std())*self.args.scale + else: + scale = self.args.scale + stream.plot( fig=self.figure, type='dayplot', interval=self.args.x_scale, number_of_ticks=self.args.time_tick_nb, tick_format=self.args.tick_format, @@ -229,7 +259,7 @@ def plot_drum(self, stream): x_labels_size=8, y_labels_size=8, title=title, title_size=14, linewidth=0.5, right_vertical_labels=False, - vertical_scaling_range=self.args.scale, + vertical_scaling_range=scale, subplots_adjust_left=0.04, subplots_adjust_right=0.99, subplots_adjust_top=0.95, subplots_adjust_bottom=0.05, one_tick_per_line=True, @@ -474,9 +504,61 @@ def get_events(self): with self.lock: start = min([tr.stats.starttime for tr in self.stream]) end = max([tr.stats.endtime for tr in self.stream]) - neries_emsc = Client("EMSC") - events = neries_emsc.get_events(starttime=start, endtime=end, - minmagnitude=self.args.events) + + events = Catalog() + + # get the coordinats of the station + splitted_ids = [x.split(".") for x in self.args.ids] # use seedlink id to get network, station, location and channel + for client in ["iris-federator","eida-routing"]: + try: + Cli = RoutingClient(client) + station_inventory = Cli.get_stations(network = splitted_ids[0][0], + station = splitted_ids[0][1], + channel = splitted_ids[0][3], + location = splitted_ids[0][2]) + + station_latidude = station_inventory[0][0].latitude + station_longitude = station_inventory[0][0].longitude + break + except: + pass + + + # search for events fullfilling each criteria + for criteria in self.args.events_criteria: + print("Search for events with criteria" + str(criteria)) + temp_catalog = Catalog() + for client in URL_MAPPINGS.keys(): + try: + cli = Client(client) + + # get all events within a rdius (in deg) around the station with a minimum magnitude + t = cli.get_events(starttime=start, endtime=end, + minmagnitude=criteria[0], + maxmagnitude=criteria[1], + latitude = station_latidude, + longitude = station_longitude, + minradius = criteria[2], + maxradius = criteria[3]) + if t.count() > temp_catalog.count(): + temp_catalog = t + except: + pass + + events.extend(temp_catalog) + if temp_catalog.count == 0: + print("No events found for the current settings " +str(criteria) + "\n") + else: + print(str(temp_catalog.count()) + " events found" ) + + # corrects the time to be the arrival time and not the local event time + if events.count() > 0: + try: + events = self.event_time_to_arrival_time(events, station_latidude, station_longitude) + except: + print("Correcting all events not possible") + + return events def update_events(self, events): @@ -486,7 +568,32 @@ def update_events(self, events): with self.lock: self.events.clear() self.events.extend(events) - + + def event_time_to_arrival_time(self, events, lat, long): + """ + Uses TauPy to calculate the time it takes to see the first arrival at the station. + """ + + for event in range(len(events)): + try: + dist_event_to_station = obspy.taup.taup_geo.calc_dist(source_latitude_in_deg = events[event].origins[0].latitude, + source_longitude_in_deg = events[event].origins[0].longitude, + receiver_latitude_in_deg = lat, + receiver_longitude_in_deg = long, + radius_of_planet_in_km = 6371, + flattening_of_planet = 0) + + model = TauPyModel(model="iasp91") + arrivals = model.get_travel_times(source_depth_in_km = events[event].origins[0].depth /1000, + distance_in_degree = dist_event_to_station) + + events[event].origins[0].time = events[event].origins[0].time + arrivals[0].time + + except: + print("Correcting event " +str(event) + "not possible \n") + + return events + def _parse_time_with_suffix_to_seconds(timestring): """ @@ -518,6 +625,22 @@ def _parse_time_with_suffix_to_seconds(timestring): return float(timestring) * mult +class Connection(): + def __init__(self, master, myargs=None): + self.args = myargs + self.master = master + + #checks all 30 seconds if the last trace is older than 2 minutes. If its older the programm restarts. + def check(self): + while True: + time.sleep(30) + global last_trace + if UTCDateTime() - last_trace > 60*2: # never smaller than 10 sec. Otherwise it restarts sponatiously + python = sys.executable + print(python) + os.execl(python, python, * sys.argv) + + def _parse_time_with_suffix_to_minutes(timestring): """ Parse a string to minutes as float. @@ -546,90 +669,123 @@ def _parse_time_with_suffix_to_minutes(timestring): seconds = _parse_time_with_suffix_to_seconds(timestring) return seconds / 60.0 +def get_station_name(trace): + """ + Returns the trace name used to look for information in a dictonary. + """ + station_network = trace.stats.network + station_station = trace.stats.station + station_channel = trace.stats.channel + station_location = trace.stats.location + name = str(station_network) + "_" + str(station_station) + ":" + str(station_location) + str(station_channel) + + return name + def main(): - parser = ArgumentParser(prog='seedlink_plotter', + + p = configargparse.ArgParser(default_config_files=['/*.txt'], prog='seedlink_plotter', description='Plot a realtime seismogram of a station', formatter_class=ArgumentDefaultsHelpFormatter) - parser.add_argument( - '-s', '--seedlink_streams', type=str, required=True, - help='The seedlink stream selector string. It has the format ' - '"stream1[:selectors1],stream2[:selectors2],...", with "stream" ' - 'in "NETWORK"_"STATION" format and "selector" a space separated ' - 'list of "LOCATION""CHANNEL", e.g. ' - '"IU_KONO:BHE BHN,MN_AQU:HH?.D".') - parser.add_argument( - '--scale', type=int, help='the scale to apply on data ex:50000', required=False) - - # Real-time parameters - parser.add_argument('--seedlink_server', type=str, - help='the seedlink server to connect to with port. "\ - "ex: rtserver.ipgp.fr:18000 ', required=True) - parser.add_argument( - '--x_scale', type=_parse_time_with_suffix_to_minutes, - help='the number of minute to plot per line' - ' The following suffixes can be used as well: "s" for seconds, ' - '"m" for minutes, "h" for hours and "d" for days.', - default=60) - parser.add_argument('-b', '--backtrace_time', + + p.add('-c', '--my_config', required=True, is_config_file=True, help='config file path') + + p.add('-s', '--seedlink_streams', type=str, + help='The seedlink stream selector string. It has the format ' + '"stream1[:selectors1],stream2[:selectors2],...", with "stream" ' + 'in "NETWORK"_"STATION" format and "selector" a space separated ' + 'list of "LOCATION""CHANNEL", e.g. ' + '"IU_KONO:BHE BHN,MN_AQU:HH?.D".', dest = "seedlink_streams" ) + + p.add_argument('--equal_scale', action='store_true', + help='True if a all plots in multiple plots should be scaled the same way.', dest = "equal_scale") + + p.add_argument('--relative_scale', action='store_true', + help='True if a relative scale should be applied.', dest = "relative_scale") + + p.add_argument('--scale', type=float, + help='The scale to apply on data ex:50000, if relative scale is' + 'active scale is the factor to multiply this relative value with.', dest = "scale") + + p.add_argument('--seedlink_server', type=str, + help='the seedlink server to connect to with port. "\ + "ex: rtserver.ipgp.fr:18000 ') + + p.add_argument('--update_time', + help='time in seconds between each graphic update.' + ' The following suffixes can be used as well: "s" for seconds, ' + '"m" for minutes, "h" for hours and "d" for days.', + type=_parse_time_with_suffix_to_seconds) + p.add_argument('--events_criteria', default=None, type = str, + help='plot events using obspy.neries, specify [Minimum_Magnitude, Maximum_magnitude,Minimum_Radius, Maximum_Radius]') + + p.add_argument('--events_update_time', + help='time in minutes between each event data update. ' + ' The following suffixes can be used as well: "s" for seconds, ' + '"m" for minutes, "h" for hours and "d" for days.', + type=_parse_time_with_suffix_to_minutes) + p.add_argument('-b', '--backtrace_time', help='the number of seconds to plot (3600=1h,86400=24h). The ' 'following suffixes can be used as well: "m" for minutes, ' - '"h" for hours and "d" for days.', required=True, + '"h" for hours and "d" for days.', type=_parse_time_with_suffix_to_seconds) - parser.add_argument('--x_position', type=int, - help='the x position of the graph', required=False, default=0) - parser.add_argument('--y_position', type=int, - help='the y position of the graph', required=False, default=0) - parser.add_argument( - '--x_size', type=int, help='the x size of the graph', required=False, default=800) - parser.add_argument( - '--y_size', type=int, help='the y size of the graph', required=False, default=600) - parser.add_argument( - '--title_size', type=int, help='the title size of each station in multichannel', required=False, default=10) - parser.add_argument( - '--time_legend_size', type=int, help='the size of time legend in multichannel', required=False, default=10) - parser.add_argument( - '--tick_format', type=str, help='the tick format of time legend ', required=False, default=None) - parser.add_argument( - '--time_tick_nb', type=int, help='the number of time tick', required=False) - parser.add_argument( - '--without-decoration', required=False, action='store_true', + + p.add_argument('--x_scale', type=_parse_time_with_suffix_to_minutes, + help='the number of minute to plot per line' + ' The following suffixes can be used as well: "s" for seconds, ' + '"m" for minutes, "h" for hours and "d" for days.') + p.add_argument('--x_position', type=int, + help='the x position of the graph') + p.add_argument('--y_position', type=int, + help='the y position of the graph') + p.add_argument('--x_size', type=int, help='the x size of the graph') + p.add_argument('--y_size', type=int, help='the y size of the graph') + p.add_argument('--title_size', type=int, + help='the title size of each station in multichannel') + p.add_argument('--time_legend_size', type=int, + help='the size of time legend in multichannel') + p.add_argument('--tick_format', type=str, + help='the tick format of time legend ') + p.add_argument('--time_tick_nb', type=int, + help='the number of time tick') + p.add_argument( + '--without-decoration', action='store_true', help=('the graph window will have no decorations. that means the ' 'window is not controlled by the window manager and can only ' 'be closed by killing the respective process.')) - parser.add_argument( - '--line_plot', help='regular real time plot for single station', required=False, action='store_true') - parser.add_argument( - '--rainbow', help='', required=False, action='store_true') - parser.add_argument( - '--nb_rainbow_colors', help='the numbers of colors for rainbow mode', required=False, default=10) - parser.add_argument( - '--update_time', - help='time in seconds between each graphic update.' - ' The following suffixes can be used as well: "s" for seconds, ' - '"m" for minutes, "h" for hours and "d" for days.', - required=False, default=10, - type=_parse_time_with_suffix_to_seconds) - parser.add_argument('--events', required=False, default=None, type=float, - help='plot events using obspy.neries, specify minimum magnitude') - parser.add_argument( - '--events_update_time', required=False, default=10, - help='time in minutes between each event data update. ' - ' The following suffixes can be used as well: "s" for seconds, ' - '"m" for minutes, "h" for hours and "d" for days.', - type=_parse_time_with_suffix_to_minutes) - parser.add_argument('-f', '--fullscreen', default=False, + p.add_argument('--line_plot', help='regular real time plot for single station' + , action='store_true') + p.add_argument('--rainbow', help='', action='store_true') + p.add_argument('--nb_rainbow_colors', help='the numbers of colors for rainbow mode') + p.add_argument('-f', '--fullscreen', default=False, action="store_true", help='set to full screen on startup') - parser.add_argument('-v', '--verbose', default=False, + p.add_argument('-v', '--verbose', default=False, action="store_true", dest="verbose", help='show verbose debugging output') - parser.add_argument('--force', default=False, action="store_true", + p.add_argument('--force', default=False, action="store_true", help='skip warning message and confirmation prompt ' 'when opening a window without decoration') - # parse the arguments - args = parser.parse_args() - + p.add_argument('--remove_response', default=False, action="store_true", + help='Trys to remove the instrument response') + + args = p.parse_args() + + if args.tick_format == "None": + args.tick_format = None + + if args.events_criteria == "None" or args.events_criteria == None: + args.events_criteria = [] + else: + # converts the string "list" to an actual list with data type float for each element + args.events_criteria = args.events_criteria.split(";") + args.events_criteria= [list(map(float,x.split(","))) for x in args.events_criteria] + + print("=================================================================") + print(args) + print("=================================================================") + + if args.verbose: loglevel = logging.DEBUG else: @@ -651,7 +807,7 @@ def main(): stream = Stream() events = Catalog() lock = threading.Lock() - + # cl is the seedlink client seedlink_client = SeedlinkUpdater(stream, myargs=args, lock=lock) if OBSPY_VERSION < [1, 0]: @@ -660,7 +816,7 @@ def main(): seedlink_client.slconn.set_sl_address(args.seedlink_server) seedlink_client.multiselect = args.seedlink_streams - # tes if drum plot or line plot + # test if drum plot or line plot if any([x in args.seedlink_streams for x in ", ?*"]) or args.line_plot: drum_plot = False if args.time_tick_nb is None: @@ -677,30 +833,48 @@ def main(): args.time_tick_nb = 13 if args.tick_format is None: args.tick_format = '%d/%m/%y %Hh' + + seedlink_client.begin_time = (now - args.backtrace_time).format_seedlink() seedlink_client.initialize() ids = seedlink_client.getTraceIDs() + args.ids = ids # start cl in a thread thread = threading.Thread(target=seedlink_client.run) thread.setDaemon(True) thread.start() - + # start another thread for event updating if requested - if args.events is not None: + if args.events_criteria != []: event_updater = EventUpdater( stream=stream, events=events, myargs=args, lock=lock) thread = threading.Thread(target=event_updater.run) thread.setDaemon(True) thread.start() - + # Wait few seconds to get data for the first plot time.sleep(2) + master = SeedlinkPlotter(stream=stream, events=events, myargs=args, lock=lock, drum_plot=drum_plot, trace_ids=ids) + + # thread to check if connection is still available + connection = Connection(master, myargs=args) + thread = threading.Thread(target=connection.check) + thread.setDaemon(True) + thread.start() + master.mainloop() if __name__ == '__main__': main() + + + + + + +