xarray-behave 0.38.0a4__tar.gz → 1.0__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 → xarray_behave-1.0}/.github/workflows/test_install.yaml +12 -14
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/AGENTS.md +3 -15
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/PKG-INFO +14 -10
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/README.md +7 -3
- xarray_behave-1.0/env/xb.yml +7 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/pyproject.toml +15 -17
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/__init__.py +1 -1
- xarray_behave-1.0/src/xarray_behave/_audio_filter.py +58 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/_dataset_service.py +2 -35
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/api.py +1 -1
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/event_utils.py +0 -9
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/app.py +386 -232
- xarray_behave-1.0/src/xarray_behave/gui/audio_playback.py +94 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/event_widgets.py +116 -42
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/formbuilder.py +5 -2
- xarray_behave-0.38.0a4/src/xarray_behave/gui/forms/das_make.yaml → xarray_behave-1.0/src/xarray_behave/gui/forms/training_package.yaml +7 -6
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/gui_config.py +1 -0
- xarray_behave-1.0/src/xarray_behave/gui/style_profile.py +589 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/import_annotations.svg +3 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/open_audio_annotations.svg +3 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/save_annotations.svg +3 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_event_table.svg +4 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_movie.svg +4 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_sidebar.svg +4 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_spec.svg +122 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_timeline.svg +3 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/show_trace.svg +3 -0
- xarray_behave-1.0/src/xarray_behave/gui/toolbar_icons/threshold_mode.svg +3 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/utils.py +3 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/view_dialog.py +58 -17
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/views.py +18 -44
- xarray_behave-1.0/src/xarray_behave/io/annotations.py +54 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/annotations_manual.py +9 -14
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/audio.py +22 -55
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/poses.py +2 -2
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/tracks.py +15 -38
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/manifests/default.yaml +0 -6
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/xarray_behave.py +44 -55
- xarray_behave-1.0/tests/fixtures/zarr2/README.md +1 -0
- xarray_behave-1.0/tests/fixtures/zarr2/recording_poses_dpk.zarr +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_api.py +16 -6
- xarray_behave-1.0/tests/test_assemble.py +70 -0
- xarray_behave-1.0/tests/test_assemble_metrics.py +20 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_dataset_service.py +72 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_annotation_import.py +11 -5
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_app.py +16 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_das.py +12 -12
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_event_widgets.py +331 -18
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_utils.py +6 -4
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_io.py +20 -2
- xarray_behave-1.0/tests/test_zarr_compatibility.py +60 -0
- xarray_behave-0.38.0a4/env/xb.yml +0 -10
- xarray_behave-0.38.0a4/src/xarray_behave/gui/style_profile.py +0 -277
- xarray_behave-0.38.0a4/src/xarray_behave/io/annotations.py +0 -163
- xarray_behave-0.38.0a4/tests/test_assemble.py +0 -184
- xarray_behave-0.38.0a4/tests/test_assemble_metrics.py +0 -58
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/.gitignore +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/LICENSE +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/doc/demo.ipynb +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/doc/demo_behavioral_features.ipynb +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/doc/demo_behavioral_features_large_group.ipynb +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/doc/ncb.mplstyle +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/scripts/fix_camera_timestamps.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/annot.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/__init__.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/annotation_import.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/checkbox_check.svg +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/forms/envelope_computation.yaml +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/forms/from_dir.yaml +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/forms/from_file.yaml +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/forms/from_zarr.yaml +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/icon.png +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/media_dialog.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/modern_video.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/project.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/gui/widgets.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/__init__.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/balltracks.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/movieparams.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/samplestamps/__init__.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/samplestamps/samplestamps.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/samplestamps/utils.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/io/timestamps.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/loaders.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/metrics.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/src/xarray_behave/v1.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_annot.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_event_utils.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_fix_camera_timestamps.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_config.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_media_dialog.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_modern_video.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_opengl.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_project.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_gui_views.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_imports.py +0 -0
- {xarray_behave-0.38.0a4 → xarray_behave-1.0}/tests/test_sampstamps.py +0 -0
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
name: Test install
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [alpha]
|
|
4
6
|
release:
|
|
5
7
|
types:
|
|
6
8
|
- published
|
|
7
9
|
workflow_dispatch:
|
|
8
|
-
inputs:
|
|
9
|
-
logLevel:
|
|
10
|
-
description: 'Log level'
|
|
11
|
-
required: true
|
|
12
|
-
default: 'warning'
|
|
13
|
-
tags:
|
|
14
|
-
description: 'manual run'
|
|
15
10
|
|
|
16
11
|
jobs:
|
|
17
12
|
test:
|
|
@@ -20,6 +15,9 @@ jobs:
|
|
|
20
15
|
fail-fast: False
|
|
21
16
|
matrix:
|
|
22
17
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
|
18
|
+
env:
|
|
19
|
+
QT_QPA_PLATFORM: offscreen
|
|
20
|
+
PYTEST_QT_API: pyside6
|
|
23
21
|
defaults: # https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
|
|
24
22
|
run:
|
|
25
23
|
shell: bash -l {0}
|
|
@@ -28,18 +26,18 @@ jobs:
|
|
|
28
26
|
- name: Setup miniconda # https://github.com/marketplace/actions/setup-miniconda
|
|
29
27
|
uses: conda-incubator/setup-miniconda@v3
|
|
30
28
|
with:
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
miniforge-version: latest
|
|
30
|
+
activate-environment: xb-ci
|
|
31
|
+
auto-activate-base: false
|
|
33
32
|
channels: conda-forge
|
|
34
|
-
python-version: 3.
|
|
33
|
+
python-version: "3.14"
|
|
35
34
|
- name: Install OpenGL dependencies
|
|
36
35
|
run: sudo apt-get update && sudo apt-get install -qq -y libx11-dev libgl1-mesa-dev libxkbcommon-x11-0
|
|
37
36
|
if: runner.os == 'Linux'
|
|
38
37
|
- name: Test
|
|
39
38
|
run: |
|
|
40
|
-
conda
|
|
41
|
-
|
|
42
|
-
python -m pip install ".[dev]"
|
|
39
|
+
conda install -y uv
|
|
40
|
+
uv pip install ".[dev]"
|
|
43
41
|
python -c "import xarray_behave; print(xarray_behave.__version__)"
|
|
44
42
|
python -c "import xarray_behave.gui.app"
|
|
45
|
-
python -m pytest -q
|
|
43
|
+
python -m pytest -q
|
|
@@ -75,11 +75,8 @@ and swap into y/x before returning arrays.
|
|
|
75
75
|
- `assemble_metrics(...)` computes absolute and relative behavioral features
|
|
76
76
|
from poses or body tracking.
|
|
77
77
|
- `convert_spatial_units(...)` mutates dataset arrays in place.
|
|
78
|
-
- `save(...)`
|
|
79
|
-
|
|
80
|
-
cannot serialize that attr.
|
|
81
|
-
- `load(...)` opens zipped zarr stores, optionally copying to a temp store and
|
|
82
|
-
normalizing byte-string coordinates.
|
|
78
|
+
- `save(...)` stages a Zarr v3 store and atomically replaces the recording ZIP.
|
|
79
|
+
- `load(...)` opens the recording ZIP and can unpack it for lazy editing.
|
|
83
80
|
|
|
84
81
|
- `src/xarray_behave/annot.py`
|
|
85
82
|
- `Events` is the annotation container used across assembly and GUI code.
|
|
@@ -100,8 +97,6 @@ and swap into y/x before returning arrays.
|
|
|
100
97
|
- Converts between binary `song_events` traces and event-time dictionaries.
|
|
101
98
|
- Connected runs in binary traces become event start/stop rows. Single-sample
|
|
102
99
|
runs become point events with `start == stop`.
|
|
103
|
-
- Category inference helpers are legacy shims and return `"event"` for every
|
|
104
|
-
event type.
|
|
105
100
|
- `eventtimes_to_traces(...)` updates existing event names only.
|
|
106
101
|
- `update_traces(...)` rebuilds traces and can add new events.
|
|
107
102
|
|
|
@@ -168,8 +163,6 @@ Registered provider families:
|
|
|
168
163
|
- `DeepPoseKit`: `_poses_dpk.zarr`
|
|
169
164
|
- `Sleap`: `_poses_sleap.h5`, `_sleap.h5`, `_sleap.h5.slp`
|
|
170
165
|
- Annotations:
|
|
171
|
-
- `DAS`: `_song.h5`, `_vibration.h5`, `_pulse.h5`, `_sine.h5`,
|
|
172
|
-
`_dss.h5`, `_das.h5`
|
|
173
166
|
- `FlySongSegmenter`: `_song.mat`
|
|
174
167
|
- manual CSV/zarr/mat loaders in `annotations_manual.py`
|
|
175
168
|
- definitions loader: `_definitions.csv`
|
|
@@ -276,12 +269,7 @@ conda run -n das-conformer python -m pytest -q tests/test_gui_utils.py tests/tes
|
|
|
276
269
|
conda run -n das-conformer python -m pytest -q tests/test_imports.py tests/test_io.py
|
|
277
270
|
```
|
|
278
271
|
|
|
279
|
-
|
|
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`.
|
|
272
|
+
The assembly and metrics tests use small, synthetic recordings.
|
|
285
273
|
|
|
286
274
|
## Common Change Patterns
|
|
287
275
|
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xarray-behave
|
|
3
|
-
Version: 0
|
|
3
|
+
Version: 1.0
|
|
4
4
|
Summary: xarray tools for behavioral data.
|
|
5
5
|
Author-email: Jan Clemens <clemensjan@googlemail.com>
|
|
6
|
-
Requires-Python: >=3.
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
Requires-Dist: defopt==6.3
|
|
11
|
-
Requires-Dist: flammkuchen
|
|
12
11
|
Requires-Dist: h5py
|
|
13
12
|
Requires-Dist: pyyaml
|
|
14
|
-
Requires-Dist: zarr
|
|
13
|
+
Requires-Dist: zarr>=3.1,<4
|
|
15
14
|
Requires-Dist: dask
|
|
16
15
|
Requires-Dist: pandas
|
|
17
|
-
Requires-Dist: xarray
|
|
16
|
+
Requires-Dist: xarray>=2025.3
|
|
18
17
|
Requires-Dist: numba
|
|
19
18
|
Requires-Dist: numpy
|
|
20
19
|
Requires-Dist: scipy>1.9
|
|
@@ -22,23 +21,28 @@ Requires-Dist: soundfile
|
|
|
22
21
|
Requires-Dist: librosa>0.8
|
|
23
22
|
Requires-Dist: av>=12
|
|
24
23
|
Requires-Dist: PySide6>=6.10
|
|
25
|
-
Requires-Dist: pyqtgraph
|
|
24
|
+
Requires-Dist: pyqtgraph>=0.13.4
|
|
26
25
|
Requires-Dist: qtpy
|
|
27
26
|
Requires-Dist: pytest ; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-qt ; extra == "dev"
|
|
28
28
|
Requires-Dist: flit ; extra == "dev"
|
|
29
|
-
Project-URL: documentation, https://
|
|
29
|
+
Project-URL: documentation, https://github.com/janclemenslab/xarray-behave/blob/v1.0/README.md
|
|
30
30
|
Project-URL: source, https://github.com/janclemenslab/xarray-behave
|
|
31
31
|
Provides-Extra: dev
|
|
32
32
|
|
|
33
33
|
# xarray-behave
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Create a Python environment with Conda and install xarray-behave with uv.
|
|
36
36
|
|
|
37
37
|
```shell
|
|
38
|
-
conda
|
|
38
|
+
conda create -n xb -c conda-forge python=3.14 uv
|
|
39
|
+
conda activate xb
|
|
40
|
+
uv pip install xarray-behave==1.0
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
The GUI saves and opens recording archives in zipped Zarr format 3.
|
|
44
|
+
|
|
45
|
+
See [the demo](doc/demo.ipynb) for usage examples.
|
|
42
46
|
|
|
43
47
|
## GUI configuration
|
|
44
48
|
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# xarray-behave
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create a Python environment with Conda and install xarray-behave with uv.
|
|
4
4
|
|
|
5
5
|
```shell
|
|
6
|
-
conda
|
|
6
|
+
conda create -n xb -c conda-forge python=3.14 uv
|
|
7
|
+
conda activate xb
|
|
8
|
+
uv pip install xarray-behave==1.0
|
|
7
9
|
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
The GUI saves and opens recording archives in zipped Zarr format 3.
|
|
12
|
+
|
|
13
|
+
See [the demo](doc/demo.ipynb) for usage examples.
|
|
10
14
|
|
|
11
15
|
## GUI configuration
|
|
12
16
|
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["flit_core >=3.2"]
|
|
3
|
-
build-backend = "flit_core.buildapi"
|
|
4
|
-
|
|
5
1
|
[project]
|
|
6
2
|
name = "xarray-behave"
|
|
7
3
|
authors = [{ name = "Jan Clemens", email = "clemensjan@googlemail.com" }]
|
|
8
4
|
classifiers = ["License :: OSI Approved :: Apache Software License"]
|
|
9
5
|
dynamic = ["version", "description"]
|
|
10
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
readme = "README.md"
|
|
11
8
|
dependencies = [
|
|
12
9
|
'defopt==6.3',
|
|
13
|
-
'flammkuchen',
|
|
14
10
|
'h5py',
|
|
15
11
|
'pyyaml',
|
|
16
|
-
'zarr
|
|
12
|
+
'zarr>=3.1,<4',
|
|
17
13
|
'dask',
|
|
18
14
|
'pandas',
|
|
19
|
-
'xarray',
|
|
15
|
+
'xarray>=2025.3',
|
|
20
16
|
'numba',
|
|
21
17
|
'numpy',
|
|
22
18
|
'scipy>1.9',
|
|
@@ -24,30 +20,32 @@ dependencies = [
|
|
|
24
20
|
'librosa>0.8',
|
|
25
21
|
'av>=12',
|
|
26
22
|
'PySide6>=6.10',
|
|
27
|
-
'pyqtgraph
|
|
23
|
+
'pyqtgraph>=0.13.4',
|
|
28
24
|
'qtpy',
|
|
29
25
|
]
|
|
30
|
-
readme = "README.md"
|
|
31
26
|
|
|
32
27
|
[project.optional-dependencies]
|
|
33
|
-
dev = ["pytest", "flit"]
|
|
28
|
+
dev = ["pytest", "pytest-qt", "flit"]
|
|
34
29
|
|
|
35
30
|
[project.urls]
|
|
36
31
|
source = "https://github.com/janclemenslab/xarray-behave"
|
|
37
|
-
documentation = "https://
|
|
32
|
+
documentation = "https://github.com/janclemenslab/xarray-behave/blob/v1.0/README.md"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["flit_core >=3.2"]
|
|
36
|
+
build-backend = "flit_core.buildapi"
|
|
38
37
|
|
|
39
38
|
[tool.flit.module]
|
|
40
39
|
name = "xarray_behave"
|
|
41
40
|
|
|
42
|
-
[tool.flit.sdist]
|
|
43
|
-
include = ["scripts/fix_camera_timestamps.py", "tests/test_fix_camera_timestamps.py"]
|
|
44
|
-
|
|
45
41
|
[tool.pytest.ini_options]
|
|
46
42
|
minversion = "6.0"
|
|
47
43
|
testpaths = ["tests"]
|
|
48
44
|
|
|
49
45
|
[tool.ruff]
|
|
50
|
-
extend-select = ["C4", "NPY", "PD", "TCH"]
|
|
51
|
-
ignore = ["E501"]
|
|
52
46
|
show-fixes = true
|
|
53
47
|
line-length = 196
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
extend-select = ["C4", "NPY", "PD", "TC"]
|
|
51
|
+
ignore = ["E501"]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""On-demand zero-phase filtering for audio arrays."""
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from uuid import uuid4
|
|
5
|
+
|
|
6
|
+
import dask.array as da
|
|
7
|
+
import numpy as np
|
|
8
|
+
from scipy import signal
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def bandpass_audio(source, sampling_rate, cutoffs):
|
|
12
|
+
"""Build a lazy band-pass view of the original audio samples."""
|
|
13
|
+
low, high = cutoffs
|
|
14
|
+
nyquist = sampling_rate / 2
|
|
15
|
+
if not 0 < low < high < nyquist:
|
|
16
|
+
raise ValueError(f"Use cutoffs with 0 < lower < upper < {nyquist:g} Hz.")
|
|
17
|
+
sos = signal.butter(5, cutoffs, "bandpass", fs=sampling_rate, output="sos")
|
|
18
|
+
if source.ndim == 1:
|
|
19
|
+
return filtered_blocks(source[:, None], sos, sampling_rate)[:, 0]
|
|
20
|
+
return filtered_blocks(source, sos, sampling_rate)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def filtered_blocks(source, sos, sampling_rate, *, cache_bytes=256_000_000):
|
|
24
|
+
"""Expose filtered, five-second blocks as one sliceable (sample, channel) array."""
|
|
25
|
+
samples, channels = source.shape
|
|
26
|
+
dtype = np.result_type(source.dtype, sos.dtype)
|
|
27
|
+
block_samples = max(1, round(5 * sampling_rate))
|
|
28
|
+
block_bytes = block_samples * channels * dtype.itemsize
|
|
29
|
+
|
|
30
|
+
# Let the slowest pole decay to 1e-12 before retaining the interior.
|
|
31
|
+
# At the true recording ends, sosfiltfilt uses its usual endpoint padding.
|
|
32
|
+
_, poles, _ = signal.sos2zpk(sos)
|
|
33
|
+
radius = max(abs(poles))
|
|
34
|
+
margin = samples if radius >= 1 else int(np.ceil(np.log(1e-12) / np.log(radius)))
|
|
35
|
+
margin = max(margin, 3 * (2 * len(sos) + 1))
|
|
36
|
+
padlen = 3 * (2 * len(sos) + 1 - min(np.count_nonzero(sos[:, 2] == 0), np.count_nonzero(sos[:, 5] == 0)))
|
|
37
|
+
|
|
38
|
+
@lru_cache(maxsize=cache_bytes // block_bytes)
|
|
39
|
+
def read(start, stop):
|
|
40
|
+
left = max(0, start - margin)
|
|
41
|
+
right = min(samples, stop + margin)
|
|
42
|
+
window = source[left:right, :]
|
|
43
|
+
if isinstance(window, da.Array):
|
|
44
|
+
# The outer Dask graph already schedules independent output blocks.
|
|
45
|
+
window = window.compute(scheduler="synchronous")
|
|
46
|
+
filtered = signal.sosfiltfilt(sos, window, axis=0, padlen=min(padlen, len(window) - 1))
|
|
47
|
+
# Own just the retained samples, so the cache budget excludes discarded margins.
|
|
48
|
+
return filtered[start - left : stop - left].copy()
|
|
49
|
+
|
|
50
|
+
def block(block_info):
|
|
51
|
+
start, stop = block_info[None]["array-location"][0]
|
|
52
|
+
return read(start, stop)
|
|
53
|
+
|
|
54
|
+
chunks = da.core.normalize_chunks((block_samples, -1), shape=source.shape, dtype=dtype)
|
|
55
|
+
return da.map_blocks(
|
|
56
|
+
block, chunks=chunks, dtype=dtype, meta=np.empty((0, 0), dtype=dtype),
|
|
57
|
+
name=f"filtered-daq-{uuid4().hex}",
|
|
58
|
+
)
|
|
@@ -8,7 +8,6 @@ from typing import Optional
|
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
import pandas as pd
|
|
11
|
-
import scipy.signal as ss
|
|
12
11
|
|
|
13
12
|
from . import annot, api, event_utils, io, v1 as xb
|
|
14
13
|
from .xarray_behave import _etho_media_paths
|
|
@@ -59,7 +58,6 @@ def replace_event_times(ds, event_times):
|
|
|
59
58
|
|
|
60
59
|
|
|
61
60
|
def assemble_from_file(filename: str, form_data: dict):
|
|
62
|
-
filter_song_requested = form_data["filter_song"] == "yes"
|
|
63
61
|
ds = xb.assemble(
|
|
64
62
|
filepath_daq=filename,
|
|
65
63
|
filepath_annotations=form_data["annotation_path"],
|
|
@@ -67,13 +65,10 @@ def assemble_from_file(filename: str, form_data: dict):
|
|
|
67
65
|
audio_sampling_rate=form_data["samplerate"],
|
|
68
66
|
target_sampling_rate=form_data["target_samplingrate"],
|
|
69
67
|
audio_dataset=form_data["data_set"],
|
|
70
|
-
lazy_load_song=
|
|
68
|
+
lazy_load_song=True,
|
|
71
69
|
make_song_events=form_data.get("generate_event_traces", False),
|
|
72
70
|
)
|
|
73
71
|
|
|
74
|
-
if filter_song_requested:
|
|
75
|
-
ds = filter_song(ds, form_data["f_low"], form_data["f_high"])
|
|
76
|
-
|
|
77
72
|
ds.attrs["filename"] = filename
|
|
78
73
|
ds.attrs["filebase"] = os.path.splitext(filename)[0]
|
|
79
74
|
ds.attrs["datename"] = ""
|
|
@@ -140,10 +135,8 @@ def assemble_from_dir(dirname: str, form_data: dict, pixel_size_mm: Optional[flo
|
|
|
140
135
|
else:
|
|
141
136
|
resample_video_data = True
|
|
142
137
|
|
|
143
|
-
filter_song_requested = form_data["filter_song"] == "yes"
|
|
144
138
|
include_tracks = not form_data["ignore_tracks"]
|
|
145
139
|
include_poses = not form_data["ignore_tracks"]
|
|
146
|
-
lazy_load_song = not filter_song_requested
|
|
147
140
|
base, datename = os.path.split(os.path.normpath(dirname))
|
|
148
141
|
root, dat_path = os.path.split(base)
|
|
149
142
|
annotation_path = None if not len(form_data["annotation_path"]) else form_data["annotation_path"]
|
|
@@ -171,7 +164,7 @@ def assemble_from_dir(dirname: str, form_data: dict, pixel_size_mm: Optional[flo
|
|
|
171
164
|
"target_sampling_rate": form_data["target_samplingrate"],
|
|
172
165
|
"resample_video_data": resample_video_data,
|
|
173
166
|
"pixel_size_mm": pixel_size_mm,
|
|
174
|
-
"lazy_load_song":
|
|
167
|
+
"lazy_load_song": True,
|
|
175
168
|
"include_tracks": include_tracks,
|
|
176
169
|
"include_poses": include_poses,
|
|
177
170
|
"make_song_events": form_data.get("generate_event_traces", False),
|
|
@@ -190,9 +183,6 @@ def assemble_from_dir(dirname: str, form_data: dict, pixel_size_mm: Optional[flo
|
|
|
190
183
|
|
|
191
184
|
ds = xb.assemble(datename, root, dat_path, **assemble_kwargs, **recording_kwargs)
|
|
192
185
|
|
|
193
|
-
if filter_song_requested:
|
|
194
|
-
ds = filter_song(ds, form_data["f_low"], form_data["f_high"])
|
|
195
|
-
|
|
196
186
|
event_names = []
|
|
197
187
|
if form_data["init_annotations"] and len(form_data["events_string"]):
|
|
198
188
|
for pair in form_data["events_string"].split(";"):
|
|
@@ -250,9 +240,6 @@ def load_from_zarr(filename: str, form_data: dict):
|
|
|
250
240
|
if "song_raw" in ds:
|
|
251
241
|
ds.song_raw.load()
|
|
252
242
|
|
|
253
|
-
if form_data["filter_song"] == "yes":
|
|
254
|
-
ds = filter_song(ds, form_data["f_low"], form_data["f_high"])
|
|
255
|
-
|
|
256
243
|
ds = ensure_event_categories(ds)
|
|
257
244
|
logger.info(ds)
|
|
258
245
|
return ds
|
|
@@ -336,26 +323,6 @@ def merge_event_times(existing, imported):
|
|
|
336
323
|
return annot.Events(merged)
|
|
337
324
|
|
|
338
325
|
|
|
339
|
-
def filter_song(ds, f_low, f_high):
|
|
340
|
-
if f_low is None:
|
|
341
|
-
f_low = 1.0
|
|
342
|
-
if "song_raw" in ds:
|
|
343
|
-
if f_high is None:
|
|
344
|
-
f_high = ds.song_raw.attrs["sampling_rate_Hz"] / 2 - 1
|
|
345
|
-
else:
|
|
346
|
-
f_high = min(f_high, ds.song_raw.attrs["sampling_rate_Hz"] / 2 - 1)
|
|
347
|
-
sos_bp = ss.butter(
|
|
348
|
-
5,
|
|
349
|
-
[f_low, f_high],
|
|
350
|
-
"bandpass",
|
|
351
|
-
output="sos",
|
|
352
|
-
fs=ds.song_raw.attrs["sampling_rate_Hz"],
|
|
353
|
-
)
|
|
354
|
-
logger.info(f"Filtering `song_raw` between {f_low} and {f_high} Hz.")
|
|
355
|
-
ds.song_raw.data = ss.sosfiltfilt(sos_bp, ds.song_raw.data, axis=0)
|
|
356
|
-
return ds
|
|
357
|
-
|
|
358
|
-
|
|
359
326
|
def ensure_event_categories(ds):
|
|
360
327
|
if "song_events" in ds and "event_categories" not in ds:
|
|
361
328
|
event_categories = ["event" for _evt in ds.event_types.values]
|
|
@@ -191,7 +191,7 @@ def _matches(spec, context):
|
|
|
191
191
|
patterns = spec.get("path", spec.get("paths", spec.get("patterns", [])))
|
|
192
192
|
matches = []
|
|
193
193
|
for pattern in patterns:
|
|
194
|
-
paths = sorted(glob(pattern.format(**context)))
|
|
194
|
+
paths = sorted(str(Path(path)) for path in glob(pattern.format(**context)))
|
|
195
195
|
if Path(pattern).name.startswith("{recording_prefix}*") and context["recording_prefix"]:
|
|
196
196
|
paths = [path for path in paths if io.is_recording_sidecar(path, context["recording_prefix"])]
|
|
197
197
|
matches.extend(paths)
|
|
@@ -55,15 +55,6 @@ def _as_start_stop_rows(event_data):
|
|
|
55
55
|
return rows[:, :2]
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def infer_event_categories_from_traces(data):
|
|
59
|
-
"""Return legacy event categories for trace columns.
|
|
60
|
-
|
|
61
|
-
Args:
|
|
62
|
-
data ([type]): binary matrix [samples x events]
|
|
63
|
-
"""
|
|
64
|
-
return ["event"] * data.shape[1]
|
|
65
|
-
|
|
66
|
-
|
|
67
58
|
def update_traces(ds, event_times):
|
|
68
59
|
"""Slightly redundant with eventtimes_to_traces but
|
|
69
60
|
will add populate new events.
|