From 623597b17445f79627664a8c19ec31e2858a5f82 Mon Sep 17 00:00:00 2001 From: lochhh Date: Fri, 24 Nov 2023 17:15:29 +0000 Subject: [PATCH] Store only .slp as labels_path --- docs/source/getting_started.md | 4 +++- movement/io/save_poses.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/source/getting_started.md b/docs/source/getting_started.md index ff2d0375..50d6c447 100644 --- a/docs/source/getting_started.md +++ b/docs/source/getting_started.md @@ -228,7 +228,9 @@ save_poses.to_sleap_analysis_file(ds, "/path/to/file.h5") :::{note} When saving to SLEAP-style files, only `track_names`, `node_names`, `tracks`, `track_occupancy`, -`point_scores`, and `labels_path` are saved. Other attributes and data variables +and `point_scores` are saved. `labels_path` will only be saved if the source +file of the dataset is a SLEAP .slp file. Otherwise, it will be an empty string. +Other attributes and data variables (i.e., `instance_scores`, `tracking_scores`, `edge_names`, `edge_inds`, `video_path`, `video_ind`, and `provenance`) are not currently supported. To learn more about what each attribute and data variable represents, see the diff --git a/movement/io/save_poses.py b/movement/io/save_poses.py index 14e6d772..599556f5 100644 --- a/movement/io/save_poses.py +++ b/movement/io/save_poses.py @@ -246,9 +246,11 @@ def to_sleap_analysis_file( "track_names", "node_names", "tracks", "track_occupancy", "point_scores", "instance_scores", "tracking_scores", "labels_path", "edge_names", "edge_inds", "video_path", "video_ind", "provenance" [1]_. - However, only "track_names", "node_names", "tracks", "track_occupancy", - "point_scores" and "labels_path" will contain data extracted from the - input dataset. + However, only "track_names", "node_names", "tracks", "track_occupancy" + and "point_scores" will contain data extracted from the input dataset. + "labels_path" will contain the path to the input file only if the source + file of the dataset is a SLEAP .slp file. Otherwise, it will be an empty + string. The other attributes and data variables that are not present in the input dataset will contain default (empty) values. @@ -293,7 +295,9 @@ def to_sleap_analysis_file( point_scores = np.transpose(ds.confidence.data, (1, 2, 0)) instance_scores = np.full((n_individuals, n_frames), np.nan, dtype=float) tracking_scores = np.full((n_individuals, n_frames), np.nan, dtype=float) - + labels_path = ( + ds.source_file if Path(ds.source_file).suffix == ".slp" else "" + ) data_dict = dict( track_names=individual_names, node_names=keypoint_names, @@ -302,7 +306,7 @@ def to_sleap_analysis_file( point_scores=point_scores, instance_scores=instance_scores, tracking_scores=tracking_scores, - labels_path=ds.source_file, + labels_path=labels_path, edge_names=[], edge_inds=[], video_path="",