def Generate_Tracab_Chance_Videos(match_OPTA, match_tb, frames_tb): t_init_buf = 0.5 t_end_buf = 0.1 match_end = frames_tb[-1].timestamp all_shots = [e for e in match_OPTA.hometeam.events if e.is_shot] + [e for e in match_OPTA.awayteam.events if e.is_shot] for shot in all_shots: print shot tstart = (shot.period_id, max(0.0,shot.time-45*(shot.period_id-1) - t_init_buf)) tend = (shot.period_id, min(match_end,shot.time-45*(shot.period_id-1) + t_end_buf)) frames_in_segment = vis.get_frames_between_timestamps(frames_tb,match_tb,tstart,tend) vis.save_match_clip(frames_in_segment,match_tb,fpath=match_OPTA.fpath+'/chances/',fname=shot.shot_id,include_player_velocities=False,description=shot.shot_descriptor)
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'] ] ball_positions_xyz = [] ball_velocities_xyz = [] timestamps = [] for frame in frames_in_first_half: if frame.ball: # sometimes the ball data isn't in the frame (for whatever reason) ball_positions_xyz.append( [frame.ball_pos_x, frame.ball_pos_y, frame.ball_pos_z] ) ball_velocities_xyz.append( [frame.ball_vx, frame.ball_vy, frame.ball_vz] ) timestamps.append( frame.timestamp ) # convert from list into array to make it easier to slice ball_positions_xyz = np.array( ball_positions_xyz ) / 100. # convert to m ball_velocities_xyz = np.array( ball_velocities_xyz ) # already in m/s