PySport / kloppy

kloppy: standardizing soccer tracking- and event data
https://kloppy.pysport.org
BSD 3-Clause "New" or "Revised" License
362 stars 59 forks source link

Accurate transformation of pitch dimensions #297

Closed probberechts closed 6 months ago

probberechts commented 7 months ago

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 #293
  2. Allows creating pitch dimensions with unknown boundaries. This will allow solving #299 .

BREAKING CHANGES:

This changes the interface of the PitchDimensions class.

koenvo commented 6 months ago

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