xarray-behave 0.38.0a2__tar.gz → 0.38.0a4__tar.gz
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.
- xarray_behave-0.38.0a4/.github/workflows/test_install.yaml +45 -0
- xarray_behave-0.38.0a4/.gitignore +130 -0
- xarray_behave-0.38.0a4/AGENTS.md +368 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/PKG-INFO +2 -3
- xarray_behave-0.38.0a4/doc/demo.ipynb +1277 -0
- xarray_behave-0.38.0a4/doc/demo_behavioral_features.ipynb +1720 -0
- xarray_behave-0.38.0a4/doc/demo_behavioral_features_large_group.ipynb +215 -0
- xarray_behave-0.38.0a4/doc/ncb.mplstyle +44 -0
- xarray_behave-0.38.0a4/env/xb.yml +10 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/pyproject.toml +3 -0
- xarray_behave-0.38.0a4/scripts/fix_camera_timestamps.py +72 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/__init__.py +1 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/_dataset_service.py +112 -8
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/annot.py +1 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/api.py +7 -2
- xarray_behave-0.38.0a4/src/xarray_behave/gui/annotation_import.py +160 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/app.py +268 -101
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/event_widgets.py +27 -2
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/formbuilder.py +3 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/forms/from_dir.yaml +9 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/forms/from_file.yaml +6 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/forms/from_zarr.yaml +6 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/gui_config.py +4 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/modern_video.py +45 -22
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/view_dialog.py +10 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/views.py +24 -7
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/__init__.py +20 -1
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/annotations_manual.py +8 -7
- xarray_behave-0.38.0a4/src/xarray_behave/manifests/default.yaml +94 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/xarray_behave.py +54 -29
- xarray_behave-0.38.0a4/tests/test_annot.py +141 -0
- xarray_behave-0.38.0a4/tests/test_api.py +228 -0
- xarray_behave-0.38.0a4/tests/test_assemble.py +184 -0
- xarray_behave-0.38.0a4/tests/test_assemble_metrics.py +58 -0
- xarray_behave-0.38.0a4/tests/test_dataset_service.py +445 -0
- xarray_behave-0.38.0a4/tests/test_event_utils.py +67 -0
- xarray_behave-0.38.0a4/tests/test_fix_camera_timestamps.py +57 -0
- xarray_behave-0.38.0a4/tests/test_gui_annotation_import.py +277 -0
- xarray_behave-0.38.0a4/tests/test_gui_app.py +370 -0
- xarray_behave-0.38.0a4/tests/test_gui_config.py +157 -0
- xarray_behave-0.38.0a4/tests/test_gui_das.py +358 -0
- xarray_behave-0.38.0a4/tests/test_gui_event_widgets.py +2479 -0
- xarray_behave-0.38.0a4/tests/test_gui_media_dialog.py +111 -0
- xarray_behave-0.38.0a4/tests/test_gui_modern_video.py +62 -0
- xarray_behave-0.38.0a4/tests/test_gui_opengl.py +77 -0
- xarray_behave-0.38.0a4/tests/test_gui_project.py +193 -0
- xarray_behave-0.38.0a4/tests/test_gui_utils.py +56 -0
- xarray_behave-0.38.0a4/tests/test_gui_views.py +41 -0
- xarray_behave-0.38.0a4/tests/test_imports.py +10 -0
- xarray_behave-0.38.0a4/tests/test_io.py +123 -0
- xarray_behave-0.38.0a4/tests/test_sampstamps.py +34 -0
- xarray_behave-0.38.0a2/src/xarray_behave/manifests/default.yaml +0 -94
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/LICENSE +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/README.md +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/event_utils.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/__init__.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/checkbox_check.svg +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/forms/das_make.yaml +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/forms/envelope_computation.yaml +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/icon.png +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/media_dialog.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/project.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/style_profile.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/utils.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/gui/widgets.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/annotations.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/audio.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/balltracks.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/movieparams.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/poses.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/samplestamps/__init__.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/samplestamps/samplestamps.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/samplestamps/utils.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/timestamps.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/io/tracks.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/loaders.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/metrics.py +0 -0
- {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a4}/src/xarray_behave/v1.py +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Test install
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
logLevel:
|
|
10
|
+
description: 'Log level'
|
|
11
|
+
required: true
|
|
12
|
+
default: 'warning'
|
|
13
|
+
tags:
|
|
14
|
+
description: 'manual run'
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ${{ matrix.os }}
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: False
|
|
21
|
+
matrix:
|
|
22
|
+
os: [ubuntu-latest, windows-latest, macOS-latest]
|
|
23
|
+
defaults: # https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
|
|
24
|
+
run:
|
|
25
|
+
shell: bash -l {0}
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- name: Setup miniconda # https://github.com/marketplace/actions/setup-miniconda
|
|
29
|
+
uses: conda-incubator/setup-miniconda@v3
|
|
30
|
+
with:
|
|
31
|
+
auto-update-conda: true
|
|
32
|
+
auto-activate-base: true
|
|
33
|
+
channels: conda-forge
|
|
34
|
+
python-version: 3.13
|
|
35
|
+
- name: Install OpenGL dependencies
|
|
36
|
+
run: sudo apt-get update && sudo apt-get install -qq -y libx11-dev libgl1-mesa-dev libxkbcommon-x11-0
|
|
37
|
+
if: runner.os == 'Linux'
|
|
38
|
+
- name: Test
|
|
39
|
+
run: |
|
|
40
|
+
conda env create -n xb_test -y -f https://raw.githubusercontent.com/janclemenslab/xarray-behave/refs/heads/master/env/xb.yml
|
|
41
|
+
conda activate xb_test
|
|
42
|
+
python -m pip install ".[dev]"
|
|
43
|
+
python -c "import xarray_behave; print(xarray_behave.__version__)"
|
|
44
|
+
python -c "import xarray_behave.gui.app"
|
|
45
|
+
python -m pytest -q tests/test_imports.py tests/test_io.py tests/test_sampstamps.py tests/test_dataset_service.py tests/test_fix_camera_timestamps.py
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# Translations
|
|
51
|
+
*.mo
|
|
52
|
+
*.pot
|
|
53
|
+
|
|
54
|
+
# Django stuff:
|
|
55
|
+
*.log
|
|
56
|
+
local_settings.py
|
|
57
|
+
db.sqlite3
|
|
58
|
+
|
|
59
|
+
# Flask stuff:
|
|
60
|
+
instance/
|
|
61
|
+
.webassets-cache
|
|
62
|
+
|
|
63
|
+
# Scrapy stuff:
|
|
64
|
+
.scrapy
|
|
65
|
+
|
|
66
|
+
# Sphinx documentation
|
|
67
|
+
|
|
68
|
+
# PyBuilder
|
|
69
|
+
target/
|
|
70
|
+
|
|
71
|
+
# Jupyter Notebook
|
|
72
|
+
.ipynb_checkpoints
|
|
73
|
+
|
|
74
|
+
# pyenv
|
|
75
|
+
.python-version
|
|
76
|
+
|
|
77
|
+
# celery beat schedule file
|
|
78
|
+
celerybeat-schedule
|
|
79
|
+
|
|
80
|
+
# SageMath parsed files
|
|
81
|
+
*.sage.py
|
|
82
|
+
|
|
83
|
+
# Environments
|
|
84
|
+
.env
|
|
85
|
+
.venv
|
|
86
|
+
env/
|
|
87
|
+
venv/
|
|
88
|
+
ENV/
|
|
89
|
+
env.bak/
|
|
90
|
+
venv.bak/
|
|
91
|
+
|
|
92
|
+
# Spyder project settings
|
|
93
|
+
.spyderproject
|
|
94
|
+
.spyproject
|
|
95
|
+
|
|
96
|
+
# Rope project settings
|
|
97
|
+
.ropeproject
|
|
98
|
+
|
|
99
|
+
# mkdocs documentation
|
|
100
|
+
/site
|
|
101
|
+
|
|
102
|
+
# mypy
|
|
103
|
+
.mypy_cache/
|
|
104
|
+
|
|
105
|
+
# MATLAB
|
|
106
|
+
*.asv
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# LEAP-specific
|
|
110
|
+
dat/*
|
|
111
|
+
dat.*/
|
|
112
|
+
res*
|
|
113
|
+
fig*
|
|
114
|
+
*.err
|
|
115
|
+
*.out
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
/*/
|
|
119
|
+
!/src/
|
|
120
|
+
!/tests/
|
|
121
|
+
!/scripts/
|
|
122
|
+
!/env/
|
|
123
|
+
!/docs/
|
|
124
|
+
!/AGENTS.md
|
|
125
|
+
!/*.toml
|
|
126
|
+
!/.github
|
|
127
|
+
!/conda
|
|
128
|
+
/src/*.egg-info/
|
|
129
|
+
/src/*.egg-info
|
|
130
|
+
/tests/data
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Guide for coding agents working in this repository. This file is meant to save
|
|
4
|
+
future agents from re-parsing the whole codebase before small changes.
|
|
5
|
+
|
|
6
|
+
## Local Workflow
|
|
7
|
+
|
|
8
|
+
- Prefer Python.
|
|
9
|
+
- Use the `das-conformer` conda environment for Python commands:
|
|
10
|
+
`conda run -n das-conformer python -m pytest -q ...`
|
|
11
|
+
- If packages are needed, prefer `uv pip install ...` inside the conda env when
|
|
12
|
+
possible.
|
|
13
|
+
- Check `git status --short` before editing. This repo may have user-owned
|
|
14
|
+
uncommitted changes; do not revert or reformat unrelated files.
|
|
15
|
+
- Keep changes surgical. Match the existing style, even where it is older or
|
|
16
|
+
inconsistent.
|
|
17
|
+
|
|
18
|
+
## Project Snapshot
|
|
19
|
+
|
|
20
|
+
- Package: `xarray-behave`
|
|
21
|
+
- Source layout: `src/xarray_behave`
|
|
22
|
+
- Public API: `xarray_behave.assemble`, `assemble_metrics`, `load`, `save`
|
|
23
|
+
- GUI entry points: `xarray_behave.gui.app.main`, `main_das`, and CLI via
|
|
24
|
+
`defopt.run(main)`
|
|
25
|
+
- Internal GUI/data boundary: `src/xarray_behave/_dataset_service.py` contains
|
|
26
|
+
non-Qt dataset orchestration used by the GUI.
|
|
27
|
+
- GUI runtime uses full `PySide6>=6.10`. Qt Multimedia is imported directly from
|
|
28
|
+
`PySide6.QtMultimedia`; do not switch transport playback back to `qtpy`
|
|
29
|
+
multimedia wrappers or split `PySide6-Essentials/Addons` pins without testing
|
|
30
|
+
real audio output.
|
|
31
|
+
- Build backend: `flit_core` in `pyproject.toml`.
|
|
32
|
+
- Version lives in `src/xarray_behave/__init__.py`.
|
|
33
|
+
- `__init__.py` also sets `QT_API=pyside6`.
|
|
34
|
+
|
|
35
|
+
## What The Package Does
|
|
36
|
+
|
|
37
|
+
`xarray-behave` assembles behavioral recordings into self-describing
|
|
38
|
+
`xarray.Dataset` objects. Inputs can include audio/DAQ data, camera timestamps,
|
|
39
|
+
video tracking, pose tracking, ball tracking, DLP movie parameters, and automatic
|
|
40
|
+
or manual annotations. The main assembly path aligns everything onto either a
|
|
41
|
+
target sample grid or original frame times, then stores data arrays with time
|
|
42
|
+
coordinates and metadata.
|
|
43
|
+
|
|
44
|
+
The main model is:
|
|
45
|
+
|
|
46
|
+
- `time`: seconds on the analysis grid.
|
|
47
|
+
- `sampletime`: seconds on the raw audio/sample grid.
|
|
48
|
+
- `nearest_frame`: video frame nearest to each analysis time.
|
|
49
|
+
- `song_raw`: raw audio, dims `sampletime, channels`.
|
|
50
|
+
- `non_song_raw`: non-song channels, dims `sampletime, no_song_channels`.
|
|
51
|
+
- `song_events`: binary event traces, dims `time, event_types`, with legacy
|
|
52
|
+
`event_categories` normalized to `"event"`.
|
|
53
|
+
- `event_names` and `event_times`: table-like annotation representation.
|
|
54
|
+
- `body_positions`: tracked body positions, dims
|
|
55
|
+
`time, flies, bodyparts, coords`.
|
|
56
|
+
- `pose_positions`: egocentric pose positions, dims
|
|
57
|
+
`time, flies, poseparts, coords`.
|
|
58
|
+
- `pose_positions_allo`: allocentric pose positions in frame coordinates.
|
|
59
|
+
- `balltracks` and `movieparams`: optional aligned auxiliary traces.
|
|
60
|
+
|
|
61
|
+
Spatial coordinates use `coords=["y", "x"]`. Many loaders ingest x/y formats
|
|
62
|
+
and swap into y/x before returning arrays.
|
|
63
|
+
|
|
64
|
+
## Core Modules
|
|
65
|
+
|
|
66
|
+
- `src/xarray_behave/xarray_behave.py`
|
|
67
|
+
- `assemble(...)` is the central pipeline. It infers paths from
|
|
68
|
+
`root/dat_path/res_path/datename`, loads timestamps, audio, tracks, poses,
|
|
69
|
+
annotations, and optional auxiliary data, aligns arrays to the target grid,
|
|
70
|
+
builds an `xarray.Dataset`, converts positions to millimeters when
|
|
71
|
+
`pixel_size_mm` is available, and applies fly identity swaps when requested.
|
|
72
|
+
- `target_sampling_rate=0` or `None` disables resampling to a uniform target
|
|
73
|
+
grid and uses frame times.
|
|
74
|
+
- `align_time(...)` interpolates frame-indexed arrays onto target samples.
|
|
75
|
+
- `assemble_metrics(...)` computes absolute and relative behavioral features
|
|
76
|
+
from poses or body tracking.
|
|
77
|
+
- `convert_spatial_units(...)` mutates dataset arrays in place.
|
|
78
|
+
- `save(...)` writes a zipped zarr store using `zarr.ZipStore`; it removes
|
|
79
|
+
dict-valued `song_events.attrs["event_times"]` before saving because xarray
|
|
80
|
+
cannot serialize that attr.
|
|
81
|
+
- `load(...)` opens zipped zarr stores, optionally copying to a temp store and
|
|
82
|
+
normalizing byte-string coordinates.
|
|
83
|
+
|
|
84
|
+
- `src/xarray_behave/annot.py`
|
|
85
|
+
- `Events` is the annotation container used across assembly and GUI code.
|
|
86
|
+
- Internally each event name maps to an `N x 3` array:
|
|
87
|
+
`[start_seconds, stop_seconds, channel]`.
|
|
88
|
+
- Everything is an event. Instantaneous events have `start == stop`; events
|
|
89
|
+
with duration use different start/stop values.
|
|
90
|
+
- `categories` is legacy compatibility metadata. Inputs may still contain
|
|
91
|
+
`"segment"`, but code should normalize all values to `"event"` and must not
|
|
92
|
+
use categories to decide behavior.
|
|
93
|
+
- Empty names are preserved through DataFrame/list conversion with NaN
|
|
94
|
+
conventions: empty event names use `[nan, nan]`.
|
|
95
|
+
- Common methods: `from_df`, `from_lists`, `from_dataset`, `to_df`,
|
|
96
|
+
`to_dataset`, `add_name`, `add_time`, `delete_time`, `change_name`,
|
|
97
|
+
`filter_range`, `delete_range`, `find_next`, `find_prev`.
|
|
98
|
+
|
|
99
|
+
- `src/xarray_behave/event_utils.py`
|
|
100
|
+
- Converts between binary `song_events` traces and event-time dictionaries.
|
|
101
|
+
- Connected runs in binary traces become event start/stop rows. Single-sample
|
|
102
|
+
runs become point events with `start == stop`.
|
|
103
|
+
- Category inference helpers are legacy shims and return `"event"` for every
|
|
104
|
+
event type.
|
|
105
|
+
- `eventtimes_to_traces(...)` updates existing event names only.
|
|
106
|
+
- `update_traces(...)` rebuilds traces and can add new events.
|
|
107
|
+
|
|
108
|
+
- `src/xarray_behave/metrics.py`
|
|
109
|
+
- NumPy/SciPy helpers for smoothing, derivatives, distance, orientation,
|
|
110
|
+
velocity, acceleration, angular velocity/acceleration, vector projection,
|
|
111
|
+
and wing/internal angles.
|
|
112
|
+
|
|
113
|
+
- `src/xarray_behave/loaders.py`
|
|
114
|
+
- Timestamp loading helpers, channel merging, fly swap utilities, and legacy
|
|
115
|
+
key normalization.
|
|
116
|
+
- `swap_flies(...)` mutates selected dataset arrays from each swap time onward.
|
|
117
|
+
|
|
118
|
+
- `src/xarray_behave/_dataset_service.py`
|
|
119
|
+
- Thin internal service layer between `gui.app` and dataset logic.
|
|
120
|
+
- Wraps GUI-facing assembly from media/project recordings and files/directories,
|
|
121
|
+
zarr loading, song filtering, legacy event-category normalization, event-time
|
|
122
|
+
extraction, display unit conversion, and save preparation.
|
|
123
|
+
- Must stay free of Qt imports. Keep helpers small and avoid extra validation;
|
|
124
|
+
this module exists to separate concerns, not to change behavior.
|
|
125
|
+
|
|
126
|
+
- `src/xarray_behave/gui/project.py`
|
|
127
|
+
- Stores project recordings, their media paths, embedded annotations, and
|
|
128
|
+
project-specific GUI settings in `.xbp.yaml` files.
|
|
129
|
+
- Annotation types and presets belong to the project settings, not the global
|
|
130
|
+
GUI config. Project saves must not rewrite annotation sidecar files.
|
|
131
|
+
|
|
132
|
+
## IO Provider System
|
|
133
|
+
|
|
134
|
+
`src/xarray_behave/io/__init__.py` defines `BaseProvider`,
|
|
135
|
+
`register_provider`, and `get_loader(kind, basename, ...)`.
|
|
136
|
+
|
|
137
|
+
Provider modules register themselves at import time. Keep the final import line
|
|
138
|
+
in `io/__init__.py` updated when adding a new provider module, otherwise
|
|
139
|
+
`get_loader` will not know about it.
|
|
140
|
+
|
|
141
|
+
To add a loader, follow the existing pattern:
|
|
142
|
+
|
|
143
|
+
1. Subclass `io.BaseProvider`.
|
|
144
|
+
2. Set `KIND`, `NAME`, and `SUFFIXES`.
|
|
145
|
+
3. Decorate with `@io.register_provider`.
|
|
146
|
+
4. Implement `load(...)`; implement `make(...)` when the provider returns an
|
|
147
|
+
`xarray.DataArray`.
|
|
148
|
+
5. Return arrays in the expected dims and y/x coordinate order.
|
|
149
|
+
|
|
150
|
+
Registered provider families:
|
|
151
|
+
|
|
152
|
+
- Audio:
|
|
153
|
+
- `Ethodrome`: `_daq.h5`
|
|
154
|
+
- `Npz`: `.npz`
|
|
155
|
+
- `Npy`: `.npy`
|
|
156
|
+
- `AudioFile`: `.wav`, `.aif`, `.mp3`, `.flac`
|
|
157
|
+
- `H5file`: `.h5`, `.hdf5`, `.hdfs`
|
|
158
|
+
- `MMAPfile`: `.mmap`
|
|
159
|
+
- Timestamps:
|
|
160
|
+
- `CamStamps`: `_timestamps.h5`
|
|
161
|
+
- `DaqStamps`: `.h5`
|
|
162
|
+
- `CsvStamps`: `_timestamps.csv`
|
|
163
|
+
- Tracks:
|
|
164
|
+
- `Ethotracker`: `_tracks.h5`, `_tracks_fixed.h5`
|
|
165
|
+
- `CSV_tracks`: `_tracks.csv`
|
|
166
|
+
- Poses:
|
|
167
|
+
- `Leap`: `_poses.h5`, `_poses_leap.h5`
|
|
168
|
+
- `DeepPoseKit`: `_poses_dpk.zarr`
|
|
169
|
+
- `Sleap`: `_poses_sleap.h5`, `_sleap.h5`, `_sleap.h5.slp`
|
|
170
|
+
- Annotations:
|
|
171
|
+
- `DAS`: `_song.h5`, `_vibration.h5`, `_pulse.h5`, `_sine.h5`,
|
|
172
|
+
`_dss.h5`, `_das.h5`
|
|
173
|
+
- `FlySongSegmenter`: `_song.mat`
|
|
174
|
+
- manual CSV/zarr/mat loaders in `annotations_manual.py`
|
|
175
|
+
- definitions loader: `_definitions.csv`
|
|
176
|
+
- Legacy annotation files may contain event/segment labels. Loaders should
|
|
177
|
+
preserve start/stop timing but normalize all categories to `"event"`.
|
|
178
|
+
- Auxiliary:
|
|
179
|
+
- FicTrac ball tracks: `_fictrac.csv`
|
|
180
|
+
- DLP movie params: `_dlp.h5`, `_movieparams.npz`
|
|
181
|
+
|
|
182
|
+
## Sample/Time Conversion
|
|
183
|
+
|
|
184
|
+
`src/xarray_behave/io/samplestamps` contains conversion utilities:
|
|
185
|
+
|
|
186
|
+
- `SampStamp` builds interpolators between samples, frames, and timestamps.
|
|
187
|
+
- `SimpleStamp` is used for audio-only data with a regular sampling rate.
|
|
188
|
+
- `utils.monotonize(...)` truncates at the first monotonicity violation; tests
|
|
189
|
+
cover strict and non-strict increasing/decreasing behavior.
|
|
190
|
+
|
|
191
|
+
Assembly depends heavily on these converters, so changes here can affect
|
|
192
|
+
alignment throughout the package.
|
|
193
|
+
|
|
194
|
+
## GUI Architecture
|
|
195
|
+
|
|
196
|
+
- `src/xarray_behave/gui/app.py`
|
|
197
|
+
- `MainWindow` handles initial menus, dialogs, DAS integration, saving UI,
|
|
198
|
+
annotation editing, and project recording management.
|
|
199
|
+
- Dataset assembly/loading/filtering/event extraction/save prep is delegated to
|
|
200
|
+
`xarray_behave._dataset_service`; keep new non-Qt dataset orchestration
|
|
201
|
+
there instead of adding it directly to GUI methods.
|
|
202
|
+
- `PSV` is the main viewer/controller for synchronized waveform, spectrogram,
|
|
203
|
+
event timeline/table widgets, transport controls, and optional movie view.
|
|
204
|
+
- In the audio-focused layout the center stack is waveform, spectrogram,
|
|
205
|
+
event timeline, then event table, with initial splitter weights `1:4:1:2`.
|
|
206
|
+
Event presets live in the left preset panel. The current audio channel
|
|
207
|
+
selector overlays the waveform or spectrogram; there is intentionally no top
|
|
208
|
+
event/channel selector row.
|
|
209
|
+
- Switching a project recording keeps the window, project list, and preset
|
|
210
|
+
panel alive. Refresh only recording-dependent views and rebuild the preset
|
|
211
|
+
panel only when annotation types actually differ.
|
|
212
|
+
- Event table/timeline edits update the shared `annot.Events` instance.
|
|
213
|
+
Keep table-row selection, timeline selection, and audio view synchronization
|
|
214
|
+
in `PSV` rather than duplicating annotation mutation in widget classes.
|
|
215
|
+
- Transport playback is QMediaPlayer-backed when an audio source path is
|
|
216
|
+
available. Playback should run continuously; when the visible window flips,
|
|
217
|
+
update the displayed range without calling `setPosition()`/`play()` again.
|
|
218
|
+
- DAS helpers provide current-audio slices and prediction callbacks.
|
|
219
|
+
Focused tests live in `tests/test_gui_das.py`.
|
|
220
|
+
- `src/xarray_behave/gui/event_widgets.py`
|
|
221
|
+
- Qt/PyQtGraph widgets for the event table, waveform pane, event timeline, and
|
|
222
|
+
preset sidebar. `EventsTableWidget` owns table UI only; `WaveformPane` owns
|
|
223
|
+
the audio waveform display/playhead/annotation overlay; `EventTimelineWidget`
|
|
224
|
+
owns event-bar display and can optionally include an embedded waveform for
|
|
225
|
+
standalone use. They emit signals and do not own dataset save/load behavior.
|
|
226
|
+
- Table cells allow event-name dropdown edits and start/stop second edits.
|
|
227
|
+
Selection can be linked to the audio view; changing the audio range selects
|
|
228
|
+
overlapping rows.
|
|
229
|
+
- Timeline bars support selecting, creating, moving, and edge-resizing events.
|
|
230
|
+
- `EventTypePreset`, `EventPresetPanel`, and `EventTypePresetDialog` provide
|
|
231
|
+
the audio-only preset sidebar. Presets are GUI metadata over event names:
|
|
232
|
+
name, fixed-duration mode, default duration, editability after creation, and
|
|
233
|
+
color. `ChannelSelectorPanel` hosts the compact channel selector above the
|
|
234
|
+
preset panel. Presets must not replace the `Events` start/stop/channel
|
|
235
|
+
storage model.
|
|
236
|
+
- `WaveformPane` draws continuous traces for normal/default zooms and switches
|
|
237
|
+
to min/max overview pairs only for windows of at least 4 seconds. Keep this
|
|
238
|
+
threshold behavior in mind when changing waveform performance or appearance.
|
|
239
|
+
- `src/xarray_behave/gui/views.py`
|
|
240
|
+
- PyQtGraph view/items for traces, spectrograms, annotations, draggable body
|
|
241
|
+
and pose points, and movie display.
|
|
242
|
+
- `src/xarray_behave/gui/modern_video.py`
|
|
243
|
+
- PyAV-backed reader used by the GUI movie path. It exposes the small reader
|
|
244
|
+
protocol expected by `views.MovieView` (`read`, `__getitem__`, frame shape,
|
|
245
|
+
frame count, and rate metadata).
|
|
246
|
+
- `src/xarray_behave/gui/media_dialog.py`
|
|
247
|
+
- Collects named audio/video sources and optional timestamp, offset, rate, and
|
|
248
|
+
dataset overrides before `dataset_service.assemble_from_media(...)` loads them.
|
|
249
|
+
- `src/xarray_behave/gui/formbuilder.py`
|
|
250
|
+
- YAML-driven Qt form builder. Forms live under `src/xarray_behave/gui/forms`.
|
|
251
|
+
- `src/xarray_behave/gui/utils.py`
|
|
252
|
+
- Color palettes, fast plotting, image widget,
|
|
253
|
+
nearest-index helpers, worker/thread helpers, and checkable combo box.
|
|
254
|
+
- `src/xarray_behave/gui/style_profile.py`
|
|
255
|
+
- Shared dark Qt stylesheet and timeline colors adapted from `xb_gui`.
|
|
256
|
+
Prefer using these constants for new GUI widgets instead of introducing a
|
|
257
|
+
separate look.
|
|
258
|
+
GUI tests are written to avoid opening real windows where possible by using
|
|
259
|
+
`__new__`, monkeypatching imported modules, and faking datasets.
|
|
260
|
+
|
|
261
|
+
## Tests And Verification
|
|
262
|
+
|
|
263
|
+
Use the requested conda env:
|
|
264
|
+
|
|
265
|
+
```shell
|
|
266
|
+
conda run -n das-conformer python -m pytest -q
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Useful narrower checks:
|
|
270
|
+
|
|
271
|
+
```shell
|
|
272
|
+
conda run -n das-conformer python -m pytest -q tests/test_annot.py tests/test_sampstamps.py
|
|
273
|
+
conda run -n das-conformer python -m pytest -q tests/test_event_utils.py tests/test_gui_event_widgets.py
|
|
274
|
+
conda run -n das-conformer python -m pytest -q tests/test_dataset_service.py tests/test_gui_das.py tests/test_imports.py
|
|
275
|
+
conda run -n das-conformer python -m pytest -q tests/test_gui_utils.py tests/test_gui_das.py
|
|
276
|
+
conda run -n das-conformer python -m pytest -q tests/test_imports.py tests/test_io.py
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Assembly tests in `tests/test_assemble.py` and
|
|
280
|
+
`tests/test_assemble_metrics.py` use fixture data paths under `tests/data`.
|
|
281
|
+
They are closer to smoke tests than strict structure assertions.
|
|
282
|
+
|
|
283
|
+
The GitHub Actions workflow only runs import/IO/samplestamp smoke tests after
|
|
284
|
+
creating an env from `env/xb.yml`.
|
|
285
|
+
|
|
286
|
+
## Common Change Patterns
|
|
287
|
+
|
|
288
|
+
- Adding a new file format: implement a provider in `src/xarray_behave/io`,
|
|
289
|
+
register it, import the module from `io/__init__.py`, and add a focused test
|
|
290
|
+
for suffix matching and return shape.
|
|
291
|
+
- Changing annotations: update `annot.Events` and `event_utils` tests first.
|
|
292
|
+
Preserve the `N x 3` internal layout and NaN empty-name conventions unless the
|
|
293
|
+
task explicitly asks for a migration. Do not reintroduce event-vs-segment
|
|
294
|
+
behavior; duration belongs in start/stop seconds.
|
|
295
|
+
- Changing assembly behavior: add or update an assembly fixture test where
|
|
296
|
+
possible, but keep it narrow because full assembly can be slow.
|
|
297
|
+
- Changing GUI dataset creation/loading/saving behavior: update
|
|
298
|
+
`_dataset_service.py` first and add/adjust a focused test in
|
|
299
|
+
`tests/test_dataset_service.py`. Keep `gui.app` responsible for Qt dialogs and
|
|
300
|
+
viewer construction.
|
|
301
|
+
- Changing project persistence or recording switching: update `gui/project.py`,
|
|
302
|
+
the focused `tests/test_gui_project.py` / `tests/test_gui_event_widgets.py`,
|
|
303
|
+
and keep project-wide panels intact during a recording change.
|
|
304
|
+
- Changing event table/timeline behavior: update `src/xarray_behave/gui/event_widgets.py`
|
|
305
|
+
and `tests/test_gui_event_widgets.py`. Keep widgets signal-driven and keep
|
|
306
|
+
dataset mutation in `PSV`.
|
|
307
|
+
- Changing waveform, transport, side-panel, or audio-channel UI behavior usually
|
|
308
|
+
touches `gui.app`, `gui.event_widgets`, `gui.style_profile`, and
|
|
309
|
+
`tests/test_gui_event_widgets.py` together. Smoke launch the audio GUI after
|
|
310
|
+
such changes:
|
|
311
|
+
`conda run -n das-conformer python -m xarray_behave.gui.app scratch/dat/Dmel_male.wav --skip-dialog`.
|
|
312
|
+
- Changing GUI DAS behavior: update `tests/test_gui_das.py`; the tests
|
|
313
|
+
intentionally monkeypatch the external `das` module.
|
|
314
|
+
- Changing color maps or GUI helper behavior: update `tests/test_gui_utils.py`.
|
|
315
|
+
- Changing saved dataset structure: check `save`, `load`, GUI save logic, and
|
|
316
|
+
manual annotation loaders together.
|
|
317
|
+
|
|
318
|
+
## Pitfalls
|
|
319
|
+
|
|
320
|
+
- Many functions mutate arrays or datasets in place (`Events`, `swap_flies`,
|
|
321
|
+
`convert_spatial_units`, GUI annotation edits). Avoid assuming pure returns.
|
|
322
|
+
- `get_loader(...)` returns either one loader or a list depending on
|
|
323
|
+
`stop_after_match`.
|
|
324
|
+
- `eventtimes_to_traces(...)` does not add new event names; use
|
|
325
|
+
`update_traces(...)` when new names must appear.
|
|
326
|
+
- Category values are legacy. Treat any `"segment"` strings from old files or
|
|
327
|
+
tests as input compatibility only, and normalize them to `"event"` before GUI
|
|
328
|
+
use or saving.
|
|
329
|
+
- Event rows are identified in the GUI table/timeline by event name plus row
|
|
330
|
+
index. After deleting or moving rows, refresh widgets from `self.event_times`
|
|
331
|
+
before reusing old row ids.
|
|
332
|
+
- Fixed-duration presets are enforced in `PSV`, not in `Events`. For locked
|
|
333
|
+
fixed-duration event types, table edits and timeline edge drags should move
|
|
334
|
+
the whole event while preserving the preset duration.
|
|
335
|
+
- The active event type is stored in `PSV._current_event_name` and mirrored by
|
|
336
|
+
the preset side panel. Do not reintroduce a hidden or visible top combo box as
|
|
337
|
+
the source of truth.
|
|
338
|
+
- The current audio channel selector lives in `ChannelSelectorPanel.channel_combo`;
|
|
339
|
+
`PSV.cb2` is a compatibility alias used by existing channel-selection methods.
|
|
340
|
+
- Project recordings can have different audio data and annotations, but share
|
|
341
|
+
project presets and settings. Do not recreate the whole viewer just to switch
|
|
342
|
+
recordings.
|
|
343
|
+
- The linked table/audio behavior is optional. Respect
|
|
344
|
+
`EventsTableWidget.sync_enabled` before changing the audio range in response
|
|
345
|
+
to table selection.
|
|
346
|
+
- The waveform panel and event timeline both use seconds. `WaveformPane` is the
|
|
347
|
+
top audio panel; do not replace it with the legacy `views.TraceView` unless
|
|
348
|
+
restoring all playhead, annotation overlay, click, and threshold behavior.
|
|
349
|
+
- Some loader code catches broad exceptions and logs instead of failing. When
|
|
350
|
+
debugging assembly, inspect logs and the final dataset variables.
|
|
351
|
+
- `pixel_size_mm` can be `nan`; conversion should be skipped when there is no
|
|
352
|
+
valid scale.
|
|
353
|
+
- `song_raw` may be a NumPy array, dask array, h5-backed array, or memmap-like
|
|
354
|
+
object depending on loader and lazy settings.
|
|
355
|
+
- GUI code uses both sample indices and seconds. Check whether a variable is an
|
|
356
|
+
index (`time0`, `time1`) or seconds (`t0`, `t1`, `mouseT`) before changing it.
|
|
357
|
+
- The event table and timeline use seconds. Convert to sample indices only at
|
|
358
|
+
the `PSV` boundary when changing the audio view.
|
|
359
|
+
- `_dataset_service.py` intentionally preserves GUI-era behavior, including small
|
|
360
|
+
quirks in form-data mapping. Treat it as orchestration glue unless explicitly
|
|
361
|
+
asked to change behavior.
|
|
362
|
+
- Keep generated or temporary files out of the repo. Some tests/examples write
|
|
363
|
+
`test.txt`; do not treat it as source.
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
## Inspiration for extensions
|
|
367
|
+
- https://www.pamguard.org/olhelp/detectors/whistleMoanHelp/docs/whistleMoan_Overview.html
|
|
368
|
+
- https://www.ravensoundsoftware.com/article-categories/raven-workbench/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: xarray-behave
|
|
3
|
-
Version: 0.38.
|
|
3
|
+
Version: 0.38.0a4
|
|
4
4
|
Summary: xarray tools for behavioral data.
|
|
5
5
|
Author-email: Jan Clemens <clemensjan@googlemail.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -29,7 +29,6 @@ Requires-Dist: flit ; extra == "dev"
|
|
|
29
29
|
Project-URL: documentation, https://janclemenslab.org/das-alpha/
|
|
30
30
|
Project-URL: source, https://github.com/janclemenslab/xarray-behave
|
|
31
31
|
Provides-Extra: dev
|
|
32
|
-
Import-Name: xarray_behave
|
|
33
32
|
|
|
34
33
|
# xarray-behave
|
|
35
34
|
|