Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kloppy/_providers/secondspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def load(
limit: Optional[int] = None,
coordinates: Optional[str] = None,
only_alive: Optional[bool] = False,
exclude_missing_ball_frames: Optional[bool] = False,
) -> TrackingDataset:
"""
Load SecondSpectrum tracking data.
Expand All @@ -30,6 +31,7 @@ def load(
limit: Limit the number of frames to load to the first `limit` frames.
coordinates: The coordinate system to use.
only_alive: Only include frames in which the game is not paused.
exclude_missing_ball_frames: SecondSpectrum sets ball_z to -10 when ball is missing / out of frame. True excludes these frames, False includes them.

Returns:
The parsed tracking data.
Expand All @@ -39,6 +41,7 @@ def load(
limit=limit,
coordinate_system=coordinates,
only_alive=only_alive,
exclude_missing_ball_frames=exclude_missing_ball_frames,
)
with (
open_as_file(meta_data) as meta_data_fp,
Expand Down
9 changes: 7 additions & 2 deletions kloppy/infra/serializers/tracking/secondspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,24 @@ def __init__(
sample_rate: Optional[float] = None,
coordinate_system: Optional[Union[str, Provider]] = None,
only_alive: Optional[bool] = True,
exclude_missing_ball_frames: Optional[bool] = False,
):
super().__init__(limit, sample_rate, coordinate_system)
self.only_alive = only_alive
self.exclude_missing_ball_frames = exclude_missing_ball_frames

@property
def provider(self) -> Provider:
return Provider.SECONDSPECTRUM

@classmethod
def _frame_from_framedata(cls, teams, period, frame_data):
def _frame_from_framedata(self, teams, period, frame_data):
frame_id = frame_data["frameIdx"]
frame_timestamp = timedelta(seconds=frame_data["gameClock"])

if frame_data["ball"]["xyz"]:
ball_x, ball_y, ball_z = frame_data["ball"]["xyz"]
if self.exclude_missing_ball_frames and ball_z == -10:
return
ball_coordinates = Point3D(
float(ball_x), float(ball_y), float(ball_z)
)
Expand Down Expand Up @@ -301,6 +304,8 @@ def _iter():
period = periods[frame_data["period"] - 1]

frame = self._frame_from_framedata(teams, period, frame_data)
if not frame:
continue
frame = transformer.transform_frame(frame)
frames.append(frame)

Expand Down
Loading
Loading