def test_cut_window(self): recorded_animation = Animation( np.array([[1, 3, 4], [1, 2, 3], [1, 2, 2], [1, 2, 1], [1, 2, 0], [1, 2, -1], [1, 2, 0], [1, 2, 1]])) anim1 = Animation(np.array([[1, 3, 4], [1, 2, 3]])) anim2 = Animation(np.array([[1, 2, 3], [1, 2, 2]])) anim3 = Animation(np.array([[1, 2, 0], [1, 2, 1]])) anim4 = Animation(np.array([[1, 2, 0]])) anim5 = Animation(np.array([[1, 2, 1], [1, 2, 0], [1, 2, -1]])) self.assertEqual(recorded_animation.cut_window(0, 2), anim1) self.assertEqual(recorded_animation.cut_window(1, 2), anim2) self.assertEqual(recorded_animation.cut_window(6, 2), anim3) self.assertEqual(recorded_animation.cut_window(6, 1), anim4) self.assertEqual(recorded_animation.cut_window(3, 3), anim5) with self.assertRaises(ValueError): recorded_animation.cut_window(7, 0) with self.assertRaises(ValueError): recorded_animation.cut_window(7, 2) with self.assertRaises(ValueError): recorded_animation.cut_window(-1, 2)
def get_single_anim_moving_window_scores(self, rec_anim: Animation, anim: Animation, window_step=1) -> List[ScoreSpaceElement]: # TODO Write the doc """ Slide the moving window with lib_anim through the rec_anim and collect scores Parameters ---------- rec_anim: anim: window_step: Returns ------- """ scores = list() # List[ScoreSpaceElement] if anim.num_frames() > rec_anim.num_frames(): raise ValueError("Length or lib_anim can't be greater than length of rec_anim") for win_start in range(0, rec_anim.num_frames() - anim.num_frames() + 1, window_step): cut_anim = rec_anim.cut_window(win_start, anim.num_frames()) score_space_el = self.compare_equal_length_single_animations(cut_anim, anim) score_space_el.window_start_frame = win_start scores.append(score_space_el) return scores