traces.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:stream2segment 作者: rizac 项目源码 文件源码
def maxabs(trace, starttime=None, endtime=None):
    """Returns the maximum of the absolute values of `trace`, and its occurrence time.
    In other words, returns the point `(time, value)` where `value = max(abs(trace.data))`
    and time (`UTCDateTime`) is the time occurrence of `value`

    :param trace: the input obspy.core.Trace
    :param starttime: (`obspy.UTCDateTime`) the start time (None or missing defaults to the trace
        end): the maximum of the trace `abs` will be searched *from* this time. This argument,
        if provided, does not affect the
        returned `time` which will be always relative to the trace passed as argument
    :param endtime: an obspy UTCDateTime object (or any value
        `UTCDateTime` accepts, e.g. integer / `datetime` object) denoting
        the end time (None or missing defaults to the trace end): the maximum of the trace `abs`
        will be searched *until* this time
        :return: the tuple (time, value) where `value = max(abs(trace.data))`, and time is
        the value occurrence (`UTCDateTime`)

    :return: the tuple `(time_of_max_abs, max_abs)`
    """
    original_stime = None if starttime is None else trace.stats.starttime
    if starttime is not None or endtime is not None:
        # from the docs: "this returns a New Trace object
        # Does not copy data but just passes a reference to it"
        trace = trace.slice(starttime, endtime)
    if trace.stats.npts < 1:
        return np.nan
    idx = np.nanargmax(np.abs(trace.data))
    val = trace.data[idx]
    tdelta = 0 if original_stime is None else trace.stats.starttime - original_stime
    time = timeof(trace, idx) + tdelta
    return (time, val)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号