.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/convert_file_formats.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_convert_file_formats.py: Convert pose tracks between file formats =========================================== Load pose tracks from one file format, modify them, and save them to another file format. .. GENERATED FROM PYTHON SOURCE LINES 9-23 Motivation ---------- When working with pose estimation data, it's often useful to convert between file formats. For example, you may need to use some downstream analysis tool that requires a specific file format, or expects the keypoints to be named in a certain way. In the following example, we will load a dataset from a SLEAP file, modify the keypoints (rename, delete, reorder), and save the modified dataset as a DeepLabCut file. We'll first walk through each step separately, and then combine them into a single function that can be applied to multiple files at once. .. GENERATED FROM PYTHON SOURCE LINES 25-27 Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 27-33 .. code-block:: Python import tempfile from pathlib import Path from movement import sample_data from movement.io import load_poses, save_poses .. GENERATED FROM PYTHON SOURCE LINES 34-39 Load the dataset ---------------- We'll start with the path to a file output by one of our :ref:`supported pose estimation frameworks`. For example, the path could be something like: .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python # uncomment and edit the following line to point to your own local file # file_path = "/path/to/my/data.h5" .. GENERATED FROM PYTHON SOURCE LINES 44-46 For the sake of this example, we will use the path to one of the sample datasets provided with ``movement``. .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: Python file_path = sample_data.fetch_dataset_paths( "SLEAP_single-mouse_EPM.analysis.h5" )["poses"] print(file_path) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/.movement/data/poses/SLEAP_single-mouse_EPM.analysis.h5 .. GENERATED FROM PYTHON SOURCE LINES 53-56 Now let's load this file into a :ref:`movement poses dataset`, which we can then modify to our liking. .. GENERATED FROM PYTHON SOURCE LINES 56-63 .. code-block:: Python ds = load_poses.from_sleap_file(file_path, fps=30) print(ds, "\n") print("Individuals:", ds.coords["individuals"].values) print("Keypoints:", ds.coords["keypoints"].values) .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 1MB Dimensions: (time: 18485, space: 2, keypoints: 6, individuals: 1) Coordinates: * time (time) float64 148kB 0.0 0.03333 0.06667 ... 616.1 616.1 616.1 * space (space) ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: convert_file_formats.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: convert_file_formats.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_