예제 #1
0
 def test_rigid_fill_exceptions(self):
     """
     We test the exception raised when the marker SACR does not
     exist in Data.
     """
     #Test that the marker SACR must exist:
     with pytest.raises(Exception):
         data = self.data
         static = self.static
         Pipelines.rigid_fill(data, static)
예제 #2
0
    def test_rigid_fill_transform_from_static(self):
        """
        This function tests Pipelines.rigid_fill(Data, static),
        where Data is an array of dictionaries of marker data,
        and static is an array of dictionaries of static trial data.

        Pipelines.rigid_fill() fills gaps for frames with missing data using
        the transform functions Pipelines.transform_from_static and
        Pipelines.transform_from_mov.

        Pipelines.rigid_fill() determines whether to call transform_from_static
        or transform_from_mov by determining if there is a previous frame where
        all markers in the cluster of the missing marker exist, and can be used
        to create an inverse transformation matrix to determine
        the position of the missing marker in the current frame. If there is,
        transform_from_mov is used. Otherwise, transform_from_static, which uses
        static data to reconstruct missing markers, is used.
        
        This function tests that rigid_fill will properly call transform_from_static
        by using Pipelines.clearMarker() to clear the value of a given key at all
        frames. Since there are no other frames to reconstruct the inverse transform
        off of, we expect the function to use transform_from_static.
        """

        #The sacrum marker must exist in data to use rigid_fill
        #Use data with the LFHD marker cleared from every frame
        data = self.data_with_sacrum_clear_marker 
        static = self.static

        #Return value from transform_from_static is mocked 
        mock_return_val = np.array([1, 2, 3])
        with mock.patch.object(Pipelines, 'transform_from_static', return_value=mock_return_val) as mock_transform_from_static:
            #Call Pipelines.rigid_fill with the mocked transform_from_static
            rigid_fill_data = Pipelines.rigid_fill(data, static)
            mock_transform_from_static.assert_called()

        result = rigid_fill_data['LFHD'][10]
        np.testing.assert_almost_equal(result, np.array([1, 2, 3]), self.rounding_precision)
예제 #3
0
    def test_rigid_fill_transform_from_mov(self):
        """        
        This function tests that Pipelines.rigid_fill() will properly call transform_from_mov
        by clearing the value of a marker at only one frame. We expect transform_from_mov
        to be called in this case since there are previous markers to create the
        inverse transform matrix from.
        """

        #Use data with all markers
        data = self.data_with_sacrum
        static = self.static
        #Clear marker LFHD from frame 10
        data['LFHD'][10] = np.array([np.nan, np.nan, np.nan])

        #Return value from transform_from_mov is mocked 
        mock_return_val = np.array([1, 2, 3])
        with mock.patch.object(Pipelines, 'transform_from_mov', return_value=mock_return_val) as mock_transform_from_mov:
            #Call Pipelines.rigid_fill with the mocked transform_from_static
            rigid_fill_data = Pipelines.rigid_fill(data, static)
            mock_transform_from_mov.assert_called()

        result = rigid_fill_data['LFHD'][10]
        np.testing.assert_almost_equal(result, np.array([1, 2, 3]), self.rounding_precision)