import Tracking_Visuals as vis import numpy as np import matplotlib.pyplot as plt current_dir = os.path.dirname(os.getcwd()) fpath = os.path.join(current_dir, 'TrackingSample') # path to directory of Tracab data # config LEAGUE = 'DSL' #fname_dict = tracab.get_filename_dict() # fname = 'SouthamptonManchester City2018-11-04T15,00,00Z.txt.g987698'# filename of Tracab match fname = '984628' # read frames, match meta data, and data for individual players frames_tb, match_tb, team1_players, team0_players = tracab.read_tracab_match_data(LEAGUE,fpath,fname,verbose=True)# frames is a list of the individual match snapshots (positions, velocities) # match contains some metadata (pitch dimensions, etc) # team1_players is a dictionary of the home team players (containing arrays of their positions/velocities over the match) # team0_players is a dictionary of the away team players (containing arrays of their positions/velocities over the match) # EXAMPLE: plot the pitch, players and ball in a single frame. # the co-ordinate system has the origin in the center of the pitch. x-axis is left-right, y-axis is up-down. Distances are in cm by default. fig,ax = vis.plot_frame(frames_tb[1000],match_tb,include_player_velocities=True,include_ball_velocities=False) # EXAMPLE: get all frames between the 19th and 21st minute in the first half tstart = (1,19) tend = (1,21) frames_in_segment = vis.get_frames_between_timestamps(frames_tb,match_tb,tstart,tend) # EXAMPLE: get the x,y,z positions and velocities of the ball throughout the first half frames_in_first_half = frames_tb[ 0:match_tb.period_attributes[1]['iEnd'] ]
fpath = '/Path/To/Directory/of/Tracking/Data/' # path to directory of Tracab data match_ids = range(984455, 984634 + 1) # data problems in these three matches, so remove them missing = [984474, 984488, 984616] [match_ids.remove(m) for m in missing] all_formations = [] formation_stats = [] for match in match_ids[0:1]: print(match) fname = str(match) # read frames, match meta data, and data for individual players frames_tb, match_tb, team1_players, team0_players = tracab.read_tracab_match_data( 'DSL', fpath, fname, verbose=False) # get goalkeeper ids team1_exclude = match_tb.team1_exclude team0_exclude = match_tb.team0_exclude # get all possessions posessions = tracab.get_tracab_posessions(frames_tb, match_tb, min_pos_length=1) # get home and away possessions, remove possessions less than 5 seconds (unless they start with a dead ball) and those in the defensive quarter of the field posH = [ p for p in posessions if p.team == 'H' and p.pos_type in ['A', 'N'] and ( p.pos_duration > 5 or p.pos_start_type == 'DeadBall')
for path in games: # match_id, _ = path.replace(os.path.dirname(path) + '/', '').split('_') # local Aalborg match_id = path.split('/')[-1] # cluster print('Starting energy expenditure calculcation for game {} at location {}'.format(match_id, path)) # skip games which are not in player id mapping with player info if int(match_id) not in game_ids_w_player_mapping: print('skipped match {}'.format(match_id)) continue # save data game_data = {'data_path': path} # read fpath, fname = path, str(match_id) frames_tb, match_tb, team1_players, team0_players = tracab.read_tracab_match_data(LEAGUE, fpath, fname, verbose=True) # players info players_info = helpers.map_playerids_positions(team1_players, team0_players, match_id, loc_mapping=PLAYER_ID_to_JERSEY_NUM_LOC) # get stats time_series_mat = get_time_series(players_info) # store game_data['player_info'] = players_info.drop('obj', axis=1) game_data['energy_x'] = time_series_mat # save OUTFILE_NAME = 'EX_time_series_game_{}.pkl'.format(match_id) with open(os.path.join('../saved', OUTFILE_NAME), 'wb') as outfile:
@author: laurieshaw """ import Tracab as tracab import Tracking_Visuals as vis import numpy as np import Pitch_Control as pc import matplotlib.colors as mcol fpath = '/Path/To/Directory/of/Tracking/Data/' # path to directory of Tracab data match_id = 984455 # example print match_id fname = str(match_id) # read frames, match meta data, and data for individual players frames_tb, match_tb, team1_players, team0_players = tracab.read_tracab_match_data( 'DSL', fpath, fname, verbose=False) params = pc.default_model_params() params[ 'lambda_def'] = 3.99 # reset this so it's the same as the defending team frame = frames_tb[ 7995] # plot at randome frame. need to start from at least the 5th frame as velocities are uninitialised until then ball_pos = np.array([frame.ball_pos_x, frame.ball_pos_y]) / 100. # if you want to actually take into acount the time taken for the ball to get to any given area of the pitch, you'll need to uncomment the lines below. # NB: calc_trajectory_grid, which generates a library of trajectories, takes a while to run (but you only need to generate it once) # dgrid just calculates the shortest flight time for the ball to travel a certain distance. ''' rgrid = pc.calc_trajectory_grid() dgrid = pc.calc_shortest_flighttimes_array(np.arange(0,100,0.5),rgrid,dr=0.5,ball_vmax=40.)