From 422a1ad351badd327b5679c64c382c15ab1a2735 Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Mon, 21 Jan 2019 09:46:05 +0100 Subject: [PATCH 1/7] Initial Commit for the Branch 'Config_File_and_Event_Criterias'. This commit contains all the changes necessary to use a Configuration File to set up all settings. It is still possible to use the command line to change the settings. The commit contains changes in the way events are handled as well. It is now possible to give more than one Criteria for Events. A minimum and a maximum Magnitude for a minimum and maximum distance. And the event times are now corrected for the runtime. So the time you see is the first arrival at your station. --- seedlink_plotter/config_drum.txt | 133 ++++++++++ seedlink_plotter/config_line.txt | 132 ++++++++++ seedlink_plotter/config_line_multiple.txt | 133 ++++++++++ seedlink_plotter/seedlink_plotter.py | 284 ++++++++++++++++------ 4 files changed, 606 insertions(+), 76 deletions(-) create mode 100644 seedlink_plotter/config_drum.txt create mode 100644 seedlink_plotter/config_line.txt create mode 100644 seedlink_plotter/config_line_multiple.txt 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..245e42f 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -18,12 +18,22 @@ 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 +# to parse through all stations +from obspy.clients.fdsn.header import URL_MAPPINGS + +# get settings +import configargparse +from argparse import ArgumentDefaultsHelpFormatter + from math import sin import threading import time @@ -222,6 +232,16 @@ 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 +249,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, @@ -252,7 +272,10 @@ def plot_lines(self, stream): # single traces of one id together. for tr in stream: tr.stats.processing = [] - stream.plot(fig=fig, method="fast", draw=False, equal_scale=False, + if len(tr.data) < 5: # otherwise emty streams make problems with equal scale + tr.data = np.array([0.000000000000000000001]) + + stream.plot(fig=fig, method="fast", draw=False, equal_scale=self.args.equal_scale, size=(self.args.x_size, self.args.y_size), title="", color='Blue', tick_format=self.args.tick_format, number_of_ticks=self.args.time_tick_nb) @@ -474,9 +497,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 +561,31 @@ 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): """ @@ -546,90 +645,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: @@ -660,7 +792,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: From 33ea8106f053bc9d43821db92dbe852ce1708ed3 Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Thu, 21 Feb 2019 16:07:12 +0100 Subject: [PATCH 2/7] Changing code to adhere mostly to PEP8. Fixing a few minor bugs. --- seedlink_plotter/seedlink_plotter.py | 189 +++++++++++++-------------- 1 file changed, 94 insertions(+), 95 deletions(-) diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index 245e42f..04328e6 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -99,7 +99,7 @@ def format_seedlink(self): try: SLPacket.get_type except AttributeError: - # create the new get_type fonction using the old getType method + # create the new get_type fonction using the old getType method def get_type(self): return self.getType() # add the function in the class @@ -108,7 +108,7 @@ def get_type(self): try: SLPacket.get_trace except AttributeError: - # create the new get_trace fonction using the old getTrace method + # create the new get_trace fonction using the old getTrace method def get_trace(self): return self.getTrace() # add the function in the class @@ -133,7 +133,7 @@ def __init__(self, stream=None, events=None, myargs=None, lock=None, self._bind_keys() args = myargs self.lock = lock - ### size and position + # size and position self.geometry(str(args.x_size) + 'x' + str(args.y_size) + '+' + str( args.x_position) + '+' + str(args.y_position)) w, h, pad = self.winfo_screenwidth(), self.winfo_screenheight(), 3 @@ -238,7 +238,7 @@ def plot_drum(self, stream): # adjust scale if self.args.relative_scale: - scale = max(stream.std())*self.args.scale + scale = max(stream.std()) * self.args.scale else: scale = self.args.scale @@ -375,7 +375,6 @@ def __init__(self, stream, myargs=None, lock=None): self.lock = lock self.args = myargs - def packet_handler(self, count, slpack): """ for compatibility with obspy 0.10.3 renaming @@ -499,50 +498,50 @@ def get_events(self): end = max([tr.stats.endtime for tr in self.stream]) 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"]: + + # get the coordinates 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_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 - - + pass + # search for events fullfilling each criteria for criteria in self.args.events_criteria: - print("Search for events with criteria" + str(criteria)) + print("Search for events with criteria " + str(criteria)) temp_catalog = Catalog() for client in URL_MAPPINGS.keys(): try: - cli = Client(client) + client = 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]) + t = client.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") + if temp_catalog.count() == 0: + print("No events found for the current settings " + str(criteria) + "\n") else: - print(str(temp_catalog.count()) + " events found" ) + 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: @@ -550,8 +549,6 @@ def get_events(self): 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): @@ -568,21 +565,21 @@ def event_time_to_arrival_time(self, events, lat, long): """ 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) + 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) + 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") + print("Correcting event " + str(event) + "not possible \n") return events @@ -645,6 +642,7 @@ 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. @@ -661,107 +659,107 @@ def get_station_name(trace): def main(): p = configargparse.ArgParser(default_config_files=['/*.txt'], prog='seedlink_plotter', - description='Plot a realtime seismogram of a station', - formatter_class=ArgumentDefaultsHelpFormatter) + description='Plot a realtime seismogram of a station', + formatter_class=ArgumentDefaultsHelpFormatter) 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('-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('--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('--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('--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 ') + 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]') + 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('--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 ' + 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.', - type=_parse_time_with_suffix_to_seconds) + type=_parse_time_with_suffix_to_seconds) 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.') + 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') + help='the x position of the graph') p.add_argument('--y_position', type=int, - help='the y position of the graph') + 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('--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.')) p.add_argument('--line_plot', help='regular real time plot for single station' - , action='store_true') + , 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') + action="store_true", + help='set to full screen on startup') p.add_argument('-v', '--verbose', default=False, - action="store_true", dest="verbose", - help='show verbose debugging output') + action="store_true", dest="verbose", + help='show verbose debugging output') p.add_argument('--force', default=False, action="store_true", - help='skip warning message and confirmation prompt ' - 'when opening a window without decoration') + help="skip warning message and confirmation prompt " + "when opening a window without decoration") p.add_argument('--remove_response', default=False, action="store_true", - help='Trys to remove the instrument response') + 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: + if args.events_criteria == "None" or args.events_criteria is 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] + 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: @@ -819,7 +817,7 @@ def main(): thread.start() # start another thread for event updating if requested - if args.events is not None: + if args.events_criteria is not None: event_updater = EventUpdater( stream=stream, events=events, myargs=args, lock=lock) thread = threading.Thread(target=event_updater.run) @@ -834,5 +832,6 @@ def main(): trace_ids=ids) master.mainloop() + if __name__ == '__main__': main() From 114e560fff5faa9d8ab31d42fb1ab22d3c85ebc8 Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Thu, 21 Feb 2019 17:09:26 +0100 Subject: [PATCH 3/7] Change the config files to be more consistent and using *cfg as suffix --- seedlink_plotter/config_drum.txt | 133 ---------------------- seedlink_plotter/config_line.txt | 132 --------------------- seedlink_plotter/config_line_multiple.txt | 133 ---------------------- seedlink_plotter/drum.cfg.txt | 125 ++++++++++++++++++++ seedlink_plotter/line.cfg.txt | 123 ++++++++++++++++++++ seedlink_plotter/line_multiple.cfg.txt | 125 ++++++++++++++++++++ 6 files changed, 373 insertions(+), 398 deletions(-) delete mode 100644 seedlink_plotter/config_drum.txt delete mode 100644 seedlink_plotter/config_line.txt delete mode 100644 seedlink_plotter/config_line_multiple.txt create mode 100644 seedlink_plotter/drum.cfg.txt create mode 100644 seedlink_plotter/line.cfg.txt create mode 100644 seedlink_plotter/line_multiple.cfg.txt diff --git a/seedlink_plotter/config_drum.txt b/seedlink_plotter/config_drum.txt deleted file mode 100644 index 40f75c6..0000000 --- a/seedlink_plotter/config_drum.txt +++ /dev/null @@ -1,133 +0,0 @@ ---- 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 deleted file mode 100644 index 195797c..0000000 --- a/seedlink_plotter/config_line.txt +++ /dev/null @@ -1,132 +0,0 @@ ---- 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 deleted file mode 100644 index 9bee650..0000000 --- a/seedlink_plotter/config_line_multiple.txt +++ /dev/null @@ -1,133 +0,0 @@ ---- 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/drum.cfg.txt b/seedlink_plotter/drum.cfg.txt new file mode 100644 index 0000000..8c64657 --- /dev/null +++ b/seedlink_plotter/drum.cfg.txt @@ -0,0 +1,125 @@ +#Configuration File (Drum Plot) + + +# Regular real time plot for single station. +line_plot = False + + +############################################################################ +# All about the data: + +# The seedlink stream selector string. +# Format:stream1[:selectors1],stream2[:selectors2],... +# "stream" in "NETWORK"_"STATION" format +# "selector" a space separated "list of "LOCATION""CHANNEL" +seedlink_streams=GE_STU:BHZ + +# The seedlink server to connect to with port +seedlink_server=geofon.gfz-potsdam.de:18000 + +# 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. +update_time = 10 + +# Only relevant for day plots +# Sets the plotscale to "max(stream.std()) * scale" +relative_scale = True + +# Only relevant for day plots. +# Scale to apply on the data. +# Relative scale True: The plot scale is dynamically set to the standard deviation times scale +# Relative scale False: The plot scale is directly set to the scale value. +scale=10 + +# Only relevant for multiple line 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. +equal_scale = True + +# 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.' +backtrace_time = 12h + +# If true the programme tries to remove the instrument response +remove_response = True + +############################################################################ +# All about Events + +# 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_criteria = 5,10,0,180;4,10,0,50;2,10,0,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.' +events_update_time = 10 + + +############################################################################ +#All about Layout + +# 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_scale= 60 + +# The x position of the graph +x_position = 200 + +# The y position of the graph +y_position = 50 + +# The x size of the graph +x_size = 800 + +# The y size of the graph +y_size = 600 + +# The title size of each station in multichannel +title_size = 10 + +# The size of time legend in multichannel +time_legend_size = 10 + +# The tick format of time legend +tick_format = None + +# The number of time tick +time_tick_nb = 10 + +# 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. +without-decoration = False + +# Rainbow colours instead of red, blue, green, back in drum plot +rainbow = False + +# Number of different rainbow colours +nb_rainbow_colors = 10 + +# Set to full screen on startup +fullscreen = False + +# show verbose debugging output +verbose = False + +# Skip warning message and confirmation prompt +# when opening a window without decoration' +force = False + + + diff --git a/seedlink_plotter/line.cfg.txt b/seedlink_plotter/line.cfg.txt new file mode 100644 index 0000000..1069595 --- /dev/null +++ b/seedlink_plotter/line.cfg.txt @@ -0,0 +1,123 @@ +#Configuration File (Line Plot) + + +# Regular real time plot for single station. +line_plot = True + + +############################################################################ +# All about the data: + +# The seedlink stream selector string. +# Format:stream1[:selectors1],stream2[:selectors2],... +# "stream" in "NETWORK"_"STATION" format +# "selector" a space separated "list of "LOCATION""CHANNEL" +seedlink_streams=GE_DSB:BHZ + + +# The seedlink server to connect to with port +seedlink_server=geofon.gfz-potsdam.de:18000 + +# 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. +update_time = 1 + +# Only relevant for day plots +# Sets the plotscale to "max(stream.std()) * scale" +relative_scale = True + +# Only relevant for day plots. +# Scale to apply on the data. +# Relative scale True: The plot scale is dynamically set to the standard deviation times scale +# Relative scale False: The plot scale is directly set to the scale value. +scale=10 + +# Only relevant for multiple line 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. +equal_scale = True + +# 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.' +backtrace_time = 10m + +# If true the programme tries to remove the instrument response +remove_response = True + +############################################################################ +# All about Events + +# 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_criteria = None + +# 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.' +events_update_time = 10 + + +############################################################################ +#All about Layout + +# 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_scale= 60 + +# The x position of the graph +x_position = 200 + +# The y position of the graph +y_position = 50 + +# The x size of the graph +x_size = 800 + +# The y size of the graph +y_size = 600 + +# The title size of each station in multichannel +title_size = 10 + +# The size of time legend in multichannel +time_legend_size = 10 + +# The tick format of time legend +tick_format = None + +# The number of time tick +time_tick_nb = 10 + +# 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. +without-decoration = False + +# Rainbow colours instead of red, blue, green, back in drum plot +rainbow = False + +# Number of different rainbow colours +nb_rainbow_colors = 10 + +# Set to full screen on startup +fullscreen = False + +# show verbose debugging output +verbose = False + +# Skip warning message and confirmation prompt +# when opening a window without decoration' +force = False \ No newline at end of file diff --git a/seedlink_plotter/line_multiple.cfg.txt b/seedlink_plotter/line_multiple.cfg.txt new file mode 100644 index 0000000..91a148b --- /dev/null +++ b/seedlink_plotter/line_multiple.cfg.txt @@ -0,0 +1,125 @@ +#Configuration File (Multiple Line Plot) + + +# Regular real time plot for single station. +line_plot = True + + +############################################################################ +# All about the data: + +# The seedlink stream selector string. +# Format:stream1[:selectors1],stream2[:selectors2],... +# "stream" in "NETWORK"_"STATION" format +# "selector" a space separated "list of "LOCATION""CHANNEL" +seedlink_streams=G_FDF:00BHZ 00BHN 00BHE,G_SSB:00BHZ 00BHN 00BHE,G_MBO:00BHZ 00BHE 00BHN + + + +# The seedlink server to connect to with port +seedlink_server=rtserver.ipgp.fr:18000 + + +# 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. +update_time = 1 + +# Only relevant for day plots +# Sets the plotscale to "max(stream.std()) * scale" +relative_scale = True + +# Only relevant for day plots. +# Scale to apply on the data. +# Relative scale True: The plot scale is dynamically set to the standard deviation times scale +# Relative scale False: The plot scale is directly set to the scale value. +scale=10 + +# Only relevant for multiple line 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. +equal_scale = True + +# 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.' +backtrace_time = 10m + +# If true the programme tries to remove the instrument response +remove_response = True + +############################################################################ +# All about Events + +# 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_criteria = None + +# 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.' +events_update_time = 10 + + +############################################################################ +#All about Layout + +# 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_scale= 60 + +# The x position of the graph +x_position = 200 + +# The y position of the graph +y_position = 50 + +# The x size of the graph +x_size = 800 + +# The y size of the graph +y_size = 600 + +# The title size of each station in multichannel +title_size = 10 + +# The size of time legend in multichannel +time_legend_size = 10 + +# The tick format of time legend +tick_format = None + +# The number of time tick +time_tick_nb = 10 + +# 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. +without-decoration = False + +# Rainbow colours instead of red, blue, green, back in drum plot +rainbow = False + +# Number of different rainbow colours +nb_rainbow_colors = 10 + +# Set to full screen on startup +fullscreen = False + +# show verbose debugging output +verbose = False + +# Skip warning message and confirmation prompt +# when opening a window without decoration' +force = False From 35864a7b3ec0d2feb244d54e25068b12bd98507c Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Thu, 21 Feb 2019 17:15:09 +0100 Subject: [PATCH 4/7] Changing the suffix to be .cft instead of .cfg.txt --- seedlink_plotter/{drum.cfg.txt => drum.cfg} | 0 seedlink_plotter/{line.cfg.txt => line.cfg} | 0 seedlink_plotter/{line_multiple.cfg.txt => line_multiple.cfg} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename seedlink_plotter/{drum.cfg.txt => drum.cfg} (100%) rename seedlink_plotter/{line.cfg.txt => line.cfg} (100%) rename seedlink_plotter/{line_multiple.cfg.txt => line_multiple.cfg} (100%) diff --git a/seedlink_plotter/drum.cfg.txt b/seedlink_plotter/drum.cfg similarity index 100% rename from seedlink_plotter/drum.cfg.txt rename to seedlink_plotter/drum.cfg diff --git a/seedlink_plotter/line.cfg.txt b/seedlink_plotter/line.cfg similarity index 100% rename from seedlink_plotter/line.cfg.txt rename to seedlink_plotter/line.cfg diff --git a/seedlink_plotter/line_multiple.cfg.txt b/seedlink_plotter/line_multiple.cfg similarity index 100% rename from seedlink_plotter/line_multiple.cfg.txt rename to seedlink_plotter/line_multiple.cfg From 92b43398f7944a85f85acac8838ac804692d9b1c Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Fri, 22 Feb 2019 19:34:46 +0100 Subject: [PATCH 5/7] Fixing minor bugs and inconsistencies --- seedlink_plotter/seedlink_plotter.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index 04328e6..fd73e1e 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -270,10 +270,11 @@ def plot_lines(self, stream): fig = self.figure # avoid the differing trace.processing attributes prohibiting to plot # single traces of one id together. - for tr in stream: + for i, tr in enumerate(stream): tr.stats.processing = [] - if len(tr.data) < 5: # otherwise emty streams make problems with equal scale - tr.data = np.array([0.000000000000000000001]) + # otherwise emty streams make problems with equal scale + if len(tr.data) < 5 and len(stream.traces) > 0: + stream.pop(i) stream.plot(fig=fig, method="fast", draw=False, equal_scale=self.args.equal_scale, size=(self.args.x_size, self.args.y_size), title="", @@ -510,7 +511,7 @@ def get_events(self): channel=splitted_ids[0][3], location=splitted_ids[0][2]) - station_latidude = station_inventory[0][0].latitude + station_latitude = station_inventory[0][0].latitude station_longitude = station_inventory[0][0].longitude break except: @@ -524,11 +525,11 @@ def get_events(self): try: client = Client(client) - # get all events within a rdius (in deg) around the station with a minimum magnitude + # get all events within a radius (in deg) around the station with a minimum magnitude t = client.get_events(starttime=start, endtime=end, minmagnitude=criteria[0], maxmagnitude=criteria[1], - latitude=station_latidude, + latitude=station_latitude, longitude=station_longitude, minradius=criteria[2], maxradius=criteria[3]) @@ -546,7 +547,7 @@ def get_events(self): # 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) + events = self.event_time_to_arrival_time(events, station_latitude, station_longitude) except: print("Correcting all events not possible") return events @@ -729,8 +730,8 @@ def main(): 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.')) - p.add_argument('--line_plot', help='regular real time plot for single station' - , action='store_true') + 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, From b35f2a0045c5da5f30a795cc2ec702e0a3bf385c Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Fri, 22 Feb 2019 19:34:46 +0100 Subject: [PATCH 6/7] Fixing minor bugs and inconsistencies --- seedlink_plotter/seedlink_plotter.py | 32 +++++++++------------------- setup.py | 3 ++- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index 04328e6..6bea2fd 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -270,10 +270,11 @@ def plot_lines(self, stream): fig = self.figure # avoid the differing trace.processing attributes prohibiting to plot # single traces of one id together. - for tr in stream: + for i, tr in enumerate(stream): tr.stats.processing = [] - if len(tr.data) < 5: # otherwise emty streams make problems with equal scale - tr.data = np.array([0.000000000000000000001]) + # otherwise emty streams make problems with equal scale + if len(tr.data) < 5 and len(stream.traces) > 0: + stream.pop(i) stream.plot(fig=fig, method="fast", draw=False, equal_scale=self.args.equal_scale, size=(self.args.x_size, self.args.y_size), title="", @@ -510,7 +511,7 @@ def get_events(self): channel=splitted_ids[0][3], location=splitted_ids[0][2]) - station_latidude = station_inventory[0][0].latitude + station_latitude = station_inventory[0][0].latitude station_longitude = station_inventory[0][0].longitude break except: @@ -524,11 +525,11 @@ def get_events(self): try: client = Client(client) - # get all events within a rdius (in deg) around the station with a minimum magnitude + # get all events within a radius (in deg) around the station with a minimum magnitude t = client.get_events(starttime=start, endtime=end, minmagnitude=criteria[0], maxmagnitude=criteria[1], - latitude=station_latidude, + latitude=station_latitude, longitude=station_longitude, minradius=criteria[2], maxradius=criteria[3]) @@ -546,7 +547,7 @@ def get_events(self): # 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) + events = self.event_time_to_arrival_time(events, station_latitude, station_longitude) except: print("Correcting all events not possible") return events @@ -643,19 +644,6 @@ def _parse_time_with_suffix_to_minutes(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(): p = configargparse.ArgParser(default_config_files=['/*.txt'], prog='seedlink_plotter', @@ -729,8 +717,8 @@ def main(): 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.')) - p.add_argument('--line_plot', help='regular real time plot for single station' - , action='store_true') + 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, diff --git a/setup.py b/setup.py index ac7b989..cce6ac9 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,8 @@ 'numpy', 'scipy', 'matplotlib>=1.3.0', - 'obspy>=0.9.0'] + 'obspy>=0.9.0', + 'configargparse'] setup( name="seedlink-plotter", From 963fd65235409e29d47cd009a4b4caaadcf41add Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Sat, 23 Feb 2019 21:19:19 +0100 Subject: [PATCH 7/7] The clients to get station and event data are now specified in the config file. Each event criteria can have its own client. Otherwise minor bugs and inconsistencies especially regarding exceptions were fixed. --- seedlink_plotter/drum.cfg | 15 ++- seedlink_plotter/line.cfg | 14 ++- seedlink_plotter/line_multiple.cfg | 14 ++- seedlink_plotter/seedlink_plotter.py | 164 +++++++++++++++------------ 4 files changed, 130 insertions(+), 77 deletions(-) diff --git a/seedlink_plotter/drum.cfg b/seedlink_plotter/drum.cfg index 8c64657..b27a1ab 100644 --- a/seedlink_plotter/drum.cfg +++ b/seedlink_plotter/drum.cfg @@ -17,6 +17,13 @@ seedlink_streams=GE_STU:BHZ # The seedlink server to connect to with port seedlink_server=geofon.gfz-potsdam.de:18000 +# Specifies the client used to retrieve information for each station. +# If too few or too much are given it only takes the first one. +# Used for correcting event time and removing instrument response. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +station_clients = GFZ + # Time in seconds between each graphic update. # The following suffixes can be used as well: # "s" for seconds, "m" for minutes @@ -56,7 +63,13 @@ remove_response = True # Specify: event_criteria1; event_criteria2; ... # event_criteria1: Minimum_Magnitude, Maximum_magnitude, Minimum_Radius, Maximum_Radius # if no events should show up: None -events_criteria = 5,10,0,180;4,10,0,50;2,10,0,10 +events_criteria = 4,10,0,180;3,10,0,90;2,10,0,50 + +# Specifies the client used to retrieve information for each event criteria. +# If too few or too much are given it only takes the first one. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +events_clients = IRIS,GEONET,EMSC # Time in minutes between each event data update. # The following suffixes can be used as well: diff --git a/seedlink_plotter/line.cfg b/seedlink_plotter/line.cfg index 1069595..dbb14e4 100644 --- a/seedlink_plotter/line.cfg +++ b/seedlink_plotter/line.cfg @@ -14,10 +14,16 @@ line_plot = True # "selector" a space separated "list of "LOCATION""CHANNEL" seedlink_streams=GE_DSB:BHZ - # The seedlink server to connect to with port seedlink_server=geofon.gfz-potsdam.de:18000 +# Specifies the client used to retrieve information for each station. +# If too few or too much are given it only takes the first one. +# Used for correcting event time and removing instrument response. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +station_clients = GFZ + # Time in seconds between each graphic update. # The following suffixes can be used as well: # "s" for seconds, "m" for minutes @@ -59,6 +65,12 @@ remove_response = True # if no events should show up: None events_criteria = None +# Specifies the client used to retrieve information for each event criteria. +# If too few or too much are given it only takes the first one. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +events_clients = IRIS,GEONET,EMSC + # Time in minutes between each event data update. # The following suffixes can be used as well: # "m" for minutes diff --git a/seedlink_plotter/line_multiple.cfg b/seedlink_plotter/line_multiple.cfg index 91a148b..e604d49 100644 --- a/seedlink_plotter/line_multiple.cfg +++ b/seedlink_plotter/line_multiple.cfg @@ -14,11 +14,15 @@ line_plot = True # "selector" a space separated "list of "LOCATION""CHANNEL" seedlink_streams=G_FDF:00BHZ 00BHN 00BHE,G_SSB:00BHZ 00BHN 00BHE,G_MBO:00BHZ 00BHE 00BHN - - # The seedlink server to connect to with port seedlink_server=rtserver.ipgp.fr:18000 +# Specifies the client used to retrieve information for each station. +# If too few or too much are given it only takes the first one. +# Used for correcting event time and removing instrument response. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +station_clients = GFZ # Time in seconds between each graphic update. # The following suffixes can be used as well: @@ -61,6 +65,12 @@ remove_response = True # if no events should show up: None events_criteria = None +# Specifies the client used to retrieve information for each event criteria. +# If too few or too much are given it only takes the first one. +# If none is give the default is "EMSC". No spaces in between !! +# Form: CLIENT1,CLIENT2,CLIENT3,... +events_clients = IRIS,GEONET,EMSC + # Time in minutes between each event data update. # The following suffixes can be used as well: # "m" for minutes diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index 6bea2fd..ddcd4b0 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -463,6 +463,26 @@ def __init__(self, stream, events, myargs=None, lock=None): self.events = events self.args = myargs self.lock = lock + + self.model = TauPyModel(model="iasp91") + # get the coordinates of the station + splitted_ids = [x.split(".") for x in self.args.ids] + # initialize the event clients + self.event_clients = [] + for client in self.args.events_clients: + self.event_clients.append(Client(client)) + # use seedlink id to get network, station, location and channel + try: + client = Client(self.args.station_clients[0]) + station_inventory = client.get_stations(network=splitted_ids[0][0], + station=splitted_ids[0][1], + channel=splitted_ids[0][3], + location=splitted_ids[0][2]) + self.station_latitude = station_inventory[0][0].latitude + self.station_longitude = station_inventory[0][0].longitude + except Exception as error: + print(error) + warn_msg = "The resource identifier already exists and points to " + \ "another object. It will now point to the object " + \ "referred to by the new resource identifier." @@ -500,56 +520,40 @@ def get_events(self): events = Catalog() - # get the coordinates 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_latitude = 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)) + # search for events fulfilling each criteria + for i, criteria in enumerate(self.args.events_criterias): + if len(self.args.events_criterias) != len(self.args.events_clients): + i = 0 + print("Search for events with criteria " + str(criteria) + " with client: " + + str(self.args.events_clients[i])) temp_catalog = Catalog() - for client in URL_MAPPINGS.keys(): - try: - client = Client(client) - - # get all events within a radius (in deg) around the station with a minimum magnitude - t = client.get_events(starttime=start, endtime=end, - minmagnitude=criteria[0], - maxmagnitude=criteria[1], - latitude=station_latitude, - longitude=station_longitude, - minradius=criteria[2], - maxradius=criteria[3]) - if t.count() > temp_catalog.count(): - temp_catalog = t - except: - pass + try: + # get all events within a radius (in deg) around the station with a minimum magnitude + t = self.event_clients[i].get_events(starttime=start, endtime=end, + minmagnitude=criteria[0], + maxmagnitude=criteria[1], + latitude=self.station_latitude, + longitude=self.station_longitude, + minradius=criteria[2], + maxradius=criteria[3]) + if t.count() > temp_catalog.count(): + temp_catalog = t + except Exception as error: + print(error) 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") + print(str(temp_catalog.count()) + " events found \n") # 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_latitude, station_longitude) - except: - print("Correcting all events not possible") + events = self.event_time_to_arrival_time(events, self.station_latitude, self.station_longitude) + except Exception as error: + print("Correcting all events not possible because of: \n") + print(error) return events def update_events(self, events): @@ -566,22 +570,18 @@ def event_time_to_arrival_time(self, events, lat, long): """ 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) - + distance = 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) + arrivals = self.model.get_travel_times(source_depth_in_km=events[event].origins[0].depth / 1000, + distance_in_degree=distance) events[event].origins[0].time = events[event].origins[0].time + arrivals[0].time - - except: - print("Correcting event " + str(event) + "not possible \n") - + except Exception as error: + print("Correcting event " + str(event) + "not possible " + "beacuse of: \n") + print(error) return events @@ -658,31 +658,36 @@ def main(): '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('--station_clients', default="EMSC", type=str, + help='specifies the client used to retrieve information for each station.' + 'If too few or too much are given it only takes the first one.' + 'Used for correcting event time and removing instrument response.' + 'If none is give the default is "EMSC"') 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, + p.add_argument('--events_criterias', default=None, type=str, help='plot events using obspy.neries, ' - 'specify [Minimum_Magnitude, Maximum_magnitude,Minimum_Radius, Maximum_Radius]') - + 'Specify: event_criteria1; event_criteria2; ...' + 'event_criteria1: Minimum_Magnitude, Maximum_magnitude, Minimum_Radius, Maximum_Radius' + 'if no events should show up: None') + p.add_argument('--events_clients', default="EMSC", type=str, + help='specifies the client used to retrieve information for each event criteria.' + 'If too few or too much are given it only takes the first one.' + 'If none is give the default is "EMSC". No spaces in between !!') 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, ' @@ -693,7 +698,6 @@ def main(): 'following suffixes can be used as well: "m" for minutes, ' '"h" for hours and "d" for days.', type=_parse_time_with_suffix_to_seconds) - 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, ' @@ -737,13 +741,28 @@ def main(): if args.tick_format == "None": args.tick_format = None - - if args.events_criteria == "None" or args.events_criteria is None: - args.events_criteria = [] + + # converts the "station_clients" to a usable list + if args.station_clients == "None" or args.station_clients is None: + args.station_clients = ["EMSC"] + else: + # converts the string "list" to an actual list with data type float for each element + args.station_clients = list(map(str, args.station_clients.split(","))) + + # converts the "event_clients" to a usable list + if args.events_clients == "None" or args.events_clients is None: + args.events_clients = ["EMSC"] + else: + # converts the string "list" to an actual list with data type float for each element + args.events_clients = list(map(str, args.events_clients.split(","))) + + # converts the "events_criterias" to a usable list + if args.events_criterias == "None" or args.events_criterias is None: + args.events_criterias = [] 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] + args.events_criterias = args.events_criterias.split(";") + args.events_criterias = [list(map(float, x.split(","))) for x in args.events_criterias] print("=================================================================") print(args) @@ -798,14 +817,13 @@ def main(): seedlink_client.begin_time = (now - args.backtrace_time).format_seedlink() seedlink_client.initialize() - ids = seedlink_client.getTraceIDs() + args.ids = seedlink_client.getTraceIDs() # 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_criteria is not None: + if len(args.events_criterias) > 0: event_updater = EventUpdater( stream=stream, events=events, myargs=args, lock=lock) thread = threading.Thread(target=event_updater.run) @@ -817,7 +835,7 @@ def main(): master = SeedlinkPlotter(stream=stream, events=events, myargs=args, lock=lock, drum_plot=drum_plot, - trace_ids=ids) + trace_ids=args.ids) master.mainloop()