def test_get_stream_gaps(): """TimeseriesUtility_test.test_get_stream_gaps() confirms that gaps are found in a stream """ stream = Stream([ __create_trace('H', [numpy.nan, 1, 1, numpy.nan, numpy.nan]), __create_trace('Z', [0, 0, 0, 1, 1, 1]) ]) for trace in stream: # set time of first sample trace.stats.starttime = UTCDateTime('2015-01-01T00:00:00Z') # set sample rate to 1 second trace.stats.delta = 1 # find gaps gaps = TimeseriesUtility.get_stream_gaps(stream) assert_equals(len(gaps['H']), 2) # gap at start of H gap = gaps['H'][0] assert_equals(gap[0], UTCDateTime('2015-01-01T00:00:00Z')) assert_equals(gap[1], UTCDateTime('2015-01-01T00:00:00Z')) # gap at end of H gap = gaps['H'][1] assert_equals(gap[0], UTCDateTime('2015-01-01T00:00:03Z')) assert_equals(gap[1], UTCDateTime('2015-01-01T00:00:04Z')) # no gaps in Z channel assert_equals(len(gaps['Z']), 0)
def test_get_stream_gaps(): """TimeseriesUtility_test.test_get_stream_gaps() confirms that gaps are found in a stream """ stream = Stream([ __create_trace('H', [numpy.nan, 1, 1, numpy.nan, numpy.nan]), __create_trace('Z', [0, 0, 0, 1, 1, 1]) ]) for trace in stream: # set time of first sample trace.stats.starttime = UTCDateTime('2015-01-01T00:00:00Z') # set sample rate to 1 second trace.stats.delta = 1 # find gaps gaps = TimeseriesUtility.get_stream_gaps(stream) assert_equals(len(gaps['H']), 2) # gap at start of H gap = gaps['H'][0] assert_equals(gap[0], UTCDateTime('2015-01-01T00:00:00Z')) assert_equals(gap[1], UTCDateTime('2015-01-01T00:00:00Z')) # gap at end of H gap = gaps['H'][1] assert_equals(gap[0], UTCDateTime('2015-01-01T00:00:03Z')) assert_equals(gap[1], UTCDateTime('2015-01-01T00:00:04Z')) # no gaps in Z channel assert_equals(len(gaps['Z']), 0)
def test_get_stream_gaps_channels(): """TimeseriesUtility_test.test_get_stream_gaps_channels() test that gaps are only checked in specified channels. """ stream = Stream([ __create_trace("H", [numpy.nan, 1, 1, numpy.nan, numpy.nan]), __create_trace("Z", [0, 0, 0, 1, 1, 1]), ]) for trace in stream: # set time of first sample trace.stats.starttime = UTCDateTime("2015-01-01T00:00:00Z") # set sample rate to 1 second trace.stats.delta = 1 # find gaps gaps = TimeseriesUtility.get_stream_gaps(stream, ["Z"]) assert_equal("H" in gaps, False) assert_equal(len(gaps["Z"]), 0)
def test_get_stream_gaps_channels(): """TimeseriesUtility_test.test_get_stream_gaps_channels() test that gaps are only checked in specified channels. """ stream = Stream stream = Stream([ __create_trace('H', [numpy.nan, 1, 1, numpy.nan, numpy.nan]), __create_trace('Z', [0, 0, 0, 1, 1, 1]) ]) for trace in stream: # set time of first sample trace.stats.starttime = UTCDateTime('2015-01-01T00:00:00Z') # set sample rate to 1 second trace.stats.delta = 1 # find gaps gaps = TimeseriesUtility.get_stream_gaps(stream, ['Z']) assert_equals('H' in gaps, False) assert_equals(len(gaps['Z']), 0)
def print_observatories(args): """Print all the observatories Parameters --------- args: dictionary Holds all the command line arguments. See parse_args Returns ------- Boolean: if a warning was issued. """ intervals = args.intervals channels = args.channels starttime = args.starttime endtime = args.endtime host = args.edge_host table_header = get_table_header() warning_issued = False table_end = \ '</tbody>\n' + \ '</table>\n' for observatory in args.observatories: summary_table = '' gap_details = '' print_it = False summary_header = '<p>Observatory: %s </p>\n' % observatory summary_table += table_header for interval in intervals: factory = edge.EdgeFactory(host=host, port=2060, observatory=observatory, type=args.type, channels=channels, locationCode=args.locationcode, interval=interval) timeseries = factory.get_timeseries(starttime=starttime, endtime=endtime) gaps = TimeseriesUtility.get_stream_gaps(timeseries) if args.gaps_only and not has_gaps(gaps): continue else: print_it = True warning = '' warning_threshold = calculate_warning_threshold( args.warning_threshold, interval) summary_table += '<tr>' summary_table += '<td style="text-align:center;">' summary_table += ' %sS \n </td></tr>\n' % interval.upper() gap_details += ' %sS <br>\n' % interval.upper() for channel in channels: gap = gaps[channel] trace = timeseries.select(channel=channel)[0] total = get_gap_total(gap, interval) percentage, count = calculate_gap_percentage(total, trace) last = get_last_time(gap, endtime) summary_table += '<tr>\n' summary_table += '<td style="text-align:center;">%s</td>' % \ channel summary_table += '<td style="text-align:center;">%s</td>' % \ format_time(last) summary_table += '<td style="text-align:center;">%d</td>' % \ len(gap) summary_table += '<td style="text-align:center;">%d %s</td>' \ % (total, interval) summary_table += '<td style="text-align:center;">%0.2f%%</td>'\ % percentage summary_table += '<td style="text-align:center;">%d</td>' \ % count summary_table += '</tr>\n' if endtime - last > warning_threshold: warning += '%s ' % channel warning_issued = True # Gap Detail gap_details += ' Channel: %s <br>\n' % channel gap_details += get_gaps(gap) + '\n' if len(warning): summary_header += 'Warning: Channels older then ' + \ 'warning-threshold ' + \ '%s %ss<br>\n' % (warning, interval) summary_table += table_end if print_it: print(summary_header) print(summary_table) print(gap_details) return warning_issued
def print_observatories(args): """Print all the observatories Parameters --------- args: dictionary Holds all the command line arguments. See parse_args Returns ------- Boolean: if a warning was issued. """ intervals = args.intervals channels = args.channels starttime = args.starttime endtime = args.endtime host = args.edge_host table_header = get_table_header() warning_issued = False table_end = \ '</tbody>\n' + \ '</table>\n' for observatory in args.observatories: summary_table = '' gap_details = '' print_it = False summary_header = '<p>Observatory: %s </p>\n' % observatory summary_table += table_header for interval in intervals: factory = edge.EdgeFactory( host=host, port=2060, observatory=observatory, type=args.type, channels=channels, locationCode=args.locationcode, interval=interval) timeseries = factory.get_timeseries( starttime=starttime, endtime=endtime) gaps = TimeseriesUtility.get_stream_gaps(timeseries) if args.gaps_only and not has_gaps(gaps): continue else: print_it = True warning = '' warning_threshold = calculate_warning_threshold( args.warning_threshold, interval) summary_table += '<tr>' summary_table += '<td style="text-align:center;">' summary_table += ' %sS \n </td></tr>\n' % interval.upper() gap_details += ' %sS <br>\n' % interval.upper() for channel in channels: gap = gaps[channel] trace = timeseries.select(channel=channel)[0] total = get_gap_total(gap, interval) percentage, count = calculate_gap_percentage(total, trace) last = get_last_time(gap, endtime) summary_table += '<tr>\n' summary_table += '<td style="text-align:center;">%s</td>' % \ channel summary_table += '<td style="text-align:center;">%s</td>' % \ format_time(last) summary_table += '<td style="text-align:center;">%d</td>' % \ len(gap) summary_table += '<td style="text-align:center;">%d %s</td>' \ % (total, interval) summary_table += '<td style="text-align:center;">%0.2f%%</td>'\ % percentage summary_table += '<td style="text-align:center;">%d</td>' \ % count summary_table += '</tr>\n' if endtime - last > warning_threshold: warning += '%s ' % channel warning_issued = True # Gap Detail gap_details += ' Channel: %s <br>\n' % channel gap_details += get_gaps(gap) + '\n' if len(warning): summary_header += 'Warning: Channels older then ' + \ 'warning-threshold ' + \ '%s %ss<br>\n' % (warning, interval) summary_table += table_end if print_it: print summary_header print summary_table print gap_details return warning_issued