Skip to content

Adding a transform function to overlay teams #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

douglaspampu
Copy link
Contributor

Adding a new transformation function intended to position all players in a frame pointing to the same direction, overlaying them instead of the traditional orientation where tam A faces team B

This PR implements the issue #253

Some questions I have about the issue and this implementation are:

  • I am creating a new transform for the tracking dataset, would the events dataset benefit of this transformation as well?
  • I am implementing this transformation using the flip_point function on the players facing left-to-right, does the flip_point does the symmetry transformation @probberechts suggested on the issue?
  • From a functional point of view, if I overlay the players on the field this way, the teams would be overlaid, but when I have an attacker facing a defender the transform would position them in opposite places of the field (defender is moved to the right side of the pitch and attacker to the left side) is this the expected behavior?

Appreciate any comments on this @probberechts and @DriesDeprest

@douglaspampu douglaspampu force-pushed the transform branch 2 times, most recently from 85f987a to a1cf591 Compare January 14, 2025 14:03
@probberechts
Copy link
Contributor

Let's illustrate how I think it should work. Assume we have a dataset with two corner kicks. One by the blue team and one by the red team. For each corner kick there is one defender in the penalty area.

Untitled-1-01

After a "MirrorHorizontal"1 operation, it should look like this.

Untitled-1-02

Next, after a "MirrorVertical" operation, it should look like this.

Untitled-1-03

I am creating a new transform for the tracking dataset, would the events dataset benefit of this transformation as well?

Ideally, this works for both event and tracking data.

I am implementing this transformation using the flip_point function on the players facing left-to-right, does the flip_point does the symmetry transformation @probberechts suggested on the issue?

Yes, you can use it for the "MirrorHorizontal" operation.

Footnotes

  1. I am not sure about the best name for this operation yet.

@DriesDeprest
Copy link
Contributor

DriesDeprest commented Jan 15, 2025

To be clear, what I wanted to achieve with: #253 is the following:

image

@douglaspampu
Copy link
Contributor Author

Hi @probberechts and @DriesDeprest Thanks for your explanations and examples! this makes things a lot clearer.

One comment I would like to make is that each one of you have a different feature in mind. @probberechts is suggesting is applying horizontal and vertical transformations until we can overlay different actions, like the corner kicks in his example. For that, we could have the "mirror_vertical" and "mirror_horizontal" functions available for the user to apply over all players in a frame or event until they have these players rotated to a specific position.
On the corners, for example, we would apply mirror_vertical and mirror_horizontal on the top left corner. But we would apply just the mirror_horizontal on the top right corner.

On another hand, @DriesDeprest suggestion seems to be overlaying formations. I would rotate one of the teams for two players playing on the same position for opposed teams to be on the same position on the field. But, in this case, if I apply this transform for the corners I would rotate the corner kicker but not the defender.
I can see the importance for this feature if I am analyzing just the attacking actions of one team over time regardless of the defenders of the other team (or even on different matches).

For this one, it would be possible to refactor the flip_point to call a "mirror_vertical" and "mirror_horizontal" functions and then also expose these new functions to allow for both suggestions

@probberechts
Copy link
Contributor

If I understand it correctly, what @DriesDeprest suggests is the combination of a MirrorHorizontal + MirrorVertical operation (in his example applied to the away team). I considered that both of these operations would be useful, hence why I initially proposed to split it up in those two transformations.

@douglaspampu
Copy link
Contributor Author

@probberechts and @DriesDeprest
I refactored the code to do a horizontal mirror, flip point on the x axis, and a vertical mirror, flip over the y axis.

I kept the overlay option to flip the coordinates of the team facing left to right, but this is now using the the mirror operations.
I also exposed the mirror vertical and horizontal options on the transform function to allow the suggestion of rotating frames to have all the corners starting from the same position.

Appreciate any comment you have over this! If this implementation is good I will add support for events as well

@probberechts
Copy link
Contributor

I still think we need a different "concept" for these kinds of data operations. They are clearly a different operation than changing the orientation or pitch dimensions. Cfr. my previous remark:

Orientation transforms merely switch perspectives without altering the underlying data, similar to changing the camera angle. On the other hand, symmetry transforms modify the relationships between data points. So maybe we should create a different kind of transformation for this.

Currently, I find both the API and implementation a bit messy and I feel that separating things will help.

Maybe we should define these operations as Normalizers since we are essentially transforming the data so that all events/movements are treated as if they come from the same reference point on the pitch.

dataset
.transform(...)
.normalize_playing_direction(direction='left_to_right', ...)
.normalize_side_of_pitch(side='left', ...)

or

dataset
.transform(...)
.normalize(playing_direction='left_to_right', side_of_pitch='left')

Apologies if this causes any confusion—I'm just brainstorming some ideas. But I feel that we should first precisely define what we exactly want and carefully think through the API design.

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.

3 participants