Coverage for /opt/obspy/update-docs/src/obspy/obspy/realtime/signal : 86%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- Signal processing functions for RtMemory objects.
For sequential packet processing that requires memory (which includes recursive filtering), each processing function (e.g., :mod:`obspy.realtime.signal`) needs to manage the initialization and update of :class:`~obspy.realtime.rtmemory.RtMemory` object(s), and needs to know when and how to get values from this memory.
For example: Boxcar smoothing: For each new data point available past the end of the boxcar, the original, un-smoothed data point value at the beginning of the boxcar has to be subtracted from the running boxcar sum, this value may be in a previous packet, so has to be retrieved from memory see :func:`obspy.realtime.signal.boxcar`.
:copyright: The ObsPy Development Team (devs@obspy.org) & Anthony Lomax :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """
""" Scale array data samples by specified factor.
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type factor: float, optional :param factor: Scale factor (default is 1.0). :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
""" Apply simple rectangular integration to array data.
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
return sample
# initialize memory object memory_size_output, 0, 0)
""" Apply simple differentiation to array data.
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
return(sample)
# initialize memory object memory_size_output, 0, 0) # avoid large diff value for first output sample
""" Apply boxcar smoothing to data in array sample.
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type width: int :param width: Width in number of sample points for filter. :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
msg = "width parameter not specified or < 1." raise ValueError(msg)
# initialize memory object memory_size_output, 0, 0)
# initialize array for time-series results
else: else: # later passes, update sum else: value = rtmemory.input[width + i2] else: else: new_sample[i] = 0.0
""" Calculate instantaneous period in a fixed window (Tau_c).
.. seealso::
Implements equations 1-3 in [Allen2003]_ except use a fixed width window instead of decay function.
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type width: int :param width: Width in number of sample points for tauc window. :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
msg = "tauc: width parameter not specified or < 1." raise ValueError(msg)
# initialize memory object memory_size_output, 0, 0) else:
# initialize memory object memory_size_output, 0, 0)
#sample_last = rtmemory.input[width - 1]
+ sample_d * sample_d + deriv_d * deriv_d else: + sample_d * sample_d - rtmemory_dval.input[index] * rtmemory_dval.input[index] \ + deriv_d * deriv_d # if (xval > _MIN_FLOAT_VAL & & dval > _MIN_FLOAT_VAL) { else:
# update memory
# memory object indices for storing specific values
rtmemory_list=None): """ Calculate Mwp integral on a displacement trace.
.. seealso:: [Tsuboi1999]_ and [Tsuboi1995]_
:type trace: :class:`~obspy.core.trace.Trace` :param trace: :class:`~obspy.core.trace.Trace` object to append to this RtTrace :type max_time: float :param max_time: Maximum time in seconds after ref_time to apply Mwp integration. :type ref_time: :class:`~obspy.core.utcdatetime.UTCDateTime` :param ref_time: Reference date and time of the data sample (e.g. P pick time) at which to begin Mwp integration. :type mem_time: float, optional :param mem_time: Length in seconds of data memory (must be much larger than maximum delay between pick declaration and pick time). Defaults to ``1.0``. :type gain: float, optional :param gain: Nominal gain to convert input displacement trace to meters of ground displacement. Defaults to ``1.0``. :type rtmemory_list: list of :class:`~obspy.realtime.rtmemory.RtMemory`, optional :param rtmemory_list: Persistent memory used by this process for specified trace. :rtype: NumPy :class:`numpy.ndarray` :return: Processed trace data from appended Trace object. """ msg = "trace parameter must be an obspy.core.trace.Trace object." raise ValueError(msg)
msg = "ref_time must be an obspy.core.utcdatetime.UTCDateTime object." raise ValueError(msg)
msg = "max_time parameter not specified or < 0." raise ValueError(msg)
# initialize memory object memory_size_output, 0, 0)
(ref_time - trace.stats.starttime) * trace.stats.sampling_rate))
# set reference amplitude # value in trace data array # value in memory array and not rtmemory.output[_HAVE_USED_MEMORY]: msg = "mem_time not large enough to buffer required input data." raise ValueError(msg) else: # set Mwp end index corresponding to maximum duration # apply double integration, check for extrema elif n >= -(np.size(rtmemory.input)): # value in memory array index = n + np.size(rtmemory.input) amplitude = rtmemory.input[index] else: msg = "Error: Mwp: attempt to access rtmemory.input array of " + \ "size=%d at invalid index=%d: this should not happen!" % \ (np.size(rtmemory.input), n + np.size(rtmemory.input)) print msg continue # should never reach here # check displacement polarity # check if past extremum # check if past extremum
# update memory
# 4.213e19 - Tsuboi 1995, 1999 # http://mail.python.org/pipermail/python-list/2010-February/1235196.html, ff. except AttributeError: FLOAT_MIN = 1.1e-37
""" Calculate Mwp magnitude.
.. seealso:: [Tsuboi1999]_ and [Tsuboi1995]_
:type peak: float :param peak: Peak value of integral of displacement seismogram. :type epicentral_distance: float :param epicentral_distance: Great-circle epicentral distance from station in degrees. :rtype: float :returns: Calculated Mwp magnitude. """ |