示例#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
示例#2
0
 def test_condense_function(self):
     """Tests whether the condense function works as expected."""
     test_data = self.exp_arr
     expect = np.array([[1.,2.],[1.,2.],[1.,2.],[1.,2.],[2.,3.],[2.,3.]])
     obtained = ra.condense_expanded_ragged_array(test_data)
     self.assertTrue(np.all(obtained == expect))