Skip to content
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

Python 3.9 GitHub tests #111

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.9"

- name: Install dependencies
run: |
Expand All @@ -54,15 +54,12 @@ jobs:

# Tests with pytest
tests:
timeout-minutes: 15
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-14"]
python: ["3.8", "3.12"]
exclude:
- os: "macos-14"
python: "3.8"
python: ["3.9"]

name: Tests (${{ matrix.os }}, Python ${{ matrix.python }})
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ labels = sio.load_file("predictions.slp")
sio.save_file(labels, "predictions.nwb")
# Or:
# labels.save("predictions.nwb")

# Save to an NWB file and convert SLEAP training data to NWB training data:
frame_inds = [i for i in range(20)]
sio.save_file(labels, "predictions.nwb", as_training=True, frame_inds=frame_inds)
# This will save the first 20 frames of the video as individual images
```

### Convert labels to raw arrays
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies = [
"attrs",
"h5py>=3.8.0",
"pynwb",
"ndx-pose",
"ndx-pose @ git+https://github.com/rly/ndx-pose@a847ad4be75e60ef9e413b8cbfc99c616fc9fd05",
"pandas",
"simplejson",
"imageio",
Expand Down
42 changes: 36 additions & 6 deletions sleap_io/io/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from typing import Optional, Union
from pathlib import Path

from pynwb import NWBHDF5IO


def load_slp(filename: str) -> Labels:
"""Load a SLEAP dataset.
Expand Down Expand Up @@ -59,21 +61,45 @@
return nwb.read_nwb(filename)


def save_nwb(labels: Labels, filename: str, append: bool = True):
def save_nwb(
labels: Labels,
filename: str,
as_training: bool = False,
append: bool = True,
frame_inds: Optional[list[int]] = None,
frame_path: Optional[str] = None,
):
"""Save a SLEAP dataset to NWB format.

Args:
labels: A SLEAP `Labels` object (see `load_slp`).
filename: Path to NWB file to save to. Must end in `.nwb`.
as_training: If `True`, save the dataset as a training dataset.
append: If `True` (the default), append to existing NWB file. File will be
created if it does not exist.
frame_inds: Optional list of frame indices to save. If None, all frames
will be saved.
frame_path: The path to save the frames. If None, the path is the video
filename without the extension.

See also: nwb.write_nwb, nwb.append_nwb
See also: nwb.write_nwb, nwb.append_nwb, nwb.append_nwb_training
"""
if append and Path(filename).exists():
nwb.append_nwb(labels, filename)
nwb.append_nwb(

Check warning on line 88 in sleap_io/io/main.py

View check run for this annotation

Codecov / codecov/patch

sleap_io/io/main.py#L88

Added line #L88 was not covered by tests
labels,
filename,
as_training=as_training,
frame_inds=frame_inds,
frame_path=frame_path,
)
else:
nwb.write_nwb(labels, filename)
nwb.write_nwb(
labels,
filename,
as_training=as_training,
frame_inds=frame_inds,
frame_path=frame_path,
)


def load_labelstudio(
Expand Down Expand Up @@ -190,6 +216,8 @@
return load_jabs(filename, **kwargs)
elif format == "video":
return load_video(filename, **kwargs)
else:
raise ValueError(f"Unknown format '{format}' for filename: '{filename}'.")

Check warning on line 220 in sleap_io/io/main.py

View check run for this annotation

Codecov / codecov/patch

sleap_io/io/main.py#L220

Added line #L220 was not covered by tests


def save_file(
Expand Down Expand Up @@ -219,8 +247,10 @@

if format == "slp":
save_slp(labels, filename, **kwargs)
elif format == "nwb":
save_nwb(labels, filename, **kwargs)
elif format in ("nwb", "nwb_predictions"):
save_nwb(labels, filename, False)
elif format == "nwb_training":
save_nwb(labels, filename, True, frame_inds=kwargs.pop("frame_inds", None))

Check warning on line 253 in sleap_io/io/main.py

View check run for this annotation

Codecov / codecov/patch

sleap_io/io/main.py#L253

Added line #L253 was not covered by tests
elif format == "labelstudio":
save_labelstudio(labels, filename, **kwargs)
elif format == "jabs":
Expand Down
Loading
Loading