sleap.info.write_tracking_h5#
Generate an HDF5 or CSV file with track occupancy and point location data.
Ignores tracks that are entirely empty. By default will also ignore
empty frames from the beginning and end of video, although
--all-frames
argument will make it include empty frames from beginning
of video.
The HDF5 file has these datasets:
“track_occupancy” (shape: tracks * frames)
“tracks” (shape: frames * nodes * 2 * tracks)
“track_names” (shape: tracks)
“node_names” (shape: nodes)
“edge_names” (shape: nodes - 1)
“edge_inds” (shape: nodes - 1)
“point_scores” (shape: frames * nodes * tracks)
“instance_scores” (shape: frames * tracks)
“tracking_scores” (shape: frames * tracks)
“labels_path”: Path to the source .slp file (if available from GUI context)
“video_path”: Path to the source
Video
.“video_ind”: Scalar integer index of the video within the
Labels
.“provenance”: Dictionary that denotes the origin of the
Labels
.
Note: the datasets are stored column-major as expected by MATLAB.
- sleap.info.write_tracking_h5.get_edges_as_np_strings(labels: sleap.io.dataset.Labels) List[Tuple[numpy.bytes_, numpy.bytes_]] [source]#
Get list of edge names as
np.string_
.
- sleap.info.write_tracking_h5.get_nodes_as_np_strings(labels: sleap.io.dataset.Labels) List[numpy.bytes_] [source]#
Get list of node names as
np.string_
.
- sleap.info.write_tracking_h5.get_occupancy_and_points_matrices(labels: sleap.io.dataset.Labels, all_frames: bool, video: Optional[sleap.io.video.Video] = None) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]#
Builds numpy matrices with track occupancy and point location data.
Note: This function assumes either all instances have tracks or no instances have tracks.
- Parameters
labels – The
Labels
from which to get data.all_frames – If True, then includes zeros so that frame index will line up with columns in the output. Otherwise, there will only be columns for the frames between the first and last frames with labeling data.
video – The
Video
from which to get data. If novideo
is specified, then the first video insource_object
videos list will be used. If there are no labeled frames in thevideo
, then None will be returned.
- Returns
occupancy matrix with shape (tracks, frames)
point location array with shape (frames, nodes, 2, tracks)
point scores array with shape (frames, nodes, tracks)
instance scores array with shape (frames, tracks)
tracking scores array with shape (frames, tracks)
- Return type
tuple of arrays
- sleap.info.write_tracking_h5.get_tracks_as_np_strings(labels: sleap.io.dataset.Labels) List[numpy.bytes_] [source]#
Get list of track names as
np.string_
.
- sleap.info.write_tracking_h5.main(labels: sleap.io.dataset.Labels, output_path: str, labels_path: Optional[str] = None, all_frames: bool = True, video: Optional[sleap.io.video.Video] = None, csv: bool = False)[source]#
Writes HDF5 file with matrices of track occupancy and coordinates.
- Parameters
labels – The
Labels
from which to get data.output_path – Path of HDF5 file to create.
labels_path – Path of
labels
.slp file.all_frames – If True, then includes zeros so that frame index will line up with columns in the output. Otherwise, there will only be columns for the frames between the first and last frames with labeling data.
video – The
Video
from which to get data. If novideo
is specified, then the first video insource_object
videos list will be used. If there are no labeled frames in thevideo
, then no output file will be written.csv – Bool to save the analysis as a csv file if set to True
- Returns
None
- sleap.info.write_tracking_h5.remove_empty_tracks_from_matrices(track_names: List, occupancy_matrix: numpy.ndarray, locations_matrix: numpy.ndarray, point_scores: numpy.ndarray, instance_scores: numpy.ndarray, tracking_scores: numpy.ndarray) Tuple[List, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]#
Removes matrix rows/columns for unoccupied tracks.
- Parameters
track_names – List of track names
occupancy_matrix – 2d numpy matrix, rows correspond to tracks
locations_matrix – 4d numpy matrix, last index is track
point_scores – 3d numpy matrix, last index is track
instance_scores – 2d numpy matrix, last index is track
tracking_scores – 2d numpy matrix, last index is track
- Returns
track_names, occupancy_matrix, locations_matrix, point_scores, instance_scores tracking_scores but without the rows/columns corresponding to unoccupied tracks.
- sleap.info.write_tracking_h5.write_csv_file(output_path, data_dict)[source]#
Write CSV file with data from given dictionary.
- Parameters
output_path – Path of HDF5 file.
data_dict – Dictionary with data to save. Keys are dataset names, values are the data.
- Returns
None
- sleap.info.write_tracking_h5.write_occupancy_file(output_path: str, data_dict: Dict[str, Any], transpose: bool = True)[source]#
Write HDF5 file with data from given dictionary.
- Parameters
output_path – Path of HDF5 file.
data_dict – Dictionary with data to save. Keys are dataset names, values are the data.
transpose – If True, then any ndarray in data dictionary will be transposed before saving. This is useful for writing files that will be imported into MATLAB, which expects data in column-major format.
- Returns
None