当前位置: 首页>>代码示例>>Python>>正文


Python Trace.stats方法代码示例

本文整理汇总了Python中obspy.core.Trace.stats方法的典型用法代码示例。如果您正苦于以下问题:Python Trace.stats方法的具体用法?Python Trace.stats怎么用?Python Trace.stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在obspy.core.Trace的用法示例。


在下文中一共展示了Trace.stats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: conv_traces

# 需要导入模块: from obspy.core import Trace [as 别名]
# 或者: from obspy.core.Trace import stats [as 别名]
def conv_traces(tr1, tr2, normal=True):
    """ Convolve two Traces and merge their meta-information

    It convolves the data stored in two :class:`~obspy.core.trace.Trace`
    Objects in frequency domain. If ``normal==True`` the resulting correlation
    data are normalized by a factor of
    :func:`sqrt(||tr1.data||^2 x ||tr2.data||^2)`

    Meta-informations associated to the resulting Trace are obtained through:

        - Merging the original meta-informations of the two input traces
          according to the :func:`~miic.core.corr_fun.combine_stats` function.

        - Adding the original two `Stats` objects to the newly
          created :class:`~obspy.core.trace.Trace` object as:
          >>> conv_tr.stats_tr1 = tr1.stats
          >>> conv_tr.stats_tr2 = tr2.stats
        - Fixing:
          >>> conv_tr.stats['npts'] = '...number of correlation points...'
          >>> conv_tr.stats['starttime'] = tr2.stats['starttime'] -
              tr1.stats['starttime']

    :type tr1: :class:`~obspy.core.trace.Trace`
    :param tr1: First Trace
    :type tr2: :class:`~obspy.core.trace.Trace`
    :param tr2: Second Trace
    :type normal: bool
    :param normal: Normalization flag

    :rtype: :class:`~obspy.core.trace.Trace`
    :return: **conv_tr**: Trace that stores convolved data and meta-information

    """

    if not isinstance(tr1, Trace):
        raise TypeError("tr1 must be an obspy Trace object.")

    if not isinstance(tr2, Trace):
        raise TypeError("tr2 must be an obspy Trace object.")
    
    zerotime = UTCDateTime(1971, 1, 1, 0, 0, 0)
    conv_tr = Trace()

    # extend traces to the next power of 2 of the longest trace
    lt = pow(2, np.ceil(np.log2(np.max([tr1.stats['npts'],
             tr2.stats['npts']]))))
    s1 = extend(tr1.data, method='zeros', length='fixed',size=lt)
    s2 = extend(tr2.data, method='zeros', length='fixed',size=lt)

    # create the combined stats
    conv_tr.stats = combine_stats(tr1, tr2)
    conv_tr.stats_tr1 = tr1.stats
    conv_tr.stats_tr2 = tr2.stats

    conv_tr.stats_tr1.npts = min(tr1.stats.npts, tr2.stats.npts)
    conv_tr.stats_tr2.npts = min(tr1.stats.npts, tr2.stats.npts)

    if normal:
        denom = np.sqrt(np.dot(s1.astype(np.float64), s1.T) *
                        np.dot(s2.astype(np.float64), s2.T))
    else:
        denom = 1.

    # remaining offset in samples (just remove fractions of samples)
    roffset = np.round((tr2.stats.starttime - tr1.stats.starttime) *
                        tr1.stats.sampling_rate)
    offset = (tr2.stats.starttime - tr1.stats.starttime) * \
        tr1.stats.sampling_rate - roffset
    # remaining offset in seconds
    roffset /= tr1.stats.sampling_rate


    convData = _fftconvolve(s1[::-1], s2, offset)
    convData = np.multiply(convData, (1 / denom))
    
    # set number of samples
    conv_tr.stats['npts'] = convData.shape[0]

    # time lag of the zero position, i.e. lag time of alignent
    t_offset_zeroleg = (float(convData.shape[0]) - 1.) / \
        (2. * tr1.stats.sampling_rate)

    # set starttime
    conv_tr.stats['starttime'] = zerotime - t_offset_zeroleg + \
        roffset

    conv_tr.data = convData

    return conv_tr
开发者ID:miic-sw,项目名称:miic,代码行数:91,代码来源:corr_fun.py

示例2: is_masked

# 需要导入模块: from obspy.core import Trace [as 别名]
# 或者: from obspy.core.Trace import stats [as 别名]
    if samples_before_start and samples_before_start > result[0]:
        result[0] = samples_before_start
    if samples_after_end and samples_after_end > result[-1]:
        result[-1] = samples_after_end
    if lost_samples and first_spot > result[empty_spots]:
        result[empty_spots] = first_spot
    if free_samples and end_samples > result[empty_spots + spots]:
        result[empty_spots + spots] = end_samples


    # Check for masked values.
    if is_masked(result):
        result.fill_value = 0.0
        result = result.filled()

    # Create new stream.
    tr = Trace(data = result)
    stats = st[0].stats
    stats.starttime = day_starttime
    # Hard code the sampling rate for safe handling of leap seconds and
    # floating point inaccuracies. This will result in 1000 samples with the
    # last sample exactly one delta step away from the beginning of the next
    # day.
    stats.sampling_rate = 0.0115740740741
    stats.npts = 1000
    tr.stats = stats
    out_stream = Stream(traces = [tr])
    # Write the stream.
    out_stream.write (file + '_index.mseed', format = 'MSEED')

开发者ID:obspy,项目名称:branches,代码行数:31,代码来源:index_files.py


注:本文中的obspy.core.Trace.stats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。