Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 2 additions & 2 deletions Metrica_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def to_single_playing_direction(home,away,events):
Flip coordinates in second half so that each team always shoots in the same direction through the match.
'''
for team in [home,away,events]:
second_half_idx = team.Period.idxmax(2)
second_half_idx = team.Period.idxmax(axis=0)
columns = [c for c in team.columns if c[-1].lower() in ['x','y']]
team.loc[second_half_idx:,columns] *= -1
return home,away,events
Expand All @@ -103,6 +103,6 @@ def find_goalkeeper(team):
Find the goalkeeper in team, identifying him/her as the player closest to goal at kick off
'''
x_columns = [c for c in team.columns if c[-2:].lower()=='_x' and c[:4] in ['Home','Away']]
GK_col = team.iloc[0][x_columns].abs().idxmax(axis=1)
GK_col = team.iloc[0][x_columns].abs().idxmax(axis=0)
return GK_col.split('_')[1]

2 changes: 1 addition & 1 deletion Metrica_Velocities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def calc_player_velocities(team, smoothing=True, filter_='Savitzky-Golay', windo
dt = team['Time [s]'].diff()

# index of first frame in second half
second_half_idx = team.Period.idxmax(2)
second_half_idx = team.Period.idxmax(0)

# estimate velocities for players in team
for player in player_ids: # cycle through players individually
Expand Down
8 changes: 4 additions & 4 deletions Metrica_Viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def plot_frame( hometeam, awayteam, figax=None, team_colors=('r','b'), field_dim
for team,color in zip( [hometeam,awayteam], team_colors) :
x_columns = [c for c in team.keys() if c[-2:].lower()=='_x' and c!='ball_x'] # column header for player x positions
y_columns = [c for c in team.keys() if c[-2:].lower()=='_y' and c!='ball_y'] # column header for player y positions
ax.plot( team[x_columns], team[y_columns], color+'o', MarkerSize=PlayerMarkerSize, alpha=PlayerAlpha ) # plot player positions
ax.plot( team[x_columns], team[y_columns], color+'o', markersize=PlayerMarkerSize, alpha=PlayerAlpha ) # plot player positions
if include_player_velocities:
vx_columns = ['{}_vx'.format(c[:-2]) for c in x_columns] # column header for player x positions
vy_columns = ['{}_vy'.format(c[:-2]) for c in y_columns] # column header for player y positions
ax.quiver( team[x_columns], team[y_columns], team[vx_columns], team[vy_columns], color=color, scale_units='inches', scale=10.,width=0.0015,headlength=5,headwidth=3,alpha=PlayerAlpha)
if annotate:
[ ax.text( team[x]+0.5, team[y]+0.5, x.split('_')[1], fontsize=10, color=color ) for x,y in zip(x_columns,y_columns) if not ( np.isnan(team[x]) or np.isnan(team[y]) ) ]
# plot ball
ax.plot( hometeam['ball_x'], hometeam['ball_y'], 'ko', MarkerSize=6, alpha=1.0, LineWidth=0)
ax.plot( hometeam['ball_x'], hometeam['ball_y'], 'ko', markersize=6, alpha=1.0, linewidth=0)
return fig,ax

def save_match_clip(hometeam,awayteam, fpath, fname='clip_test', figax=None, frames_per_second=25, team_colors=('r','b'), field_dimen = (106.0,68.0), include_player_velocities=False, PlayerMarkerSize=10, PlayerAlpha=0.7):
Expand Down Expand Up @@ -196,15 +196,15 @@ def save_match_clip(hometeam,awayteam, fpath, fname='clip_test', figax=None, fra
for team,color in zip( [hometeam.loc[i],awayteam.loc[i]], team_colors) :
x_columns = [c for c in team.keys() if c[-2:].lower()=='_x' and c!='ball_x'] # column header for player x positions
y_columns = [c for c in team.keys() if c[-2:].lower()=='_y' and c!='ball_y'] # column header for player y positions
objs, = ax.plot( team[x_columns], team[y_columns], color+'o', MarkerSize=PlayerMarkerSize, alpha=PlayerAlpha ) # plot player positions
objs, = ax.plot( team[x_columns], team[y_columns], color+'o', markersize=PlayerMarkerSize, alpha=PlayerAlpha ) # plot player positions
figobjs.append(objs)
if include_player_velocities:
vx_columns = ['{}_vx'.format(c[:-2]) for c in x_columns] # column header for player x positions
vy_columns = ['{}_vy'.format(c[:-2]) for c in y_columns] # column header for player y positions
objs = ax.quiver( team[x_columns], team[y_columns], team[vx_columns], team[vy_columns], color=color, scale_units='inches', scale=10.,width=0.0015,headlength=5,headwidth=3,alpha=PlayerAlpha)
figobjs.append(objs)
# plot ball
objs, = ax.plot( team['ball_x'], team['ball_y'], 'ko', MarkerSize=6, alpha=1.0, LineWidth=0)
objs, = ax.plot( team['ball_x'], team['ball_y'], 'ko', markersize=6, alpha=1.0, linewidth=0)
figobjs.append(objs)
# include match time at the top
frame_minute = int( team['Time [s]']/60. )
Expand Down