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)
评论列表
文章目录