stream.py 文件源码

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

项目:stfinv 作者: seismology 项目源码 文件源码
def calc_timeshift(self, st_b, allow_negative_CC=False):
        """
        dt_all, CC = calc_timeshift(self, st_b, allow_negative_CC)

        Calculate timeshift between two waveforms using the maximum of the
        cross-correlation function.

        Parameters
        ----------
        self : obspy.Stream
            Stream that contains the reference traces

        st_b : obspy.Stream
            Stream that contains the traces to compare

        allow_negative_CC : boolean
            Pick the maximum of the absolute values of CC(t). Useful,
            if polarity may be wrong.

        Returns
        -------
        dt_all : dict
            Dictionary with entries station.location and the estimated
            time shift in seconds.

        CC : dict
            Dictionary with the correlation coefficients for each station.

        """
        dt_all = dict()
        CC_all = dict()
        for tr_a in self:
            try:
                tr_b = st_b.select(station=tr_a.stats.station,
                                   location=tr_a.stats.location)[0]
                corr = signal.correlate(tr_a.data, tr_b.data)

                if allow_negative_CC:
                    idx_CCmax = np.argmax(abs(corr))
                    CC = abs(corr[idx_CCmax])
                else:
                    idx_CCmax = np.argmax(corr)
                    CC = corr[idx_CCmax]

                dt = (idx_CCmax - tr_a.stats.npts + 1) * tr_a.stats.delta
                CC /= np.sqrt(np.sum(tr_a.data**2) * np.sum(tr_b.data**2))
                # print('%s.%s: %4.1f sec, CC: %f' %
                #       (tr_a.stats.station, tr_a.stats.location, dt, CC))
                code = '%s.%s' % (tr_a.stats.station, tr_a.stats.location)
                dt_all[code] = dt
                CC_all[code] = CC
            except IndexError:
                print('Did not find %s' % (tr_a.stats.station))
        return dt_all, CC_all
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号