def test_expand_function(self): """Tests simple expansion example.""" obtained_result = ra.expand_indexed_ragged_array( self.test_data, self.index, missing_id=self.mis_id) self.assertTrue(np.all(obtained_result == self.exp_arr))
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
def test_expand_accessor_function(self): """Tests whether the accessor function works.""" test_data = [(i,data) for i,data in enumerate(self.test_data)] obtained_result = ra.expand_indexed_ragged_array( test_data, self.index, lambda x : x[1], TestIndexedRaggedArray.mis_id) self.assertTrue(np.all(obtained_result == self.exp_arr))