You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add I/O support for the ndx-pose NWB extension: take 2 (#360)
* Create nwb_export.py
* NWB requires one file per individual
* Add script
* Remove import error handling
* Add nwb optional dependencies
* Fix linting based on pre-commit hooks
* Add example docstring
* Rename to fit module naming pattern
* Add import from nwb
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Apply suggestions from code review
Co-authored-by: Niko Sirmpilatze <niko.sirbiladze@gmail.com>
* Update make pynwb and ndx-pose core dependencies
* Cleanup of docstrings and variable names from code review
* Rename function for clarity
* Update with example converting back to movement
* Add file validation and handling for single path
* Add preliminary tests
* Convert to numpy array
* Handle lack of confidence
* Display xarray
* Refactor tests
* Create nwb_export.py
* NWB requires one file per individual
* Remove import error handling
* Add nwb optional dependencies
* Fix linting based on pre-commit hooks
* Rename to fit module naming pattern
* Add import from nwb
* Update make pynwb and ndx-pose core dependencies
* Add file validation and handling for single path
* Convert to numpy array
* fix logging module import
* constrained pynwb>=0.2.1
* fixed existing unit tests
* add key_name argument to convert_nwb_to_movement
* tests should only create temp file
* use Generator instead of legacy np.random.random
* reorder dims and use from_numpy for creating movement ds
* define default nwb kwargs as constants
* renamed and reformatted `add_movement_dataset_to_nwb` to `ds_to_nwb`
* Expanded module-level docstring
* use individual instead of subject
* refactored functions for loading ds from nwb
* make mypy happy with numpy typing
* rename nwb example
* renamed private func for creating pose estimation and skeletons objects
* incorporate NWB loading into load_poses module
* incorporate NWB saving function into save_poses module
* simplified private nwb functions
* provide examples in docstrings instead of sphinx gallery example
* fix docstring syntax error
* use pose estimation series rate if possible
* use dot notation to access pose estimation attributes
* remove underscore from _nwb.py file name
* move imports at the top of docstring example
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix deprecated logger calls
* Fix line too long
* Add load_nwb test case
* Move file fixtures to tests/fixtures/files.py
* Add NWB file validator
* Extend from_nwb_file tests
* Add to_nwb_file tests
* Rename NWBFile fixture
* Remove repeated default nwb kwargs
* Simplify `_ds_to_pose_and_skeleton_objects` test
* Add pynwb to intersphinx mapping
* Draft to_nwb_file refactor
* Allow single key dict for single-ind datasets
* Create Subject in NWBFile
* Refactor resolve_kwargs
* Reduce resolve_kwargs complexity
* Include nwb module in API docs
* Resolve pose_estimation_series_kwargs for single keypoint
* Refactor _ds_to_pose_and_skeleton_objects pt1
* Allow deprioritising input ids
* Add test for _ds_to_pose_and_skeletons
* Update docstrings
* Refactor NWBFileSaveConfig tests
* Allow 0-d individuals
* Link Subject in Skeleton
* Update docstrings + rename resolve methods
* Resolve pose_estimation_kwargs
* Resolve skeleton_kwargs
* Remove unused functions
* Refactor _write_behavior_processing_module
* Convert frames to seconds when saving
* Use numpy.random.Generator
* Refactor to_nwb_file tests
* Remove unused constant
* Add to_nwb_file example in docstrings
* Add load NWB in IO guide
* Add save NWB in IO guide
* Use rng fixture in NWBFile fixtures
* Apply docstring suggestions from code review
Co-authored-by: Niko Sirmpilatze <niko.sirbiladze@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix reference to NWBFileSaveConfig in docstrings
* Mention NWBFile config option in I/O guide
* Clarify from_file fps arg
* Replace `identifier` with `experimenter` in to_nwb_file config example
* Only set `source_file` attribute when loading from NWB file path
* Log warning for missing session_start_time in NWBFileSaveConfig
* Rename `is_multi_individual` to `from_multi_individual`
* Remove "open" when describing NWBFile objects
* Use full NWBFile module refs in docstrings
* Return a single NWBFile when saving single-individual datasets
* Remove `identifier` from nwbfile_kwargs defaults
* Gather NWB fixtures
* Allow specifying key for processing module
* Allow customising processing module via kwargs
* Update nwb test config and comments for clarity
---------
Co-authored-by: Eric Denovellis <edeno@bu.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Denovellis <edeno@users.noreply.github.com>
Co-authored-by: lochhh <changhuan.lo@ucl.ac.uk>
Copy file name to clipboardExpand all lines: docs/source/user_guide/input_output.md
+85-49Lines changed: 85 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ To analyse pose tracks, `movement` supports loading data from various frameworks
12
12
-[LightingPose](lp:) (LP)
13
13
-[Anipose](anipose:) (Anipose)
14
14
15
+
Additionally, `movement` supports loading data stored in [Neurodata Without Borders (NWB)](https://nwb-overview.readthedocs.io/en/latest/) format (using the [``ndx-pose``](https://github.com/rly/ndx-pose) extension).
16
+
15
17
To analyse bounding box tracks, `movement` currently supports the [VGG Image Annotator](via:) (VIA) format for [tracks annotation](via:docs/face_track_annotation.html).
16
18
17
19
:::{note}
@@ -36,44 +38,39 @@ To read a pose tracks file into a [movement poses dataset](target-poses-and-bbox
36
38
37
39
::::{tab-set}
38
40
39
-
:::{tab-item} SLEAP
40
-
41
-
To load [SLEAP analysis files](sleap:tutorials/analysis) in .h5 format (recommended):
) # Optionally specify the name of the ProcessingModule and PoseEstimation objects.
110
+
# Defaults are "behavior" and "PoseEstimation", respectively.
111
+
112
+
# or equivalently
113
+
ds = load_poses.from_file(
114
+
"path/to/file.nwb",
115
+
source_software="NWB",
116
+
processing_module_key="behavior",
117
+
pose_estimation_key="PoseEstimation",
118
+
)
119
+
```
120
+
The above functions also accept an {class}`NWBFile<pynwb.file.NWBFile>` object as input:
121
+
```python
122
+
with pynwb.NWBHDF5IO("path/to/file.nwb", mode="r") as io:
123
+
nwb_file = io.read()
124
+
ds = load_poses.from_nwb_file(
125
+
nwb_file, pose_estimation_key="PoseEstimation"
126
+
)
101
127
```
102
128
:::
103
129
104
130
:::{tab-item} From NumPy
105
-
106
131
In the example below, we create random position data for two individuals, ``Alice`` and ``Bob``,
107
132
with three keypoints each: ``snout``, ``centre``, and ``tail_base``. These keypoints are tracked in 2D space for 100 frames, at 30 fps. The confidence scores are set to 1 for all points.
108
-
109
133
```python
110
134
import numpy as np
111
135
@@ -142,7 +166,6 @@ We currently support loading bounding box tracks in the VGG Image Annotator (VIA
Note that the x,y coordinates in the input VIA tracks .csv file represent the the top-left corner of each bounding box. Instead the corresponding ``movement`` dataset `ds` will hold in its `position` array the centroid of each bounding box.
159
-
160
-
161
181
:::
162
182
163
183
:::{tab-item} From NumPy
164
-
165
184
In the example below, we create random position data for two bounding boxes, ``id_0`` and ``id_1``,
166
185
both with the same width (40 pixels) and height (30 pixels). These are tracked in 2D space for 100 frames, which will be numbered in the resulting dataset from 0 to 99. The confidence score for all bounding boxes is set to 0.5.
The resulting data structure `ds` will include the centroid trajectories for each tracked bounding box, the boxes' widths and heights, and their associated confidence values if provided.
184
202
185
-
186
-
187
203
For more information on the bounding boxes data structure, see the [movement dataset](target-poses-and-bboxes-dataset) page.
188
204
189
205
190
206
(target-saving-pose-tracks)=
191
207
## Saving pose tracks
192
208
[movement poses datasets](target-poses-and-bboxes-dataset) can be saved in a variety of
193
-
formats, including DeepLabCut-style files (.h5 or .csv) and
To convert a `movement` poses dataset to {class}`NWBFile<pynwb.file.NWBFile>` objects:
268
+
```python
269
+
nwb_files = save_poses.to_nwb_file(ds)
270
+
```
271
+
The {func}`movement.io.save_poses.to_nwb_file` function also accepts
272
+
a {class}`movement.io.nwb.NWBFileSaveConfig` object as its ``config`` argument
273
+
for customising metadata such as session or subject information in the resulting `NWBFile`s
274
+
(see {func}`the API reference<movement.io.save_poses.to_nwb_file>` for examples).
252
275
276
+
These `NWBFile`s can then be saved to disk as .nwb files using {class}`pynwb.NWBHDF5IO`:
277
+
```python
278
+
from pynwb importNWBHDF5IO
279
+
280
+
forfilein nwb_files:
281
+
with NWBHDF5IO(f"{file.identifier}.nwb", "w") as io:
282
+
io.write(file)
283
+
```
284
+
:::{note}
285
+
To allow adding additional data to NWB files before saving, {func}`to_nwb_file<movement.io.save_poses.to_nwb_file>` does not write to disk directly.
286
+
Instead, it returns a list of {class}`NWBFile<pynwb.file.NWBFile>` objects---one per individual in the dataset---since NWB files are designed to represent data from a single individual.
0 commit comments