Tracking Data
A tracking data feed provides X/Y/(Z) coordinate data showing the position of all players and the ball. The data is collected using in-stadium optical tracking systems or based on broadcast video. In-stadium tracking data typically has a higher accuracy and provides the locations of all players and the ball, while broadcast-based tracking data only includes the positions of on-camera players.
One widely used open dataset is the Metrica Sports dataset. Below, we demonstrate how to load tracking data from Metrica Sports using kloppy:
This will create a TrackingDataset
that wraps a list of Frame
entities. The tracking data is sampled at a fixed frame rate, available via the metadata.frame_rate
attribute.
This value represents the number of frames recorded per second. For example, a frame rate of 25
means there are 25 frames per second of game time.
The remainder of this section explains the Frame
entities. Later sections of the user guide will explain in-depth how to process a tracking dataset.
Kloppy’s tracking data model
Kloppy uses Frame
objects to store tracking data. Each frame contains:
- The exact moment the frame was recorded.
- The (x, y) coordinates of the ball.
- A mapping of player identifiers to their (x, y) coordinates.
To inspect a specific frame, use indexing on the dataset.frames
list. For example, to access the frame at index 500:
Timestamp
The .timestamp
attribute returns a Time
object representing when the frame was recorded.
For more on the Time
object, see the next section.
Ball coordinates
The .ball_coordinates
attribute provides the position of the ball as a Point
object:
Some tracking data providers also include the ball's height (z-axis). In those cases, .ball_coordinates
will return a Point3D
object instead.
Player coordinates
Each Frame
includes a .players_coordinates
dictionary. This maps each Player
object to a Point
indicating the player’s location on the pitch.
Example: Coordinates of Home Team Players