def make_detection_extractor(detections, matches):
rxpair_detections = collections.defaultdict(list)
for group in matches:
for det0_id, det1_id in itertools.combinations(group, 2):
det0 = detections[det0_id]
det1 = detections[det1_id]
if det0.rxid > det1.rxid:
det0, det1 = det1, det0
rxpair_detections[(det0.rxid, det1.rxid)].append((det0, det1))
timestamps = {}
for pair, detections in rxpair_detections.iteritems():
detections.sort(cmp=lambda x, y: x[0].timestamp < y[0].timestamp)
timestamps[pair] = [d[0].timestamp for d in detections]
def extract(rxid0, rxid1, timestamp_start, timestamp_stop):
assert rxid0 < rxid1
pair = (rxid0, rxid1)
left = bisect_left(timestamps[pair], timestamp_start)
right = bisect_right(timestamps[pair], timestamp_stop)
detection_pairs = rxpair_detections[pair][left:right]
if len(detection_pairs) > 1:
sdoa = np.array([d[0].soa - d[1].soa for d in detection_pairs])
is_outlier = stat_tools.is_outlier(sdoa)
detection_pairs = list(itertools.compress(detection_pairs,
~is_outlier))
return detection_pairs
return extract
评论列表
文章目录