-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create docs pages #87
Conversation
WalkthroughThe updates primarily refine the Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files ignored due to path filters (2)
Files selected for processing (19)
Files skipped from review due to trivial changes (3)
Additional Context UsedLanguageTool (109)
Ruff (35)
Additional comments not posted (7)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
=======================================
Coverage 95.46% 95.46%
=======================================
Files 13 14 +1
Lines 1632 1633 +1
=======================================
+ Hits 1558 1559 +1
Misses 74 74 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
Out of diff range and nitpick comments (4)
sleap_io/__init__.py (1)
Line range hint
3-26
: Many imports are unused. Consider removing them or adding them to__all__
if they are meant to be exposed as public API.- from sleap_io.version import __version__ - from sleap_io.model.skeleton import Node, Edge, Skeleton, Symmetry - from sleap_io.model.video import Video - from sleap_io.model.instance import ( - Point, - PredictedPoint, - Track, - Instance, - PredictedInstance, - ) - from sleap_io.model.labeled_frame import LabeledFrame - from sleap_io.model.labels import Labels - from sleap_io.io.main import ( - load_slp, - save_slp, - load_nwb, - save_nwb, - load_labelstudio, - save_labelstudio, - load_jabs, - save_jabs, - load_video, - load_file, - save_file, - )sleap_io/model/video.py (2)
Line range hint
9-9
: Remove duplicate import ofOptional
.- from typing import Tuple, Optional, Optional + from typing import Tuple, Optional
Line range hint
90-90
: Replace bareexcept
with specific exceptions to avoid catching unexpected errors.- except: + except AttributeError: # or other specific exceptionssleap_io/model/instance.py (1)
Line range hint
44-58
: Replace type comparison withisinstance()
for better practice.- if type(other) is not type(self): + if not isinstance(other, type(self)):
def __eq__(self, other: object) -> bool: | ||
"""Compare `self` and `other` for equality. | ||
|
||
See `Point.__eq__()` for important notes about point equality semantics! | ||
|
||
Args: | ||
self, other: instance of `PredictedPoint` to compare | ||
other: Instance of `PredictedPoint` to compare | ||
|
||
Returns: | ||
True if all attributes of `self` and `other` are the identical (possibly | ||
allowing precision error for `x` and `y` attributes). | ||
Returns True if all attributes of `self` and `other` are the identical | ||
(possibly allowing precision error for `x` and `y` attributes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace type comparison with isinstance()
for better practice.
- if not super().__eq__(other):
+ if not isinstance(other, PredictedPoint) or not super().__eq__(other):
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def __eq__(self, other: object) -> bool: | |
"""Compare `self` and `other` for equality. | |
See `Point.__eq__()` for important notes about point equality semantics! | |
Args: | |
self, other: instance of `PredictedPoint` to compare | |
other: Instance of `PredictedPoint` to compare | |
Returns: | |
True if all attributes of `self` and `other` are the identical (possibly | |
allowing precision error for `x` and `y` attributes). | |
Returns True if all attributes of `self` and `other` are the identical | |
(possibly allowing precision error for `x` and `y` attributes). | |
def __eq__(self, other: object) -> bool: | |
"""Compare `self` and `other` for equality. | |
See `Point.__eq__()` for important notes about point equality semantics! | |
Args: | |
other: Instance of `PredictedPoint` to compare | |
Returns: | |
Returns True if all attributes of `self` and `other` are the identical | |
(possibly allowing precision error for `x` and `y` attributes). | |
if not isinstance(other, PredictedPoint) or not super().__eq__(other): |
@@ -64,7 +64,7 @@ def load_labelstudio( | |||
"""Read Label Studio-style annotations from a file and return a `Labels` object. | |||
|
|||
Args: | |||
labels_path: Path to the label-studio annotation file in JSON format. | |||
filename: Path to the label-studio annotation file in JSON format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename parameter labels_path
to filename
to align with other I/O functions.
- filename: Path to the label-studio annotation file in JSON format.
+ labels_path: Path to the label-studio annotation file in JSON format.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
filename: Path to the label-studio annotation file in JSON format. | |
labels_path: Path to the label-studio annotation file in JSON format. |
@@ -119,7 +119,7 @@ def __getitem__(self, inds: int | list[int] | slice) -> np.ndarray: | |||
"""Return the frames of the video at the given indices. | |||
|
|||
Args: | |||
ind: Index or list of indices of frames to read. | |||
inds: Index or list of indices of frames to read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename parameter ind
to inds
to reflect that it can handle multiple indices.
- inds: Index or list of indices of frames to read.
+ ind: Index or list of indices of frames to read.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
inds: Index or list of indices of frames to read. | |
ind: Index or list of indices of frames to read. |
@@ -121,7 +121,7 @@ def write_group(parent_group, data_to_write): | |||
|
|||
|
|||
def read_hdf5_attrs( | |||
filename, dataset: str = "/", attribute: Optional[str] = None | |||
filename: str, dataset: str = "/", attribute: Optional[str] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit typing to the filename
parameter to improve type clarity.
- filename: str, dataset: str = "/", attribute: Optional[str] = None
+ filename: str | Path, dataset: str = "/", attribute: Optional[str] = None
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
filename: str, dataset: str = "/", attribute: Optional[str] = None | |
filename: str | Path, dataset: str = "/", attribute: Optional[str] = None |
The PyPI-compatible package settings are in [pyproject.toml]. | ||
|
||
The version number is set in [sleap_io/__init__.py] in the `__version__` variable. This is read automatically by setuptools during installation and build. | ||
The version number is set in [sleap_io/version.py] in the `__version__` variable. This is read automatically by setuptools during installation and build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the version number setting location to sleap_io/version.py
.
- The version number is set in [sleap_io/__init__.py] in the `__version__` variable.
+ The version number is set in [sleap_io/version.py] in the `__version__` variable.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
The PyPI-compatible package settings are in [pyproject.toml]. | |
The version number is set in [sleap_io/__init__.py] in the `__version__` variable. This is read automatically by setuptools during installation and build. | |
The version number is set in [sleap_io/version.py] in the `__version__` variable. This is read automatically by setuptools during installation and build. | |
The PyPI-compatible package settings are in [pyproject.toml]. | |
The version number is set in [sleap_io/version.py] in the `__version__` variable. This is read automatically by setuptools during installation and build. |
@@ -294,7 +294,7 @@ def filter_and_index(annotations: Iterable[dict], annot_type: str) -> Dict[str, | |||
"""Filter annotations based on the type field and index them by ID. | |||
|
|||
Args: | |||
annotation: annotations to filter and index | |||
annotations: annotations to filter and index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct typo in parameter name from annotation
to annotations
.
- annotations: annotations to filter and index
+ annotation: annotations to filter and index
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
annotations: annotations to filter and index | |
annotation: annotations to filter and index |
|
||
::: sleap_io.load_labelstudio | ||
|
||
::: sleap_io.save_labelstudio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure files end with a single newline character.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
::: sleap_io.save_labelstudio | |
::: sleap_io.save_labelstudio | |
@@ -0,0 +1,29 @@ | |||
# Data model | |||
|
|||
`sleap-io` implements the core data structures used in SLEAP for storing data related to multi-instance pose tracking, including for annotation, training and inference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence should start with an uppercase letter.
- `sleap-io` implements the core data structures used in SLEAP for storing data related to multi-instance pose tracking, including for annotation, training and inference.
+ `Sleap-io` implements the core data structures used in SLEAP for storing data related to multi-instance pose tracking, including for annotation, training and inference.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
`sleap-io` implements the core data structures used in SLEAP for storing data related to multi-instance pose tracking, including for annotation, training and inference. | |
`Sleap-io` implements the core data structures used in SLEAP for storing data related to multi-instance pose tracking, including for annotation, training and inference. |
|
||
::: sleap_io.Track | ||
|
||
::: sleap_io.Video |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure files end with a single newline character.
+
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
::: sleap_io.Video | |
::: sleap_io.Video | |
For development, use one of the following syntaxes: | ||
``` | ||
conda env create -f environment.yml | ||
``` | ||
``` | ||
pip install -e .[dev] | ||
``` | ||
|
||
## Usage | ||
|
||
### Load and save in different formats | ||
|
||
```py | ||
import sleap_io as sio | ||
|
||
# Load from SLEAP file. | ||
labels = sio.load_file("predictions.slp") | ||
|
||
# Save to NWB file. | ||
sio.save_file(labels, "predictions.nwb") | ||
# Or: | ||
# labels.save("predictions.nwb") | ||
``` | ||
|
||
### Convert labels to raw arrays | ||
|
||
```py | ||
import sleap_io as sio | ||
|
||
labels = sio.load_slp("tests/data/slp/centered_pair_predictions.slp") | ||
|
||
# Convert predictions to point coordinates in a single array. | ||
trx = labels.numpy() | ||
n_frames, n_tracks, n_nodes, xy = trx.shape | ||
assert xy == 2 | ||
|
||
# Convert to array with confidence scores appended. | ||
trx_with_scores = labels.numpy(return_confidence=True) | ||
n_frames, n_tracks, n_nodes, xy_score = trx.shape | ||
assert xy_score == 3 | ||
``` | ||
|
||
### Read video data | ||
|
||
```py | ||
import sleap_io as sio | ||
|
||
video = sio.load_video("test.mp4") | ||
n_frames, height, width, channels = video.shape | ||
|
||
frame = video[0] | ||
height, width, channels = frame.shape | ||
``` | ||
|
||
### Create labels from raw data | ||
|
||
```py | ||
import sleap_io as sio | ||
import numpy as np | ||
|
||
# Create skeleton. | ||
skeleton = sio.Skeleton( | ||
nodes=["head", "thorax", "abdomen"], | ||
edges=[("head", "thorax"), ("thorax", "abdomen")] | ||
) | ||
|
||
# Create video. | ||
video = sio.load_video("test.mp4") | ||
|
||
# Create instance. | ||
instance = sio.Instance.from_numpy( | ||
points=np.array([ | ||
[10.2, 20.4], | ||
[5.8, 15.1], | ||
[0.3, 10.6], | ||
]), | ||
skeleton=skeleton | ||
) | ||
|
||
# Create labeled frame. | ||
lf = sio.LabeledFrame(video=video, frame_idx=0, instances=[instance]) | ||
|
||
# Create labels. | ||
labels = sio.Labels(videos=[video], skeletons=[skeleton], labeled_frames=[lf]) | ||
|
||
# Save. | ||
labels.save("labels.slp") | ||
``` | ||
|
||
## Support | ||
For technical inquiries specific to this package, please [open an Issue](https://github.com/talmolab/sleap-io/issues) | ||
with a description of your problem or request. | ||
|
||
For general SLEAP usage, see the [main website](https://sleap.ai). | ||
|
||
Other questions? Reach out to `[email protected]`. | ||
|
||
## License | ||
This package is distributed under a BSD 3-Clause License and can be used without | ||
restrictions. See [`LICENSE`](https://github.com/talmolab/sleap-io/blob/main/LICENSE) for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several formatting issues detected: missing blank lines around headings and fenced code blocks, and missing language specification for code blocks.
+
+ ```bash
+ ```bash
+ ```bash
mkdocs
,mkdocs-material
,mkdocstrings
andmike
Summary by CodeRabbit
New Features
sleap_io
module.Documentation
CONTRIBUTING.md
with new setup instructions and link updates.mkdocs.yml
.Bug Fixes
Refactor
Style