Exemplo n.º 1
0
def stitch_position_data(pos,ball,NO_PLAYERS=11):
    """Puts position data into a single array.
    
    stitch_position_data does not change the ordering of the data and
    stitches the position data together as given. Therefore, if the playing
    position must be controlled sort_position_data must be called first.
    Args:
        pos: position data list (indexed ragged array)
        ball: list with two matrices (1st and 2nd half)
        NO_PLAYERS: default = 11
    Returns:
        output_fields: 
    """
    # magic numbers
    _MISSING_ = -2.0**13
    _NO_DIM_ = 2 # x- and y-coordinates
    _POST_LOOK_ = 20
    # end magic numbers
    
    frames = ball[:,0]
    min_frame = min(frames)
    max_frame = max(frames)
    no_frames = ball.shape[0]
    if no_frames != (max_frame - min_frame + 1):
        raise IndexError("No of ball frames doesn't match")
        
    no_players_input = len(pos)

    input_fields = ra.expand_indexed_ragged_array(pos, frames, 
            lambda x: x[1], _MISSING_)
    input_fields_clean = ra.drop_expanded_ragged_entries(input_fields,NO_PLAYERS*_NO_DIM_,_MISSING_)
    output_fields = ra.condense_expanded_ragged_array(input_fields, missing_id = _MISSING_)
    
    return output_fields
Exemplo n.º 2
0
 def test_drop_function5(self):
     """Soccer data example."""
     mis_id = self.mis_id
     test_data = np.array([
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,3.,4.,5.,6.,7.,8.],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id]])
     expect = np.array([
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,mis_id,mis_id,5.,6.,7.,8.],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id],
         [1.,.2,3.,4.,5.,6.,mis_id,mis_id]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 6)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 3
0
 def test_drop_function1(self):
     """Tests simple case."""
     mis_id = self.mis_id
     test_data = np.array([[1., .2, mis_id], [1., 2., mis_id], [1., 2., 3.],
                           [mis_id, 2., 3.]])
     expect = test_data.copy()
     expect[2, 2] = mis_id
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 4
0
 def test_drop_function3(self):
     """Tests continuous and offsets entries."""
     mis_id = self.mis_id
     test_data = np.array([[1., .2, mis_id, mis_id],
                           [1., 2., mis_id, mis_id], [1., mis_id, 3., 4.],
                           [mis_id, 2., 3., 4.], [mis_id, 2., 3., 4.]])
     expect = np.array([[1., .2, mis_id, mis_id], [1., 2., mis_id, mis_id],
                        [1., mis_id, 3., mis_id], [mis_id, 2., 3., mis_id],
                        [mis_id, 2., 3., mis_id]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 5
0
 def test_drop_function1(self):
     """Tests simple case."""
     mis_id = self.mis_id
     test_data = np.array([[1.,.2,mis_id],
         [1.,2.,mis_id],
         [1.,2.,3.],
         [mis_id,2.,3.]])
     expect = test_data.copy()
     expect[2,2] = mis_id
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 6
0
 def test_drop_function3(self):
     """Tests complete change of entry positions."""
     mis_id = self.mis_id
     test_data = np.array([[1., .2, mis_id,
                            mis_id], [1., 2., mis_id, mis_id],
                           [mis_id, mis_id, 3.,
                            4.], [mis_id, mis_id, 3., 4.],
                           [mis_id, mis_id, 3., 4.]])
     expect = np.array([[1., .2, mis_id, mis_id], [1., 2., mis_id, mis_id],
                        [mis_id, mis_id, 3., 4.], [mis_id, mis_id, 3., 4.],
                        [mis_id, mis_id, 3., 4.]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 7
0
 def test_drop_function4(self):
     """Tests case with fewer entries."""
     mis_id = self.mis_id
     test_data = np.array([[1., .2, mis_id, mis_id],
                           [1., 2., mis_id, mis_id], [mis_id, 2., 3., 4.],
                           [mis_id, mis_id, mis_id, 4.],
                           [mis_id, mis_id, mis_id, 4.]])
     expect = np.array([[1., .2, mis_id, mis_id], [1., 2., mis_id, mis_id],
                        [mis_id, 2., 3., mis_id],
                        [mis_id, mis_id, mis_id, 4.],
                        [mis_id, mis_id, mis_id, 4.]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 8
0
 def test_drop_function3(self):
     """Tests continuous and offsets entries."""
     mis_id = self.mis_id
     test_data = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [1.,mis_id,3.,4.],
         [mis_id,2.,3.,4.],
         [mis_id,2.,3.,4.]])
     expect = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [1.,mis_id,3.,mis_id],
         [mis_id,2.,3.,mis_id],
         [mis_id,2.,3.,mis_id]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 9
0
 def test_drop_function4(self):
     """Tests case with fewer entries."""
     mis_id = self.mis_id
     test_data = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [mis_id,2.,3.,4.],
         [mis_id,mis_id,mis_id,4.],
         [mis_id,mis_id,mis_id,4.]])
     expect = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [mis_id,2.,3.,mis_id],
         [mis_id,mis_id,mis_id,4.],
         [mis_id,mis_id,mis_id,4.]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 10
0
 def test_drop_function3(self):
     """Tests complete change of entry positions."""
     mis_id = self.mis_id
     test_data = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [mis_id,mis_id,3.,4.],
         [mis_id,mis_id,3.,4.],
         [mis_id,mis_id,3.,4.]])
     expect = np.array([[1.,.2,mis_id,mis_id],
         [1.,2.,mis_id,mis_id],
         [mis_id,mis_id,3.,4.],
         [mis_id,mis_id,3.,4.],
         [mis_id,mis_id,3.,4.]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 2)
     self.assertTrue(np.all(obtained == expect))
Exemplo n.º 11
0
 def test_drop_function5(self):
     """Soccer data example."""
     mis_id = self.mis_id
     test_data = np.array([[1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                           [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                           [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                           [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                           [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                           [1., .2, 3., 4., 5., 6., 7., 8.],
                           [1., .2, 3., 4., 5., 6., mis_id, mis_id],
                           [1., .2, 3., 4., 5., 6., mis_id, mis_id],
                           [1., .2, 3., 4., 5., 6., mis_id, mis_id]])
     expect = np.array([[1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, mis_id, mis_id, 5., 6., 7., 8.],
                        [1., .2, 3., 4., 5., 6., mis_id, mis_id],
                        [1., .2, 3., 4., 5., 6., mis_id, mis_id],
                        [1., .2, 3., 4., 5., 6., mis_id, mis_id]])
     obtained = ra.drop_expanded_ragged_entries(test_data, 6)
     self.assertTrue(np.all(obtained == expect))