Skip to content

Conversation

@UnravelSports
Copy link
Contributor

As discussed here #464

@probberechts not sure if this is the only thing that needs fixing

@UnravelSports UnravelSports changed the title [StatsBomb] Freeze frame indent issue fix [StatsBomb] Freeze Frame parsing and transforming Jun 18, 2025
@UnravelSports
Copy link
Contributor Author

I have added a fix for the second point from Issue (#483).

The main problem, besides the earlier identified incorrect indent in the freeze frame parsing is that inside the StatsBomb parser we first loop over the events and potentially transform them in orientation or coordinate system. Then, we loop over all events again and parse the freeze frames. While doing this we call transform on the whole freeze frame again, including the ball coordinates. However, in parse_freeze_frame the ball coordinates are taken directly from the already transformed events.

This means we would transform the ball coordinates twice. This was identified by @jan-swiatek in Issue #464 (comment).

I've added a parameter transform_ball_coordinates to transformer.transform_frame() that defaults to True, but is set to False inside the below section. This is subsequently propagated to __change_frame_coordinate_system, __change_frame_dimensions and __flip_frame.

for event in dataset:
    if "freeze_frame" in event.raw_event.get("shot", {}):
        event.freeze_frame = self.transformer.transform_frame(
            parse_freeze_frame(
                freeze_frame=event.raw_event["shot"]["freeze_frame"],
                home_team=teams[0],
                away_team=teams[1],
                event=event,
                fidelity_version=data_version.shot_fidelity_version,
            ),
            transform_ball_coordinates=False,
        )
    if not event.freeze_frame and event.event_id in three_sixty_data:
        freeze_frame = three_sixty_data[event.event_id]
        event.freeze_frame = self.transformer.transform_frame(
            parse_freeze_frame(
                freeze_frame=freeze_frame["freeze_frame"],
                home_team=teams[0],
                away_team=teams[1],
                event=event,
                fidelity_version=data_version.xy_fidelity_version,
                visible_area=freeze_frame["visible_area"],
            ),
            transform_ball_coordinates=False,
        )

This means we now skip transforming the ball coordinates for a second time when parsing the freeze frames.

Obligatory: This is not a very clean fix, but I don't see an easier way to untangle this mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant