2022-12-05 MAD检测,去重

def extract_new_detections_(
                           cc_sums,
                           moveout_array,
                           n_mad=10.,
                           template_duration=8.,
                           step=1,
                           extracted_duration=60.):

    n_templates = cc_sums.shape[0]
    n_stations = moveout_array.shape[1]
    n_components = moveout_array.shape[2]
    n_extracted_samples = np.int32(extracted_duration * 100)
    buffer_extracted_events = 10.

    list_metadata = []
    list_waveforms = []
    for i in range(n_templates):
        cc_sum = cc_sums[i, :]

        cc_sum -= np.median(cc_sum)
        threshold = n_mad * np.median(np.abs(cc_sum))
        # ------------------
        cc_idx = np.argwhere(cc_sum > threshold)
        detections = cc_idx * step

        # only keep highest correlation coefficient for grouped detections
        # we assume the last component is the vertical component
        d_mv = moveout_array[i, :, 0] - moveout_array[i, :, -1]
        # fix the maximum window size to 3 times the template duration
        # fix the minimum window size to 1 time the templare duration
        # in between: choose an adaptive size based on the median
        # P-S time
        search_win = min(np.int32(3. * template_duration *
                                  100 / step),
                         max(np.int32(1. * np.median(d_mv[d_mv != 0]) / step),
                             np.int32(template_duration *
                                      100 / step)))
        for j in range(cc_idx.size):
            idx = np.arange(max(0, cc_idx[j] - search_win // 2),
                            min(cc_sum.size-1, cc_idx[j] + search_win // 2),
                            dtype=np.int32)
            idx_to_update = np.where(cc_idx == cc_idx[j])[0]
            cc_idx[idx_to_update] = np.argmax(cc_sum[idx]) + idx[0]

        cc_idx = np.unique(cc_idx)
        detections = cc_idx * step

        # after this step, we can have detections closest than search_win / 2
        cc_idx = list(cc_idx)
        n_removed = 0
        for j in range(1, detections.size):
            if (cc_idx[j-n_removed] - cc_idx[j-n_removed-1]) < search_win // 2:
                if cc_sum[cc_idx[j-n_removed]] > cc_sum[cc_idx[j-n_removed-1]]:
                    cc_idx.remove(cc_idx[j-n_removed-1])
                else:
                    cc_idx.remove(cc_idx[j-n_removed])
                n_removed += 1
        cc_idx = np.asarray(cc_idx)
        detections = cc_idx * step
    return detections
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 道声最早的“早安”,一觉醒来大宁波全面开放,要和场所码说再见了,迎来全民拼免疫力的时代,此时健康合理的运动变得尤为...
    元素瑜伽若涵阅读 133评论 0 0
  • 第1章 总则 第1条 目的 为使本公司的仓库管理规范化,保证财产物资的完好无损,根据企业管理和财务管...
    雨露_108c阅读 199评论 0 0
  • #日诵诗情,画意日趣# #日诵之20221205 清平调三首 其一 李白 云想衣裳花想容,春风拂槛露华浓。 若非群...
    人生下伴场阅读 559评论 0 0
  • 原来她是他的白月光,你是我的朱砂痣
    古灵精jing阅读 101评论 0 1
  • 这个周末比较充实,一直在和高语作业较劲,终于打败了,完成1800字,而且每日叙事坚持四天了。其实就是写日记,但是想...
    胡喜平阅读 173评论 0 0

友情链接更多精彩内容