sleap.info.write_tracking_h5

Generate an HDF5 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

Note: the datasets are stored column-major as expected by MATLAB.

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) → Tuple[numpy.ndarray, numpy.ndarray][source]

Builds numpy matrices with track occupancy and point location data.

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.

Returns

  • occupancy matrix with shape (tracks, frames)

  • point location matrix with shape (frames, nodes, 2, tracks)

Return type

tuple of two matrices

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, all_frames: bool = True)[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.

  • 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.

Returns

None

sleap.info.write_tracking_h5.remove_empty_tracks_from_matrices(track_names: List, occupancy_matrix: numpy.ndarray, locations_matrix: numpy.ndarray) → Tuple[List, 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

Returns

track_names, occupancy_matrix, locations_matrix from input, but without the rows/columns corresponding to unoccupied tracks.

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