From 422a1ad351badd327b5679c64c382c15ab1a2735 Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Mon, 21 Jan 2019 09:46:05 +0100 Subject: [PATCH 1/2] 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 eddd5c1a0ce18ece9ae503edf72d1afab79af71b Mon Sep 17 00:00:00 2001 From: Dominik Strutz Date: Mon, 21 Jan 2019 10:28:34 +0100 Subject: [PATCH 2/2] Initial commit for the branch 'remove_response'. The instrument response of all incoming traces are now removed. Subbranch because the option to activate/deactivate this feature are in the config file branch. --- seedlink_plotter/seedlink_plotter.py | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/seedlink_plotter/seedlink_plotter.py b/seedlink_plotter/seedlink_plotter.py index 245e42f..04f744e 100755 --- a/seedlink_plotter/seedlink_plotter.py +++ b/seedlink_plotter/seedlink_plotter.py @@ -374,6 +374,7 @@ def __init__(self, stream, myargs=None, lock=None): self.stream = stream self.lock = lock self.args = myargs + self.response = {} def packet_handler(self, count, slpack): @@ -413,6 +414,46 @@ def packetHandler(self, count, slpack): # process packet data trace = slpack.get_trace() + global last_trace + last_trace = UTCDateTime() + + """ + Routine to remove the instrument response + """ + if self.args.remove_response == True: #check if the repsonse needs to be removed + station_network, station_station = trace.stats.network, trace.stats.station + station_location, station_channel = trace.stats.location, trace.stats.channel + name = get_station_name(trace) # returns a seedlink like name for reference in a dictionary later + if name not in self.response: #first check if the response function is already available + found = False + for client in ["iris-federator","eida-routing"]: #parse throught the available clients + try: + Client = RoutingClient(client) + inventory = Client.get_stations(network = station_network, + station = station_station, + channel = station_channel, + location = station_location, + level="response") + + self.response[name] = inventory # dictionary with {"Trace_Name": Response_Obejct } + found = True + print(str(name) + " succsessfull") + break # if found break loop and continue + except: + pass + if not found: + print("No response function found for " +str(name)) + else: + found = True + + if found and name in self.response: #only try to remove the response if its available + try: + pre_filt = (0.005, 0.006, 30.0, 35.0) + trace.remove_response(inventory = self.response[name][0], output = "VEL", + zero_mean = True, pre_filt=pre_filt) + except: + print("Removing Response not possible for " + str(trace.stats.name)) + if trace is None: logging.info( self.__class__.__name__ + ": blockette contains no trace")