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

Fix IndexError for hdf5 file import for single instance analysis files #1695

Merged
merged 4 commits into from
Mar 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion sleap/io/format/sleap_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def read(
# shape: frames * nodes * 2 * tracks
frame_count, node_count, _, track_count = tracks_matrix.shape

if "track_names" in f:
if "track_names" in f and len(f["track_names"]):
track_names_list = f["track_names"][:].T
tracks = [Track(0, track_name.decode()) for track_name in track_names_list]
else:
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/fixtures/videos.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import pytest

from sleap.io.video import Video
from sleap.io.format.filehandle import FileHandle

TEST_H5_FILE = "tests/data/hdf5_format_v1/training.scale=0.50,sigma=10.h5"
TEST_H5_DSET = "/box"
TEST_H5_CONFMAPS = "/confmaps"
TEST_H5_AFFINITY = "/pafs"
TEST_H5_INPUT_FORMAT = "channels_first"
TEST_SMALL_ROBOT3_FRAME_H5 = (
"tests/data/hdf5_format_v1/small_robot.000_small_robot_3_frame.analysis.h5"
)


@pytest.fixture
def small_robot_3_frame_hdf5():
return FileHandle(filename=TEST_SMALL_ROBOT3_FRAME_H5)


@pytest.fixture
Expand Down
13 changes: 13 additions & 0 deletions tests/io/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
from sleap.gui.app import MainWindow
from sleap.gui.state import GuiState
from sleap.info.write_tracking_h5 import get_nodes_as_np_strings
from sleap.io.format.sleap_analysis import SleapAnalysisAdaptor


def test_sleap_analysis_read(small_robot_3_frame_vid, small_robot_3_frame_hdf5):

# Single instance hdf5 analysis file test
read_labels = SleapAnalysisAdaptor.read(
file=small_robot_3_frame_hdf5, video=small_robot_3_frame_vid
)

assert len(read_labels.videos) == 1
assert len(read_labels.tracks) == 1
assert len(read_labels.skeletons) == 1


def test_text_adaptor(tmpdir):
Expand Down
Loading