Skip to content
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

Accurate transformation of pitch dimensions #297

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

probberechts
Copy link
Contributor

@probberechts probberechts commented Feb 24, 2024

This PR is a complete rewrite of the "PitchDimensions" domain model. It implements the following main features.

  1. It implements piecewise linear transformations in each dimension (see Stats Perform MA3 docs, appendix 7) to reduce the error when transforming between different coordinate systems.
transformer = DatasetTransformer(
    from_pitch_dimensions=OptaPitchDimensions(),
    to_pitch_dimensions=MetricPitchDimensions(
        x_dim=Dimension(0, 105),
        y_dim=Dimension(0, 68),
        pitch_length=105,
        pitch_width=68,
        standardized=False,
    ),
)

transformed_point = transformer.change_point_dimensions(
    Point(17, 78.9)   # the corner of the penalty area...
)
# ... remains the corner of the penalty area
assert transformed_point == Point(16.5, 54.16)
  1. It makes it possible to compute distances between two points without having to transform the entire dataset to a metric coordinate system.
pitch = OptaPitchDimensions(pitch_length=105, pitch_width=68)
distance = pitch.distance_between(Point(0, 50), Point(11.5, 50))
assert distance == 11  # the distance from the goal line to penalty spot should be 11m
  1. Fixes Different unit used for shot_event.result_coordinates.z dimension for Opta vs StatsBomb #293
  2. Allows creating pitch dimensions with unknown boundaries. This will allow solving Incorrect Stats Perform coordinate system #299 .

BREAKING CHANGES:

This changes the interface of the PitchDimensions class.

This commit is a rewrite of the "PitchDimensions" model. It implements two main features.

1. It implements piecewise linear transformations in each dimension (see Stats Perform MA3 docs, appendix 7) to reduce the error when transforming between different coordinate system. For example, a point that is inside the penalty area will remain inside the area after a transformation to a different coordinate system.

2. It makes it possible to compute distances between two points without having to transform the entire dataset to a metric coordinate system.
@probberechts probberechts marked this pull request as draft February 25, 2024 10:19
@probberechts probberechts marked this pull request as ready for review February 25, 2024 17:18
y = 1 - y
point_base = replace(
point_base,
y=68 - point_base.y,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bit of a magic number here. Can it be moved to some other place or to a 'constant' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it by a constant + optimized it a bit more to avoid unneeded conversions between dimensions.

@koenvo
Copy link
Contributor

koenvo commented Apr 2, 2024

One minor comment. Other than that (and the merge conflict) happy to merge!

@koenvo koenvo merged commit c00a461 into PySport:master Apr 4, 2024
19 checks passed
@koenvo koenvo added this to the 3.15 milestone Apr 4, 2024
@probberechts probberechts deleted the feat/pitchdimensions branch April 25, 2024 13:51
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.

Different unit used for shot_event.result_coordinates.z dimension for Opta vs StatsBomb
2 participants