w2t-bkin 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- w2t_bkin/__init__.py +85 -0
- w2t_bkin/behavior/__init__.py +115 -0
- w2t_bkin/behavior/core.py +1027 -0
- w2t_bkin/bpod/__init__.py +38 -0
- w2t_bkin/bpod/core.py +519 -0
- w2t_bkin/config.py +625 -0
- w2t_bkin/dlc/__init__.py +59 -0
- w2t_bkin/dlc/core.py +448 -0
- w2t_bkin/dlc/models.py +124 -0
- w2t_bkin/exceptions.py +426 -0
- w2t_bkin/facemap/__init__.py +42 -0
- w2t_bkin/facemap/core.py +397 -0
- w2t_bkin/facemap/models.py +134 -0
- w2t_bkin/pipeline.py +665 -0
- w2t_bkin/pose/__init__.py +48 -0
- w2t_bkin/pose/core.py +227 -0
- w2t_bkin/pose/io.py +363 -0
- w2t_bkin/pose/skeleton.py +165 -0
- w2t_bkin/pose/ttl_mock.py +477 -0
- w2t_bkin/session.py +423 -0
- w2t_bkin/sync/__init__.py +72 -0
- w2t_bkin/sync/core.py +678 -0
- w2t_bkin/sync/stats.py +176 -0
- w2t_bkin/sync/timebase.py +311 -0
- w2t_bkin/sync/ttl.py +254 -0
- w2t_bkin/transcode/__init__.py +38 -0
- w2t_bkin/transcode/core.py +303 -0
- w2t_bkin/transcode/models.py +96 -0
- w2t_bkin/ttl/__init__.py +64 -0
- w2t_bkin/ttl/core.py +518 -0
- w2t_bkin/ttl/models.py +19 -0
- w2t_bkin/utils.py +1093 -0
- w2t_bkin-0.0.6.dist-info/METADATA +145 -0
- w2t_bkin-0.0.6.dist-info/RECORD +36 -0
- w2t_bkin-0.0.6.dist-info/WHEEL +4 -0
- w2t_bkin-0.0.6.dist-info/licenses/LICENSE +201 -0
w2t_bkin/__init__.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""W2T Body Kinematics Pipeline (w2t_bkin).
|
|
2
|
+
|
|
3
|
+
A modular, reproducible Python pipeline for processing multi-camera rodent
|
|
4
|
+
behavior recordings with synchronization, pose estimation, facial metrics,
|
|
5
|
+
and behavioral events into standardized NWB datasets.
|
|
6
|
+
|
|
7
|
+
Architecture: NWB-First
|
|
8
|
+
------------------------
|
|
9
|
+
This pipeline uses NWB (Neurodata Without Borders) as its foundational data layer.
|
|
10
|
+
All processing modules produce NWB-native data structures directly, eliminating
|
|
11
|
+
intermediate models and conversion layers.
|
|
12
|
+
|
|
13
|
+
Modules:
|
|
14
|
+
--------
|
|
15
|
+
- utils: Shared utilities (hashing, paths, JSON I/O, video analysis, frame counting)
|
|
16
|
+
- config: Configuration and session file loading
|
|
17
|
+
- session: NWB file creation from session metadata
|
|
18
|
+
- sync: Timebase providers and alignment
|
|
19
|
+
- behavior: Behavioral task recording (ndx-structured-behavior)
|
|
20
|
+
- bpod: Bpod .mat file parsing
|
|
21
|
+
- ttl: TTL hardware signals loading and EventsTable extraction (ndx-events)
|
|
22
|
+
- transcode: Video transcoding to mezzanine format
|
|
23
|
+
- pose: Pose estimation import and harmonization (DLC/SLEAP with ndx-pose)
|
|
24
|
+
- facemap: Facial metrics computation and alignment
|
|
25
|
+
- pipeline: High-level orchestration (NWB-first workflow)
|
|
26
|
+
|
|
27
|
+
Pipeline Phases:
|
|
28
|
+
----------------
|
|
29
|
+
Phase 0 (Foundation): Load config, create NWBFile from session.toml
|
|
30
|
+
Phase 1 (Discovery): Discover files, verify, add ImageSeries to NWBFile
|
|
31
|
+
Phase 2 (Behavior): Parse Bpod, add TaskRecording/TrialsTable to NWBFile
|
|
32
|
+
Phase 3 (Sync): Compute alignment stats, select timebase
|
|
33
|
+
Phase 4 (Optionals): DLC inference, pose, facemap
|
|
34
|
+
Phase 5 (Output): Write NWBFile to disk, validate
|
|
35
|
+
|
|
36
|
+
Quick Start:
|
|
37
|
+
-----------
|
|
38
|
+
>>> from w2t_bkin.pipeline import run_session
|
|
39
|
+
>>>
|
|
40
|
+
>>> # Run complete pipeline (NWB-first)
|
|
41
|
+
>>> result = run_session(
|
|
42
|
+
... config_path="config.toml",
|
|
43
|
+
... session_id="Session-000001"
|
|
44
|
+
... )
|
|
45
|
+
>>>
|
|
46
|
+
>>> # Access NWBFile
|
|
47
|
+
>>> nwbfile = result['nwbfile']
|
|
48
|
+
>>> print(f"Identifier: {nwbfile.identifier}")
|
|
49
|
+
>>> print(f"Acquisition: {list(nwbfile.acquisition.keys())}")
|
|
50
|
+
>>>
|
|
51
|
+
>>> # NWB file written to disk
|
|
52
|
+
>>> print(f"Output: {result['nwb_path']}")
|
|
53
|
+
|
|
54
|
+
Requirements:
|
|
55
|
+
-------------
|
|
56
|
+
- Python 3.10+
|
|
57
|
+
- pynwb~=3.1.0, hdmf~=4.1.0
|
|
58
|
+
- ndx-pose~=0.2.0, ndx-structured-behavior~=0.1.0
|
|
59
|
+
- scipy, numpy, pydantic
|
|
60
|
+
|
|
61
|
+
License:
|
|
62
|
+
--------
|
|
63
|
+
Apache-2.0
|
|
64
|
+
|
|
65
|
+
Documentation:
|
|
66
|
+
--------------
|
|
67
|
+
See docs/ for detailed module documentation and design principles.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
# Import main modules for convenient access
|
|
71
|
+
from . import behavior, bpod, config, facemap, pipeline, pose, session, sync, transcode, ttl, utils
|
|
72
|
+
|
|
73
|
+
__all__ = [
|
|
74
|
+
"behavior",
|
|
75
|
+
"bpod",
|
|
76
|
+
"config",
|
|
77
|
+
"facemap",
|
|
78
|
+
"pipeline",
|
|
79
|
+
"pose",
|
|
80
|
+
"session",
|
|
81
|
+
"sync",
|
|
82
|
+
"transcode",
|
|
83
|
+
"ttl",
|
|
84
|
+
"utils",
|
|
85
|
+
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Behavior module for Bpod behavioral data with ndx-structured-behavior.
|
|
2
|
+
|
|
3
|
+
This module provides transformation functions to convert Bpod .mat files
|
|
4
|
+
into ndx-structured-behavior NWB classes (StatesTable, EventsTable, ActionsTable,
|
|
5
|
+
TrialsTable, TaskRecording).
|
|
6
|
+
|
|
7
|
+
Following the NWB-first architecture established in Phase 1 (pose module),
|
|
8
|
+
this module produces community-standard ndx-structured-behavior objects directly,
|
|
9
|
+
eliminating intermediate custom models and conversion layers.
|
|
10
|
+
|
|
11
|
+
Public API:
|
|
12
|
+
Core transformation functions:
|
|
13
|
+
- extract_state_types: Parse unique state names → StateTypesTable
|
|
14
|
+
- extract_states: Convert trial states → StatesTable
|
|
15
|
+
- extract_event_types: Parse unique event names → EventTypesTable
|
|
16
|
+
- extract_events: Convert hardware events → EventsTable
|
|
17
|
+
- extract_action_types: Identify action states → ActionTypesTable
|
|
18
|
+
- extract_actions: Convert action states → ActionsTable
|
|
19
|
+
- build_trials_table: Combine states/events/actions → TrialsTable
|
|
20
|
+
- extract_trials_table: Complete extraction (convenience) → TrialsTable
|
|
21
|
+
- build_task_recording: Package tables → TaskRecording
|
|
22
|
+
- extract_task_recording: Complete extraction (convenience) → TaskRecording
|
|
23
|
+
- extract_task_arguments: Extract task parameters → TaskArgumentsTable
|
|
24
|
+
- build_task: Assemble Task container with type tables
|
|
25
|
+
- extract_task: Complete extraction (convenience) → Task
|
|
26
|
+
|
|
27
|
+
Re-exported ndx-structured-behavior types:
|
|
28
|
+
- StateTypesTable, StatesTable
|
|
29
|
+
- EventTypesTable, EventsTable
|
|
30
|
+
- ActionTypesTable, ActionsTable
|
|
31
|
+
- TrialsTable
|
|
32
|
+
- TaskRecording
|
|
33
|
+
- Task, TaskArgumentsTable
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
>>> from pathlib import Path
|
|
37
|
+
>>> from w2t_bkin.bpod.code import parse_bpod
|
|
38
|
+
>>> from w2t_bkin.behavior import (
|
|
39
|
+
... extract_state_types, extract_states,
|
|
40
|
+
... extract_event_types, extract_events,
|
|
41
|
+
... extract_action_types, extract_actions,
|
|
42
|
+
... build_trials_table, build_task_recording
|
|
43
|
+
... )
|
|
44
|
+
>>>
|
|
45
|
+
>>> # Parse Bpod data
|
|
46
|
+
>>> bpod_data = parse_bpod(Path("data"), "Bpod/*.mat", "name_asc")
|
|
47
|
+
>>>
|
|
48
|
+
>>> # Build type tables
|
|
49
|
+
>>> state_types = extract_state_types(bpod_data)
|
|
50
|
+
>>> event_types = extract_event_types(bpod_data)
|
|
51
|
+
>>> action_types = extract_action_types(bpod_data)
|
|
52
|
+
>>>
|
|
53
|
+
>>> # Build data tables (returns tuples with row indices)
|
|
54
|
+
>>> states, state_indices = extract_states(bpod_data, state_types)
|
|
55
|
+
>>> events, event_indices = extract_events(bpod_data, event_types)
|
|
56
|
+
>>> actions, action_indices = extract_actions(bpod_data, action_types)
|
|
57
|
+
>>>
|
|
58
|
+
>>> # Build trials and recording (pass indices for trial references)
|
|
59
|
+
>>> trials = build_trials_table(bpod_data, states, events, actions,
|
|
60
|
+
... state_indices, event_indices, action_indices)
|
|
61
|
+
>>> task_recording = build_task_recording(states, events, actions)
|
|
62
|
+
>>>
|
|
63
|
+
>>> # Build Task container (optional but recommended)
|
|
64
|
+
>>> task_arguments = extract_task_arguments(bpod_data) # optional
|
|
65
|
+
>>> task = build_task(state_types, event_types, action_types,
|
|
66
|
+
... task_arguments=task_arguments)
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
from ndx_structured_behavior import ActionsTable, ActionTypesTable, EventsTable, EventTypesTable, StatesTable, StateTypesTable, Task, TaskArgumentsTable, TaskRecording, TrialsTable
|
|
70
|
+
|
|
71
|
+
from .core import (
|
|
72
|
+
build_task,
|
|
73
|
+
build_task_recording,
|
|
74
|
+
build_trials_table,
|
|
75
|
+
extract_action_types,
|
|
76
|
+
extract_actions,
|
|
77
|
+
extract_behavioral_data,
|
|
78
|
+
extract_event_types,
|
|
79
|
+
extract_events,
|
|
80
|
+
extract_state_types,
|
|
81
|
+
extract_states,
|
|
82
|
+
extract_task,
|
|
83
|
+
extract_task_arguments,
|
|
84
|
+
extract_task_recording,
|
|
85
|
+
extract_trials_table,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
# Core transformation functions
|
|
90
|
+
"extract_state_types",
|
|
91
|
+
"extract_states",
|
|
92
|
+
"extract_event_types",
|
|
93
|
+
"extract_events",
|
|
94
|
+
"extract_action_types",
|
|
95
|
+
"extract_actions",
|
|
96
|
+
"build_trials_table",
|
|
97
|
+
"extract_trials_table",
|
|
98
|
+
"build_task_recording",
|
|
99
|
+
"extract_task_recording",
|
|
100
|
+
"extract_task_arguments",
|
|
101
|
+
"build_task",
|
|
102
|
+
"extract_task",
|
|
103
|
+
"extract_behavioral_data",
|
|
104
|
+
# Re-exported ndx-structured-behavior types
|
|
105
|
+
"StateTypesTable",
|
|
106
|
+
"StatesTable",
|
|
107
|
+
"EventTypesTable",
|
|
108
|
+
"EventsTable",
|
|
109
|
+
"ActionTypesTable",
|
|
110
|
+
"ActionsTable",
|
|
111
|
+
"TrialsTable",
|
|
112
|
+
"TaskRecording",
|
|
113
|
+
"Task",
|
|
114
|
+
"TaskArgumentsTable",
|
|
115
|
+
]
|