Beispiel #1
0
    def test_collect_by_interval(self):
        is1 = IntervalSet([
            Interval(Bounds3D(1, 5)),
            Interval(Bounds3D(10, 50)),
            Interval(Bounds3D(51, 52)),
        ])
        intervals = [
            Interval(Bounds3D(2, 2, 0.4, 0.6, 0.1, 0.2), 1),
            Interval(Bounds3D(3, 3, 0.1, 0.6, 0.8, 0.9), 2),
            Interval(Bounds3D(11, 23, 0, 1, 0.8, 0.9), 3),
        ]
        is2 = IntervalSet(intervals)

        is3 = is1.collect_by_interval(is2,
                                      Bounds3D.T(during_inv()),
                                      filter_empty=True,
                                      window=None).map_payload(lambda p: p[1])
        target = IntervalSet([
            Interval(Bounds3D(1, 5), payload=IntervalSet(intervals[:2])),
            Interval(Bounds3D(10, 50), payload=IntervalSet(intervals[2:3])),
        ])
        self.assertIntervalSetEq(is3, target,
                                 self.compare_interval_sets_in_payload())

        is4 = is1.collect_by_interval(is2,
                                      Bounds3D.T(overlaps()),
                                      filter_empty=False,
                                      window=0).map_payload(lambda p: p[1])
        target = IntervalSet([
            Interval(Bounds3D(1, 5), payload=IntervalSet(intervals[:2])),
            Interval(Bounds3D(10, 50), payload=IntervalSet(intervals[2:3])),
            Interval(Bounds3D(51, 52), payload=IntervalSet([])),
        ])
        self.assertIntervalSetEq(is4, target,
                                 self.compare_interval_sets_in_payload())
 def test_collect_by_interval(self):
     c = TestIntervalSetMapping.get_collection()
     d = IntervalSetMapping({1: IntervalSet([
             Interval(Bounds3D(t,t)) for t in range(1, 100)])})
     e = c.collect_by_interval(d, Bounds3D.T(overlaps()),
             filter_empty=False, window=0)
     self.assertEqual(e.keys(), c.keys())
Beispiel #3
0
    def test_match_multiple_solutions(self):
        left_box_frame_1 = Interval(Bounds3D(1, 1, 0.1, 0.4, 0.4, 0.8))
        right_box_frame_1 = Interval(Bounds3D(1, 1, 0.6, 0.9, 0.3, 0.7))
        bottom_left_box_frame_2 = Interval(Bounds3D(2, 2, 0.1, 0.3, 0.8, 0.9))
        top_right_box_frame_2 = Interval(Bounds3D(2, 2, 0.5, 0.7, 0.2, 0.7))
        is1 = IntervalSet([
            left_box_frame_1,
            right_box_frame_1,
            bottom_left_box_frame_2,
            top_right_box_frame_2,
            Interval(Bounds3D(3, 3)),
        ])

        pattern = [
            (
                ["left", "right"],
                [
                    # Two boxes on left and right on same frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(left_of()),
                ]),
        ]
        results = is1.match(pattern, exact=False)
        self.assertEqual(len(results), 2)

        # Add single interval constraints.
        pattern = pattern + [
            (["left"], [Bounds3D.XY(height_at_least(0.3))]),
            (["right"], [Bounds3D.XY(height_at_least(0.3))]),
        ]
        results = is1.match(pattern, exact=False)
        self.assertEqual(len(results), 1)
        result = results[0]
        self.assertIntervalsEq(left_box_frame_1, result['left'])
        self.assertIntervalsEq(right_box_frame_1, result['right'])
Beispiel #4
0
 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)
Beispiel #5
0
    def test_match(self):
        left_box_frame_1 = Interval(Bounds3D(1, 1, 0.1, 0.4, 0.4, 0.8))
        right_box_frame_1 = Interval(Bounds3D(1, 1, 0.6, 0.9, 0.3, 0.7))
        bottom_left_box_frame_2 = Interval(Bounds3D(2, 2, 0.1, 0.3, 0.8, 0.9))
        top_right_box_frame_2 = Interval(Bounds3D(2, 2, 0.5, 0.7, 0.2, 0.7))
        is1 = IntervalSet([
            left_box_frame_1, right_box_frame_1, bottom_left_box_frame_2,
            top_right_box_frame_2
        ])

        pattern = [
            (
                ["left", "right"],
                [
                    # Two boxes on left and right on same frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(left_of()),
                ]),
            (
                ["top", "bottom"],
                [
                    # Two boxes on top and bottom on overlapping frame
                    Bounds3D.T(equal()),
                    Bounds3D.XY(above()),
                ]),
            (
                ["left", "top"],
                [
                    # Left-Right pattern comes before Top-Bottom
                    Bounds3D.T(meets_before(epsilon=1))
                ])
        ]
        results = is1.match(pattern, exact=True)
        self.assertEqual(len(results), 1)
        result = results[0]
        self.assertIntervalsEq(left_box_frame_1, result['left'])
        self.assertIntervalsEq(right_box_frame_1, result['right'])
        self.assertIntervalsEq(top_right_box_frame_2, result['top'])
        self.assertIntervalsEq(bottom_left_box_frame_2, result['bottom'])
Beispiel #6
0
 def test_filter_against(self):
     is1 = IntervalSet([
         Interval(Bounds3D(0, 1)),
         Interval(Bounds3D(2, 5)),
         Interval(Bounds3D(6, 7)),
     ])
     is2 = IntervalSet([
         Interval(Bounds3D(1, 1)),
         Interval(Bounds3D(7, 7)),
     ])
     # Take only intervals in is1 that overlaps with some interval in is2
     is3 = is1.filter_against(is2, Bounds3D.T(overlaps()), window=0)
     self.assertIntervalSetEq(
         is3,
         IntervalSet([Interval(Bounds3D(0, 1)),
                      Interval(Bounds3D(6, 7))]))
Beispiel #7
0
 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)