Skip to content

Commit f5dcad8

Browse files
authored
Patch release 0.3.1 (#124)
Add Feature/team classification callback Fix GitPython related error in colab environments
1 parent ea755ab commit f5dcad8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1152
-1438
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.ONESHELL:
2-
.PHONY: clean data lint requirements tests create_environment install_develop develop_tests full_develop_test
2+
.PHONY: clean data lint requirements tests create_environment install_develop develop_tests full_develop_test pyupgrade autofix all_checks ruff mypy docstring help
33

44
#################################################################################
55
# GLOBALS #
@@ -28,11 +28,23 @@ mypy:
2828
$(CONDA_ACTIVATE) && \
2929
mypy $(i)
3030

31+
## Upgrade code to Python 3.10
32+
pyupgrade:
33+
$(CONDA_ACTIVATE) && \
34+
pyupgrade --py310-plus $(i)
35+
3136
## Check docstrings with pep257
3237
docstring:
3338
$(CONDA_ACTIVATE) && \
3439
pep257 $(i)
3540

41+
## Run auto-fix
42+
autofix:
43+
$(CONDA_ACTIVATE) && \
44+
find $(i) -name '*.py' -exec pyupgrade --py310-plus {} \; && \
45+
ruff check --fix $(i) && \
46+
black $(i)
47+
3648
## Run all checks
3749
all_checks: lint mypy docstring
3850

notebooks/02_user_guide/02_dataframe_visualization.ipynb

Lines changed: 271 additions & 1131 deletions
Large diffs are not rendered by default.

notebooks/02_user_guide/wip_09_callbacks.ipynb

Lines changed: 153 additions & 0 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sportslabkit"
3-
version = "0.3.0"
3+
version = "0.3.1a3"
44
description = "A Python package for sports analytics."
55
readme = "README.md"
66
authors = ["Atom Scott <[email protected]>"]
@@ -45,7 +45,7 @@ follow_imports = "skip"
4545
strict_optional = true
4646

4747
[tool.pep257]
48-
ignore = ["D100", "D101", "D105", "D200", "D202", "D411", "D213", "D413", "D406", "D407"]
48+
ignore = ["D100", "D101", "D105", "D200", "D202", "D203", "D411", "D213", "D413", "D406", "D407"]
4949
add_ignore = ["D102", "D103"]
5050

5151
[tool.pytest.ini_options]

sportslabkit/callbacks.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

sportslabkit/camera/calibrate.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from vidgear.gears.stabilizer import Stabilizer
88

99
from sportslabkit.logger import logger, tqdm
10-
from sportslabkit.types.types import _pathlike
10+
from sportslabkit.types.types import PathLike
1111
from sportslabkit.utils import make_video
1212

1313

@@ -170,10 +170,10 @@ def calibrate_camera_fisheye(objpoints, imgpoints, dim, balance=1):
170170

171171

172172
def find_intrinsic_camera_parameters(
173-
media_path: _pathlike,
173+
media_path: PathLike,
174174
fps: int = 1,
175175
scale: int = 4,
176-
save_path: _pathlike | None = None,
176+
save_path: PathLike | None = None,
177177
draw_on_save: bool = False,
178178
points_to_use: int = 50,
179179
calibration_method: str = "zhang",
@@ -202,6 +202,7 @@ def find_intrinsic_camera_parameters(
202202

203203
# Support multiple video files
204204
from sportslabkit.camera import Camera
205+
205206
camera = Camera(media_path)
206207

207208
# Find corners in each video
@@ -236,10 +237,10 @@ def find_intrinsic_camera_parameters(
236237

237238

238239
def calibrate_video_from_mappings(
239-
media_path: _pathlike,
240+
media_path: PathLike,
240241
mapx: NDArray,
241242
mapy: NDArray,
242-
save_path: _pathlike,
243+
save_path: PathLike,
243244
stabilize: bool = True,
244245
):
245246
"""
@@ -260,6 +261,7 @@ def generator():
260261
stab = Stabilizer()
261262

262263
from sportslabkit.camera import Camera
264+
263265
camera = Camera(media_path)
264266
for frame in camera:
265267
stab_frame = stab.stabilize(frame)

sportslabkit/camera/camera.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import (
6-
Dict,
7-
Generator,
8-
List,
9-
Mapping,
10-
Optional,
11-
Sequence,
12-
Tuple,
13-
)
5+
from collections.abc import Generator, Mapping, Sequence
146
from xml.etree import ElementTree
157

168
import cv2 as cv
@@ -19,24 +11,24 @@
1911

2012
from sportslabkit.camera.calibrate import find_intrinsic_camera_parameters
2113
from sportslabkit.camera.videoreader import VideoReader
22-
from sportslabkit.types.types import _pathlike
14+
from sportslabkit.types.types import PathLike
2315
from sportslabkit.utils import logger
2416

2517

2618
class Camera(VideoReader):
2719
def __init__(
2820
self,
29-
video_path: _pathlike,
21+
video_path: PathLike,
3022
threaded: bool = False,
3123
queue_size: int = 10,
32-
keypoint_xml: Optional[str] = None,
33-
x_range: Optional[Sequence[float]] = (0, 105),
34-
y_range: Optional[Sequence[float]] = (0, 68),
35-
camera_matrix: Optional[ArrayLike] = None,
36-
camera_matrix_path: Optional[str] = None,
37-
distortion_coefficients: Optional[str] = None,
38-
distortion_coefficients_path: Optional[str] = None,
39-
calibration_video_path: Optional[str] = None,
24+
keypoint_xml: str | None = None,
25+
x_range: Sequence[float] | None = (0, 105),
26+
y_range: Sequence[float] | None = (0, 68),
27+
camera_matrix: ArrayLike | None = None,
28+
camera_matrix_path: str | None = None,
29+
distortion_coefficients: str | None = None,
30+
distortion_coefficients_path: str | None = None,
31+
calibration_video_path: str | None = None,
4032
calibration_method: str = "zhang",
4133
label: str = "",
4234
verbose: int = 0,
@@ -272,7 +264,7 @@ def max(self):
272264
return 255
273265

274266
@property
275-
def keypoint_map(self) -> Dict[Tuple[int, int], Tuple[int, int]]:
267+
def keypoint_map(self) -> dict[tuple[int, int], tuple[int, int]]:
276268
"""Get dictionary of pitch keypoints in pitch space to pixel space.
277269
278270
Returns:
@@ -308,7 +300,7 @@ def H(self) -> NDArray[np.float64]:
308300
return H
309301

310302

311-
def read_pitch_keypoints(xmlfile: str, annot_type: str) -> Tuple[NDArray[np.float64], NDArray[np.float64]]:
303+
def read_pitch_keypoints(xmlfile: str, annot_type: str) -> tuple[NDArray[np.float64], NDArray[np.float64]]:
312304
"""Read pitch keypoints from xml file.
313305
314306
Args:
@@ -352,7 +344,7 @@ def read_pitch_keypoints(xmlfile: str, annot_type: str) -> Tuple[NDArray[np.floa
352344
return src, dst
353345

354346

355-
def load_cameras(camera_info: List[Mapping]) -> List[Camera]:
347+
def load_cameras(camera_info: list[Mapping]) -> list[Camera]:
356348
"""Load cameras from a list of dictionaries containing camera information.
357349
358350
Args:

sportslabkit/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Sequence
5+
from collections.abc import Sequence
66

77
import numpy as np
88

sportslabkit/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from glob import glob
3-
from typing import Optional
43

54
import gdown
65
import numpy as np
@@ -87,7 +86,7 @@ def calibrate_from_npz(
8786
npzfile: str,
8887
output: str,
8988
calibration_method: str = "zhang",
90-
keypoint_xml: Optional[str] = None,
89+
keypoint_xml: str | None = None,
9190
**kwargs,
9291
):
9392
"""Calibrate a video using precomputed calibration parameters
@@ -138,7 +137,7 @@ def calibrate(
138137
scale: int = 1,
139138
pts: int = 50,
140139
calibration_method: str = "zhang",
141-
keypoint_xml: Optional[str] = None,
140+
keypoint_xml: str | None = None,
142141
):
143142
"""Calibrate video from input
144143

sportslabkit/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
from pathlib import Path
3+
4+
5+
CACHE_DIR = Path(os.path.expanduser("~/.cache/sportslabkit/"))

0 commit comments

Comments
 (0)