diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/Metrica_IO.py b/Metrica_IO.py index 65ae83e..2c0b63a 100644 --- a/Metrica_IO.py +++ b/Metrica_IO.py @@ -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 @@ -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] \ No newline at end of file diff --git a/Metrica_Velocities.py b/Metrica_Velocities.py index 465f9a8..795386b 100644 --- a/Metrica_Velocities.py +++ b/Metrica_Velocities.py @@ -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 diff --git a/Metrica_Viz.py b/Metrica_Viz.py index f2a6c2f..96513dc 100644 --- a/Metrica_Viz.py +++ b/Metrica_Viz.py @@ -138,7 +138,7 @@ 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 @@ -146,7 +146,7 @@ def plot_frame( hometeam, awayteam, figax=None, team_colors=('r','b'), field_dim 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): @@ -196,7 +196,7 @@ 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 @@ -204,7 +204,7 @@ def save_match_clip(hometeam,awayteam, fpath, fname='clip_test', figax=None, fra 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. )