def __create_trace( data, network="NT", station="BOU", channel="H", location="R0", data_interval="second", data_type="interval", ): """ Utility to create a trace containing the given numpy array. Parameters ---------- data: array The array to be inserted into the trace. Returns ------- obspy.core.Stream Stream containing the channel. """ stats = Stats() stats.starttime = UTCDateTime("2019-12-01") stats.delta = TimeseriesUtility.get_delta_from_interval(data_interval) stats.channel = channel stats.station = station stats.npts = len(data) stats.data_interval = data_interval stats.data_type = data_type numpy_data = numpy.array(data, dtype=numpy.float64) return Trace(numpy_data, stats)
def process_step(self, step, stream): """Filters stream for one step. Filters all traces in stream. Parameters ---------- step : array element step holding variables for one filtering operation stream : obspy.core.Stream stream of data to filter Returns ------- out : obspy.core.Stream stream containing 1 trace per original trace. """ # gather variables from step input_sample_period = step["input_sample_period"] output_sample_period = step["output_sample_period"] window = np.array(step["window"]) decimation = int(output_sample_period / input_sample_period) numtaps = len(window) window = window / sum(window) out = Stream() for trace in stream: starttime, data = self.align_trace(step, trace) # check that there is still enough data to filter if len(data) < numtaps: continue filtered = self.firfilter(data, window, decimation) stats = Stats(trace.stats) stats.delta = output_sample_period stats.data_interval = step["data_interval"] stats.data_interval_type = step["data_interval_type"] stats.filter_comments = step["filter_comments"] stats.starttime = starttime stats.npts = len(filtered) trace_out = self.create_trace(stats.channel, stats, filtered) out += trace_out return out
sttime = UTCDateTime(Time_stamps[0]) endtime = UTCDateTime(Time_stamps[len(Time_stamps) - 1]) sttime._set_year(2017) endtime._set_year(2017) sttime._set_month(8) endtime._set_month(8) sttime._set_day(13 + UTCDateTime(Time_stamps[0]).day) endtime._set_day(13 + UTCDateTime(Time_stamps[len(Time_stamps) - 1]).day) # Define stats stats = Stats() stats.starttime = sttime stats.station = station stats.network = 'NT' stats.location = 'R0' stats.data_interval = '256Hz' stats.delta = .00390625 stats.data_type = 'variation' # Create list of arrays and channel names and intialize counter k arrays = [Hx, Hy, Ex, Ey] k = 0 # Loop over channels to create an obspy stream of the data for ar in arrays: stats.npts = len(ar) stats.channel = channels[k] ar = np.asarray(ar) trace = Trace(ar, stats) stream += trace trace = None