def main(): ''' An example of a join. We filter pairs based on time overlap, and merge surviving pairs by taking the intersection over the time bounds and the span of the spatial bounds (and adding the payloads). ''' is1 = IntervalSet([ Interval(Bounds3D(0, 1, 0, 1, 0, 1), 1), Interval(Bounds3D(0, 0.5, 0.5, 1, 0, 0.5), 2), ]) is2 = IntervalSet([ Interval(Bounds3D(0.5, 1, 0, 1, 0, 1), 4), Interval(Bounds3D(0, 1, 0, 1, 0, 1), 8), ]) is3 = is1.join( is2, Bounds3D.T(overlaps()), lambda i1, i2: Interval( i1['bounds'].intersect_time_span_space(i2['bounds']), i1['payload'] + i2['payload'])) print('is1:') print(is1) print('is2:') print(is2) print('is1 joined with is2:') print(is3)
def test_join_with_optimization_window(self): is1 = IntervalSet( [Interval(Bounds3D(t, t + 1), t) for t in range(100)]) is2 = IntervalSet([Interval(Bounds3D(t, t), t) for t in range(100)]) is3 = is1.join(is2, Bounds3D.T(before(max_dist=1)), lambda i1, i2: Interval(i1['bounds'].span(i2['bounds']), i2['payload']), window=1) target = IntervalSet( [Interval(Bounds3D(t, t + 2), t + 2) for t in range(98)] + [Interval(Bounds3D(t, t + 1), t + 1) for t in range(99)]) self.assertIntervalSetEq(is3, target, eq)
def test_join(self): is1 = IntervalSet([ Interval(Bounds3D(0, 1, 0, 1, 0, 1), 1), Interval(Bounds3D(0, 0.5, 0.5, 1, 0, 0.5), 2), ]) is2 = IntervalSet([ Interval(Bounds3D(0.5, 1, 0, 1, 0, 1), 4), Interval(Bounds3D(0, 1, 0, 1, 0, 1), 8), ]) is3 = is1.join( is2, Bounds3D.T(overlaps()), lambda i1, i2: Interval( i1['bounds'].intersect_time_span_space(i2['bounds']), i1[ 'payload'] + i2['payload'])) target = IntervalSet([ Interval(Bounds3D(0.5, 1, 0, 1, 0, 1), 5), Interval(Bounds3D(0, 1, 0, 1, 0, 1), 9), Interval(Bounds3D(0, 0.5, 0, 1, 0, 1), 10), ]) self.assertIntervalSetEq(is3, target, eq)