save_dataset#
- movement.io.save.save_dataset(ds, file, target_software='movement', **kwargs)[source]#
Save a
movementdataset to a file in any supported format.- Parameters:
ds (
Dataset) – Themovementdataset to save.file (
str|Path) – Path to the file to save the dataset to. The required file extension depends on the target format.target_software (
Literal['movement','DeepLabCut','SLEAP','LightningPose','NWB','VIA-tracks']) – The format to save the dataset in. Defaults to"movement", which saves the dataset inmovement’s native netCDF format (.nc). Otherwise, one of the supported third-party formats.**kwargs – Additional keyword arguments passed to the format-specific writer (e.g.
split_individualsfor DeepLabCut,configfor NWB, or anyxarray.Dataset.to_netcdf()argument for movement-netCDF).
- Return type:
- Raises:
TypeError – If
dsis not anxarray.Dataset.ValueError – If
target_softwareis not a supported format, or if it is incompatible with the dataset’sds_type(e.g. saving a bounding boxes dataset to a poses-only format).
Notes
For NWB, each individual is written to a separate file (as required by the NWB format). For a single-individual dataset, the dataset is written to
file. For a multi-individual dataset, each NWBFile’sidentifier(by default the individual’s name, but configurable viaNWBFileSaveConfig) is appended to the file path, just before the extension, e.g."/path/to/file_id_0.nwb".Examples
Save a dataset to
movement’s native netCDF format:>>> from movement.io import save_dataset >>> save_dataset(ds, "/path/to/file.nc")
Save a poses dataset to a DeepLabCut .h5 file:
>>> save_dataset(ds, "/path/to/file.h5", target_software="DeepLabCut")
Save a bounding boxes dataset to a VIA-tracks .csv file:
>>> save_dataset(ds, "/path/to/file.csv", target_software="VIA-tracks")
Save a poses dataset to NWB file(s), with custom metadata:
>>> from movement.io.nwb import NWBFileSaveConfig >>> config = NWBFileSaveConfig( ... nwbfile_kwargs={"session_description": "foraging session"} ... ) >>> save_dataset( ... ds, "/path/to/file.nwb", target_software="NWB", config=config ... )