Skip to content

CoordinateSystem

kloppy.domain.CoordinateSystem

Bases: ABC

Base class for coordinate systems.

A coordinate system defines how coordinates are represented in a dataset.

ATTRIBUTE DESCRIPTION
origin

The location of the origin.

TYPE: Origin

vertical_orientation

The orientation of the y-axis.

TYPE: VerticalOrientation

pitch_dimensions

The dimensions of the pitch.

TYPE: PitchDimensions

normalized

Whether the pitch dimensions are normalized. This means that the coordinates are mapped to a fixed range, e.g. from 0 to 1. In contrast, non-normalized coordinates correspond to the real-world dimensions of the pitch.

TYPE: bool

pitch_length

The real length of the pitch.

TYPE: float

pitch_width

The real width of the pitch.

TYPE: float

origin abstractmethod property

origin

vertical_orientation abstractmethod property

vertical_orientation

pitch_dimensions abstractmethod property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.CustomCoordinateSystem

1
2
3
CustomCoordinateSystem(
    origin, vertical_orientation, pitch_dimensions
)

Bases: CoordinateSystem

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    origin: Origin,
    vertical_orientation: VerticalOrientation,
    pitch_dimensions: PitchDimensions,
):
    self._origin = origin
    self._vertical_orientation = vertical_orientation
    self._pitch_dimensions = pitch_dimensions

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.ProviderCoordinateSystem

1
2
3
ProviderCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: CoordinateSystem

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider abstractmethod property

provider

origin abstractmethod property

origin

vertical_orientation abstractmethod property

vertical_orientation

pitch_dimensions abstractmethod property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.KloppyCoordinateSystem

KloppyCoordinateSystem(pitch_length=None, pitch_width=None)

Bases: ProviderCoordinateSystem

Kloppy's default coordinate system.

Uses a normalized pitch with the origin at the top left and the y-axis oriented from top to bottom. The coordinates range from 0 to 1.

If no pitch length and width are provided, the default pitch dimensions are 105m x 68m.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.DatafactoryCoordinateSystem

1
2
3
DatafactoryCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

Datafactory coordinate system.

Uses a normalized pitch with the origin at the top left and the y-axis oriented from top to bottom. The coordinates range from -1 to 1.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.HawkEyeCoordinateSystem

1
2
3
HawkEyeCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

HawkEye coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.MetricaCoordinateSystem

1
2
3
MetricaCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: KloppyCoordinateSystem

Metrica coordinate system.

Uses a normalized pitch with the origin at the top left and the y-axis oriented from top to bottom. The coordinates range from 0 to 1.

If no pitch length and width are provided, the default pitch dimensions are 105m x 68m.

Notes

The Metrica coordinate system is the same as the KloppyCoordinateSystem.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin abstractmethod property

origin

vertical_orientation abstractmethod property

vertical_orientation

pitch_dimensions abstractmethod property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.OptaCoordinateSystem

OptaCoordinateSystem(pitch_length=None, pitch_width=None)

Bases: ProviderCoordinateSystem

Opta coordinate system.

Uses a normalized pitch with the origin at the bottom left and the y-axis oriented from bottom to top. The coordinates range from 0 to 100.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.PFFCoordinateSystem

PFFCoordinateSystem(pitch_length=None, pitch_width=None)

Bases: ProviderCoordinateSystem

PFF coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.SecondSpectrumCoordinateSystem

1
2
3
SecondSpectrumCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

Second Spectrum coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.SkillCornerCoordinateSystem

1
2
3
SkillCornerCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

SkillCorner coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.SportVUCoordinateSystem

1
2
3
SportVUCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

StatsPerform SportVU coordinate system.

Uses a pitch with the origin at the top left and the y-axis oriented from top to bottom. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.SportecEventDataCoordinateSystem

1
2
3
SportecEventDataCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

Sportec event data coordinate system.

Uses a pitch with the origin at the bottom left and the y-axis oriented from top to bottom. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.SportecTrackingDataCoordinateSystem

1
2
3
SportecTrackingDataCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

Sportec tracking data coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in meters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.StatsBombCoordinateSystem

1
2
3
StatsBombCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

StatsBomb coordinate system.

Uses a normalized pitch with the origin at the top left and the y-axis oriented from top to bottom. The x-coordinates range from 0 to 120 and the y-coordinates range from 0 to 80.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.TracabCoordinateSystem

TracabCoordinateSystem(pitch_length=None, pitch_width=None)

Bases: ProviderCoordinateSystem

Tracab coordinate system.

Uses a pitch with the origin at the center and the y-axis oriented from bottom to top. The coordinates are in centimeters.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim

kloppy.domain.WyscoutCoordinateSystem

1
2
3
WyscoutCoordinateSystem(
    pitch_length=None, pitch_width=None
)

Bases: ProviderCoordinateSystem

Wyscout coordinate system.

Uses a normalized pitch with the origin at the top left and the y-axis oriented from top to bottom. The coordinates range from 0 to 100.

Source code in kloppy/domain/models/common.py
def __init__(
    self,
    pitch_length: Optional[float] = None,
    pitch_width: Optional[float] = None,
):
    self._pitch_length = pitch_length
    self._pitch_width = pitch_width

provider property

provider

origin property

origin

vertical_orientation property

vertical_orientation

pitch_dimensions property

pitch_dimensions

normalized property

normalized

pitch_length property

pitch_length

pitch_width property

pitch_width

to_mplsoccer

to_mplsoccer()

"Convert the coordinate system to a mplsoccer BaseDims object.

Example:

from kloppy.domain import KloppyCoordinateSystem from mplsoccer import Pitch coordinate_system = KloppyCoordinateSystem() pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

Note

This method is experimental and may change in the future.

Source code in kloppy/domain/models/common.py
def to_mplsoccer(self):
    """ "Convert the coordinate system to a mplsoccer BaseDims object.

    Example:
    >>> from kloppy.domain import KloppyCoordinateSystem
    >>> from mplsoccer import Pitch
    >>> coordinate_system = KloppyCoordinateSystem()
    >>> pitch = Pitch(dimensions=coordinate_system.to_mplsoccer())

    Note:
        This method is experimental and may change in the future.
    """
    try:
        from mplsoccer.dimensions import BaseDims
    except ImportError:
        raise ImportError(
            "Seems like you don't have `mplsoccer` installed. "
            "Please install it using: pip install mplsoccer"
        )

    if (
        self.pitch_dimensions.x_dim.min is None
        or self.pitch_dimensions.x_dim.max is None
    ):
        raise ValueError(
            "The x-dimensions of the pitch must be fully defined."
        )
    if (
        self.pitch_dimensions.y_dim.min is None
        or self.pitch_dimensions.y_dim.max is None
    ):
        raise ValueError(
            "The y-dimensions of the pitch must be fully defined."
        )

    pitch_length = (
        self.pitch_dimensions.pitch_length or DEFAULT_PITCH_LENGTH
    )
    pitch_width = self.pitch_dimensions.pitch_width or DEFAULT_PITCH_WIDTH

    invert_y = (
        self.vertical_orientation == VerticalOrientation.TOP_TO_BOTTOM
    )
    origin_center = self.origin == Origin.CENTER

    neg_if_inverted = -1 if invert_y else 1
    center = (0, 0)
    if self.origin == Origin.BOTTOM_LEFT:
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )
    elif self.origin == Origin.TOP_LEFT:
        neg_if_inverted = -1
        center = (
            (
                self.pitch_dimensions.x_dim.max
                - self.pitch_dimensions.x_dim.min
            )
            / 2,
            (
                self.pitch_dimensions.y_dim.max
                - self.pitch_dimensions.y_dim.min
            )
            / 2,
        )

    dim = BaseDims(
        left=self.pitch_dimensions.x_dim.min,
        right=self.pitch_dimensions.x_dim.max,
        bottom=self.pitch_dimensions.y_dim.min
        if not invert_y
        else self.pitch_dimensions.y_dim.max,
        top=self.pitch_dimensions.y_dim.max
        if not invert_y
        else self.pitch_dimensions.y_dim.min,
        width=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.x_dim.min,
        length=self.pitch_dimensions.y_dim.max
        - self.pitch_dimensions.y_dim.min,
        goal_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        goal_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.goal_width),
        six_yard_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.six_yard_length,
        six_yard_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.six_yard_length,
        six_yard_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        six_yard_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.six_yard_width),
        penalty_spot_distance=self.pitch_dimensions.penalty_spot_distance,
        penalty_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_spot_distance,
        penalty_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_spot_distance,
        penalty_area_left=self.pitch_dimensions.x_dim.min
        + self.pitch_dimensions.penalty_area_length,
        penalty_area_right=self.pitch_dimensions.x_dim.max
        - self.pitch_dimensions.penalty_area_length,
        penalty_area_bottom=center[1]
        - (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        penalty_area_top=center[1]
        + (neg_if_inverted / 2 * self.pitch_dimensions.penalty_area_width),
        center_width=center[1],
        center_length=center[0],
        goal_width=self.pitch_dimensions.goal_width,
        goal_length=self.pitch_dimensions.goal_height,
        six_yard_width=self.pitch_dimensions.six_yard_width,
        six_yard_length=self.pitch_dimensions.six_yard_length,
        penalty_area_width=self.pitch_dimensions.penalty_area_width,
        penalty_area_length=self.pitch_dimensions.penalty_area_length,
        circle_diameter=self.pitch_dimensions.circle_radius * 2,
        corner_diameter=self.pitch_dimensions.corner_radius * 2,
        arc=0,
        invert_y=invert_y,
        origin_center=origin_center,
        pad_default=0.02
        * (
            self.pitch_dimensions.x_dim.max
            - self.pitch_dimensions.x_dim.min
        ),
        pad_multiplier=1,
        aspect_equal=False
        if self.pitch_dimensions.unit == Unit.NORMED
        else True,
        pitch_width=pitch_width,
        pitch_length=pitch_length,
        aspect=pitch_width / pitch_length
        if self.pitch_dimensions.unit == Unit.NORMED
        else 1.0,
    )
    return dim