wavelength.py 文件源码

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

项目:goodman 作者: soar-telescope 项目源码 文件源码
def cross_correlation(self, reference, new_array, mode='full'):
        """Do cross correlation to two arrays

        Args:
            reference (array): Reference array.
            new_array (array): Array to be matched.
            mode (str): Correlation mode for `scipy.signal.correlate`.

        Returns:
            correlation_value (int): Shift value in pixels.

        """
        # print(reference, new_array)
        cyaxis2 = new_array
        if float(re.sub('[A-Za-z" ]', '', self.lamp_header['SLIT'])) > 3:

            box_width = float(
                re.sub('[A-Za-z" ]', '', self.lamp_header['SLIT'])) / 0.15

            self.log.debug('BOX WIDTH: {:f}'.format(box_width))
            box_kernel = Box1DKernel(width=box_width)
            max_before = np.max(reference)
            cyaxis1 = convolve(reference, box_kernel)
            max_after = np.max(cyaxis1)
            cyaxis1 *= max_before / max_after


        else:
            gaussian_kernel = Gaussian1DKernel(stddev=2.)
            cyaxis1 = convolve(reference, gaussian_kernel)
            cyaxis2 = convolve(new_array, gaussian_kernel)
        # plt.plot(cyaxis1, color='k', label='Reference')
        # plt.plot(cyaxis2, color='r', label='New Array')
        # plt.plot(reference, color='g')
        # plt.show()
        try:
            ccorr = signal.correlate(cyaxis1, cyaxis2, mode=mode)
        except ValueError:
            print(cyaxis1, cyaxis2)
        # print('Corr ', ccorr)
        max_index = np.argmax(ccorr)

        x_ccorr = np.linspace(-int(len(ccorr) / 2.),
                              int(len(ccorr) / 2.),
                              len(ccorr))

        correlation_value = x_ccorr[max_index]
        if False:
            plt.ion()
            plt.title('Cross Correlation')
            plt.xlabel('Lag Value')
            plt.ylabel('Correlation Value')
            plt.plot(x_ccorr, ccorr)
            plt.draw()
            plt.pause(2)
            plt.clf()
            plt.ioff()
        return correlation_value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号