StatsPerform¶
Load local event files¶
MA1 and MA3¶
In [ ]:
Copied!
from kloppy import statsperform
dataset = statsperform.load_event(
ma1_data="../../kloppy/tests/files/statsperform_event_ma1.json",
ma3_data="../../kloppy/tests/files/statsperform_event_ma3.json",
# Optional arguments
coordinates="opta",
pitch_length=102.5,
pitch_width=69.0,
event_types=["pass", "shot"],
)
dataset.to_df().head()
from kloppy import statsperform
dataset = statsperform.load_event(
ma1_data="../../kloppy/tests/files/statsperform_event_ma1.json",
ma3_data="../../kloppy/tests/files/statsperform_event_ma3.json",
# Optional arguments
coordinates="opta",
pitch_length=102.5,
pitch_width=69.0,
event_types=["pass", "shot"],
)
dataset.to_df().head()
Out[ ]:
event_id | event_type | result | success | period_id | timestamp | end_timestamp | ball_state | ball_owning_team | team_id | player_id | coordinates_x | coordinates_y | end_coordinates_x | end_coordinates_y | receiver_player_id | set_piece_type | pass_type | body_part_type | is_counter_attack | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2328589789 | PASS | COMPLETE | True | 1 | 0 days 00:00:00.030000 | None | alive | 75xi6hloabmnjn2kzgj1g8h1s | 75xi6hloabmnjn2kzgj1g8h1s | aksjicf4keobpav3tuujngell | 50.0 | 50.0 | 33.9 | 51.0 | None | KICK_OFF | None | None | None |
1 | 2328589863 | PASS | COMPLETE | True | 1 | 0 days 00:00:02.075000 | None | alive | 75xi6hloabmnjn2kzgj1g8h1s | 75xi6hloabmnjn2kzgj1g8h1s | apdrig6xt1hxub1986s3uh1x | 33.9 | 51.0 | 34.0 | 88.6 | None | None | None | None | None |
2 | 2328589885 | PASS | COMPLETE | True | 1 | 0 days 00:00:06.803000 | None | alive | 75xi6hloabmnjn2kzgj1g8h1s | 75xi6hloabmnjn2kzgj1g8h1s | 46vr35g415omy60ahbiv40wk5 | 34.2 | 88.6 | 56.1 | 92.7 | None | None | CHIPPED_PASS | None | None |
3 | 2328589929 | PASS | COMPLETE | True | 1 | 0 days 00:00:09.373000 | None | alive | 75xi6hloabmnjn2kzgj1g8h1s | 75xi6hloabmnjn2kzgj1g8h1s | 2nrmndj0uq3f46c2cb1fbf85 | 56.8 | 94.2 | 48.0 | 96.6 | None | None | None | None | None |
4 | 2328590577 | PASS | COMPLETE | True | 1 | 0 days 00:00:40.486000 | None | alive | 75xi6hloabmnjn2kzgj1g8h1s | 75xi6hloabmnjn2kzgj1g8h1s | 46vr35g415omy60ahbiv40wk5 | 46.1 | 94.7 | 32.7 | 73.8 | None | FREE_KICK | None | None | None |
Opta F7 and F24 (or F73)¶
You can also use the 'old' Opta F7 and F24 format or the F7 and F73 format.
To use F73, simply pass it to the f24_data
parameter instead of the f24 file.
In [ ]:
Copied!
from kloppy import opta
dataset = opta.load(
f7_data="../../kloppy/tests/files/opta_f7.xml",
f24_data="../../kloppy/tests/files/opta_f24.xml",
# f24_data="../../kloppy/tests/files/opta_f73.xml",
# Optional arguments
coordinates="opta",
event_types=["pass", "shot"],
)
dataset.to_df().head()
from kloppy import opta
dataset = opta.load(
f7_data="../../kloppy/tests/files/opta_f7.xml",
f24_data="../../kloppy/tests/files/opta_f24.xml",
# f24_data="../../kloppy/tests/files/opta_f73.xml",
# Optional arguments
coordinates="opta",
event_types=["pass", "shot"],
)
dataset.to_df().head()
Out[ ]:
event_id | event_type | result | success | period_id | timestamp | end_timestamp | ball_state | ball_owning_team | team_id | player_id | coordinates_x | coordinates_y | end_coordinates_x | end_coordinates_y | receiver_player_id | set_piece_type | pass_type | body_part_type | is_counter_attack | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1510681159 | PASS | COMPLETE | True | 1 | 0 days 00:00:00.431000 | 0 days 00:00:03.395000 | alive | 569 | 569 | 48337 | 50.1 | 49.4 | 36.4 | 45.1 | 76001 | KICK_OFF | None | None | None |
1 | 1646695660 | PASS | COMPLETE | True | 1 | 0 days 00:00:03.395000 | 0 days 00:00:05.299000 | alive | 569 | 569 | 76001 | 36.4 | 45.1 | 28.0 | 39.8 | 164266 | None | None | None | None |
2 | 1782829017 | PASS | COMPLETE | True | 1 | 0 days 00:00:05.299000 | 0 days 00:00:06.995000 | alive | 569 | 569 | 164266 | 27.9 | 39.8 | 29.1 | 62.0 | 77384 | None | None | None | None |
3 | 1909884550 | PASS | COMPLETE | True | 1 | 0 days 00:00:06.995000 | 0 days 00:00:08.971000 | alive | 569 | 569 | 77384 | 29.3 | 62.6 | 26.3 | 37.6 | 164266 | None | None | None | None |
4 | 1515097980 | PASS | COMPLETE | True | 1 | 0 days 00:00:08.971000 | NaT | alive | 569 | 569 | 164266 | 26.3 | 34.3 | 29.1 | 7.4 | None | None | None | None | None |
Load local tracking files¶
In [ ]:
Copied!
from kloppy import statsperform
dataset = statsperform.load_tracking(
ma1_data="../../kloppy/tests/files/statsperform_tracking_ma1.json",
ma25_data="../../kloppy/tests/files/statsperform_tracking_ma25.txt",
# Optional arguments
coordinates="statsperform",
only_alive=True,
limit=50,
sample_rate=(1/2),
pitch_length=102.5,
pitch_width=69.0,
tracking_system="sportvu",
)
dataset.to_df().head()
from kloppy import statsperform
dataset = statsperform.load_tracking(
ma1_data="../../kloppy/tests/files/statsperform_tracking_ma1.json",
ma25_data="../../kloppy/tests/files/statsperform_tracking_ma25.txt",
# Optional arguments
coordinates="statsperform",
only_alive=True,
limit=50,
sample_rate=(1/2),
pitch_length=102.5,
pitch_width=69.0,
tracking_system="sportvu",
)
dataset.to_df().head()
Out[ ]:
period_id | timestamp | frame_id | ball_state | ball_owning_team_id | ball_x | ball_y | ball_z | ball_speed | a2s2c6anax9wnlsw1s6vunl5h_x | ... | 6wfwy94p5bm0zv3aku0urfq39_d | 6wfwy94p5bm0zv3aku0urfq39_s | 6ekdnbnk56xlxforb5owt3dn9_x | 6ekdnbnk56xlxforb5owt3dn9_y | 6ekdnbnk56xlxforb5owt3dn9_d | 6ekdnbnk56xlxforb5owt3dn9_s | ct32113pfx5q9avf2c0x208ru_x | ct32113pfx5q9avf2c0x208ru_y | ct32113pfx5q9avf2c0x208ru_d | ct32113pfx5q9avf2c0x208ru_s | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 days 00:00:00 | 1598184000000 | alive | None | 52.350 | 33.250 | 0.0 | None | 52.803 | ... | None | None | 5.268 | 33.556 | None | None | NaN | NaN | None | None |
1 | 1 | 0 days 00:00:00.100000 | 1598184000100 | alive | None | 50.615 | 35.325 | 0.0 | None | 52.558 | ... | None | None | 5.265 | 33.529 | None | None | NaN | NaN | None | None |
2 | 1 | 0 days 00:00:00.200000 | 1598184000200 | alive | None | 49.630 | 36.140 | 0.0 | None | 52.310 | ... | None | None | 5.264 | 33.502 | None | None | NaN | NaN | None | None |
3 | 1 | 0 days 00:00:00.300000 | 1598184000300 | alive | None | 48.725 | 36.625 | 0.0 | None | 52.059 | ... | None | None | 5.268 | 33.476 | None | None | NaN | NaN | None | None |
4 | 1 | 0 days 00:00:00.400000 | 1598184000400 | alive | None | 47.890 | 37.130 | 0.0 | None | 51.804 | ... | None | None | 5.277 | 33.452 | None | None | NaN | NaN | None | None |
5 rows × 101 columns
In [ ]:
Copied!
from kloppy import statsperform
dataset = statsperform.load_tracking(
ma1_data="../../kloppy/tests/files/statsperform_tracking_ma1.xml",
ma25_data="../../kloppy/tests/files/statsperform_tracking_ma25.txt",
# Optional arguments
coordinates="statsperform",
only_alive=True,
limit=50,
sample_rate=(1/2),
pitch_length=102.5,
pitch_width=69.0,
tracking_system="sportvu",
)
dataset.to_df().head()
from kloppy import statsperform
dataset = statsperform.load_tracking(
ma1_data="../../kloppy/tests/files/statsperform_tracking_ma1.xml",
ma25_data="../../kloppy/tests/files/statsperform_tracking_ma25.txt",
# Optional arguments
coordinates="statsperform",
only_alive=True,
limit=50,
sample_rate=(1/2),
pitch_length=102.5,
pitch_width=69.0,
tracking_system="sportvu",
)
dataset.to_df().head()
Out[ ]:
period_id | timestamp | frame_id | ball_state | ball_owning_team_id | ball_x | ball_y | ball_z | ball_speed | a2s2c6anax9wnlsw1s6vunl5h_x | ... | 6wfwy94p5bm0zv3aku0urfq39_d | 6wfwy94p5bm0zv3aku0urfq39_s | 6ekdnbnk56xlxforb5owt3dn9_x | 6ekdnbnk56xlxforb5owt3dn9_y | 6ekdnbnk56xlxforb5owt3dn9_d | 6ekdnbnk56xlxforb5owt3dn9_s | ct32113pfx5q9avf2c0x208ru_x | ct32113pfx5q9avf2c0x208ru_y | ct32113pfx5q9avf2c0x208ru_d | ct32113pfx5q9avf2c0x208ru_s | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 days 00:00:00 | 1598184000000 | alive | None | 52.350 | 33.250 | 0.0 | None | 52.803 | ... | None | None | 5.268 | 33.556 | None | None | NaN | NaN | None | None |
1 | 1 | 0 days 00:00:00.100000 | 1598184000100 | alive | None | 50.615 | 35.325 | 0.0 | None | 52.558 | ... | None | None | 5.265 | 33.529 | None | None | NaN | NaN | None | None |
2 | 1 | 0 days 00:00:00.200000 | 1598184000200 | alive | None | 49.630 | 36.140 | 0.0 | None | 52.310 | ... | None | None | 5.264 | 33.502 | None | None | NaN | NaN | None | None |
3 | 1 | 0 days 00:00:00.300000 | 1598184000300 | alive | None | 48.725 | 36.625 | 0.0 | None | 52.059 | ... | None | None | 5.268 | 33.476 | None | None | NaN | NaN | None | None |
4 | 1 | 0 days 00:00:00.400000 | 1598184000400 | alive | None | 47.890 | 37.130 | 0.0 | None | 51.804 | ... | None | None | 5.277 | 33.452 | None | None | NaN | NaN | None | None |
5 rows × 101 columns
Load remote files¶
Kloppy supports remote files through fsspec
FileSystem under the hood. This allows you to work with files in AWS S3, Google Cloud, Azure Blob, HDFS, FTP, and SFTP without extra tools.
For example you can pass:
- Individual s3 file paths: (e.g
ma1_data=s3://.../statsperform_event_ma1.xml
)
Note: Kloppy might throw an the first time to help you identify missing cloud specific dependencies like s3fs
.
In [ ]:
Copied!
from kloppy import statsbomb
dataset = statsperform.load_event(
ma1_data="s3://.../statsperform_event_ma1.xml",
ma3_data="s3://.../statsperform_event_ma3.xml",
# Optional arguments
coordinates="opta",
pitch_length=102.5,
pitch_width=69.0,
event_types=["pass", "shot"],
)
from kloppy import statsbomb
dataset = statsperform.load_event(
ma1_data="s3://.../statsperform_event_ma1.xml",
ma3_data="s3://.../statsperform_event_ma3.xml",
# Optional arguments
coordinates="opta",
pitch_length=102.5,
pitch_width=69.0,
event_types=["pass", "shot"],
)