Second-phase corner sequences

wa_setpieces.core.phases classifies what happens after a corner is delivered: was it cleared immediately, did it produce a direct shot, or did the ball stay alive for a second-phase shot (a knockdown, blocked clearance, or loose ball the attacking team won again before the danger was cleared).

Note the defending team’s events are recorded in their own attacking direction, so we mirror them onto the attacking team’s frame with wa_setpieces.to_reference_frame() before plotting anything – see that function’s docstring for how this was verified against the data.

from pathlib import Path

from wa_setpieces import load_matches
from wa_setpieces.core.phases import second_phases
from wa_setpieces.viz.plots import plot_second_phase

try:
    _here = Path(__file__).resolve().parent
except NameError:
    _here = Path.cwd()
DATA = _here.parent / "tests" / "data" / "sample_match.json"

events = load_matches(DATA)

Classify every corner in the match:

corners = second_phases(events, "corner")
corners[["delivery_event_id", "cleared_immediately", "second_phase_shot", "phase_events_n"]]
delivery_event_id cleared_immediately second_phase_shot phase_events_n
0 191 False False 11
1 223 False False 5
2 404 False False 11
3 482 False False 6
4 610 False True 5
5 613 False False 8
6 723 False False 9
7 730 False True 9
8 786 False False 1


Plot the sequence for the first corner that produced a second-phase shot. Numbered grey dots are the contested touches after the delivery; the gold dot is the shot that eventually resulted.

shot_corners = corners.loc[corners["second_phase_shot"], "delivery_event_id"]
fig, ax = plot_second_phase(events, int(shot_corners.iloc[0]))
plot 03 second phase

And one that was cleared immediately, for contrast:

cleared = corners.loc[corners["cleared_immediately"], "delivery_event_id"]
if not cleared.empty:
    fig, ax = plot_second_phase(events, int(cleared.iloc[0]))

Gallery generated by Sphinx-Gallery