tiskitpy.TimeSpans
- class tiskitpy.TimeSpans(spans: list | None = None, start_times: list | None = None, end_times: list | None = None)
Bases:
objectA class specifying time spans, to be removed, kept, zeroed, etc.
Times are obspy UTCDateTimes
You can initialize using:
A list of (start_time, end_time) pairs (start_time and end_time can be any input to UTCDateTime, including UTCDateTime)
- or -
A list of UTCDateTime start_times and a list of UTCDateTime end_times (the lists must be the same length)
- append(new_time_spans)
Combines two TimeSpans objects (REPLACED BY COMBINE)
- Parameters:
new_time_spans (
TimeSpans) – object to combine with self
- combine(new_time_spans)
Combines two TimeSpan objects, keeping everything in either
- Parameters:
new_time_spans (
TimeSpans) – object to combine with self
- cutout(inp, plot=False)
Cut out data in the indicated time spans. Actually, it seems just to set the values to zero
- Parameters:
inp (
obspy.core.Stream) – seismological data- Returns:
obspy.core.Stream
- property end_times
list of span start times
- classmethod from_eqs(time_bounds, minmag=5.85, days_per_magnitude=1.5, eq_file=None, save_eq_file=True)
Generate timespans to avoid because of earthquakes.
Will read earthquakes from the USGS online catalog the first time, saving the information to a file that can be subsequently used
- Parameters:
time_bounds (tuple,
obspy.stream.Streamorobspy.stream.Trace) –time bounds to use. Bounds are forced to be beginning (startime) and end (endtime) of a day:
if tuple: (starttime, endtime) as
UTCDateTimeor ISO8601-compatible stringif
obspy.stream.Trace: the trace’s starttime and endtime
if
obspy.stream.Stream: earliest trace starttime and latest trace endtime
minmag (float) – EQ Magnitude above which to cut out times
days_per_magnitude (float) – days to cut per magnitude above min_magnitude
eq_file (str) – the eq filename (otherwise, generates it)
save_eq_file (bool) – save the catalog file for future use
- Returns:
time spans covering EQ signal
- Return type:
eq_spans (
TimeSpans)
- has_zeros(starttime, endtime)
Does the given time span intersect any of the TimeSpans?
- Parameters:
starttime (UTCDateTime) – start time
endtime (UTCDateTime) – end time
- Return type:
(bool)
- interp(inp, plot=False)
Interpolate data from the start to end values in each time span
- Parameters:
inp (Trace or
obspy.core.Stream) – seismological dataplot – plot traces with spans cut out
- Returns:
trace with interpolated data in each time span
- invert(ts_starttime, ts_endtime)
Return inverted time spans
If input TimeSpan had spans from A->A’’, B->B’and C->C’’, output TimeSpan will have spans from ts_starttime->A, A’->B, B’->C and C’->ts_endtime if ts_starttime < A and ts_endtime > B. If ts_start_time -> ts_endtime, is outside of the time spans, will simply use them for the time span
- Parameters:
ts_startime (
obspy.core.UTCDateTime) – timeseries start time. If None, inverted TimeSpans will start at the first end_timets_startime – timeseries end time. If None, inverted TimeSpans will end at the last start_time
- Returns:
- plot(stream=None, color='red', alpha=0.25, title=None, **kwargs)
Make a stream or trace plot with highlighted time spans
- Parameters:
stream (
obspy.core.trace.Streamorobspy.core.trace.Trace) – obspy stream/trace to plotcolor (str) – highlight color
alpha (float) – highlight transparency alpha (1=opaque, 0 = invisible)
title (str) – figure title
kwargs (dict) – arguments to stream/trace plot program
- Returns:
fig (matplotlib Figure): ax (list): list of axes
- Return type:
(tuple)
- property spans
list of spans [start_time, end_time]
- split(in_stream, merge=True, plot=False)
Returns a Stream containing only the specified time spans
- Parameters:
inp (
obspy.core.Traceorobspy.core.Stream) – seismological datamerge (bool) – Merge traces with the same seed_id into masked arrays.
plot – plot result
- Returns:
obspy.core.Stream
- property start_times
list of span start times
- zero(inp, plot=False)
Zero out data in the time spans
- Parameters:
inp (
obspy.core.Traceorobspy.core.Stream) – seismological dataplot – plot data with spans cut out
- Returns:
obspy.core.Traceorobspy.core.Stream