def test_crop(self):
        subject_id = 'subjectA'
        data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
        motion_collection = MotionCollection(subject_id=subject_id, data=data)
        interval = Interval(start_time=4, end_time=9)
        cropped_data = np.array([[4, 5, 6], [7, 8, 9]])
        cropped_motion_collection = MotionCollection(subject_id=subject_id, data=cropped_data)

        returned_collection = MotionService.crop(motion_collection, interval)

        TestHelper.assert_models_equal(self, cropped_motion_collection, returned_collection)
Exemplo n.º 2
0
    def crop(motion_collection, interval):
        subject_id = motion_collection.subject_id
        timestamps = motion_collection.timestamps
        valid_indices = ((timestamps >= interval.start_time)
                         & (timestamps < interval.end_time)).nonzero()[0]

        cropped_data = motion_collection.data[valid_indices, :]
        return MotionCollection(subject_id=subject_id, data=cropped_data)
Exemplo n.º 3
0
    def test_properties(self):
        subject_id = "subjectA"
        motion_collection = MotionCollection(subject_id=subject_id,
                                             data=np.array([[1, 2, 3], [4, 5, 6]]))

        self.assertEqual(subject_id, motion_collection.subject_id)
        self.assertEqual(np.array([1, 4]).tolist(), motion_collection.timestamps.tolist())
        self.assertEqual(np.array([[2, 3], [5, 6]]).tolist(), motion_collection.values.tolist())
    def test_write(self, mock_cropped_file_path, mock_np):
        subject_id = 'subjectA'
        data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
        motion_collection = MotionCollection(subject_id=subject_id, data=data)
        mock_cropped_file_path.return_value = file_path = 'path/to/file'

        MotionService.write(motion_collection)

        mock_np.savetxt.assert_called_once_with(file_path, motion_collection.data, fmt='%f')
    def test_load_cropped(self, mock_get_cropped_file_path, mock_load):
        subject_id = 'subjectB'
        mock_get_cropped_file_path.return_value = returned_cropped_path = 'path/to/file'
        mock_load.return_value = data = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
        expected_motion_collection = MotionCollection(subject_id=subject_id, data=data)

        returned_motion_collection = MotionService.load_cropped(subject_id)

        TestHelper.assert_models_equal(self, expected_motion_collection, returned_motion_collection)
        mock_get_cropped_file_path.assert_called_once_with(subject_id)
        mock_load.assert_called_once_with(returned_cropped_path)
    def test_load_raw(self, mock_get_raw_file_path, mock_load, mock_remove_repeats):
        subject_id = 'subjectA'
        mock_get_raw_file_path.return_value = returned_raw_path = 'path/to/file'
        mock_load.return_value = data = np.array([[1, 2, 3], [4, 5, 6]])
        mock_remove_repeats.return_value = data
        expected_motion_collection = MotionCollection(subject_id=subject_id, data=data)

        returned_motion_collection = MotionService.load_raw(subject_id)

        TestHelper.assert_models_equal(self, expected_motion_collection, returned_motion_collection)
        mock_get_raw_file_path.assert_called_once_with(subject_id)
        mock_load.assert_called_once_with(returned_raw_path)
        mock_remove_repeats.assert_called_once_with(data)
Exemplo n.º 7
0
 def load_cropped(subject_id):
     cropped_motion_path = MotionService.get_cropped_file_path(subject_id)
     motion_array = MotionService.load(cropped_motion_path)
     return MotionCollection(subject_id=subject_id, data=motion_array)
Exemplo n.º 8
0
 def load_raw(subject_id):
     raw_motion_path = MotionService.get_raw_file_path(subject_id)
     motion_array = MotionService.load(raw_motion_path)
     motion_array = utils.remove_repeats(motion_array)
     return MotionCollection(subject_id=subject_id, data=motion_array)
Exemplo n.º 9
0
 def test_get_interval(self):
     motion_collection = MotionCollection(subject_id="subjectA",
                                              data=np.array([[1, 2, 3], [4, 5, 6]]))
     interval = Interval(start_time=1, end_time=4)
     self.assertEqual(interval.start_time, motion_collection.get_interval().start_time)
     self.assertEqual(interval.end_time, motion_collection.get_interval().end_time)