Parses and packages AIND VR Foraging behavioral sessions into tabular (parquet) and NWB outputs.
Project description
Aind.Behavior.VrForaging.Packaging
Parses raw AIND VR-foraging behavioral sessions into analysis-ready parquet tables and an NWB file.
Architecture
A session is loaded once (via contraqctor), then a set of independent
processors fan out over it. Each processor owns one output and knows how to
express it in two targets:
raw session dir
│
▼
Dataset ◄── aind_behavior_vr_foraging.data_contract.dataset(path)
│
▼
create_processors(dataset) # picks processor variants by dataset version
│ [TrialTable, PositionAndVelocity, Licks, Sniffing, SoftwareEvents, Events]
│
├─► proc.compute() ──► pandas DataFrame ──► one <name>.parquet (run_session)
│ (provenance stamped into df.attrs / parquet schema)
│
└─► proc.nwbize(nwb) ──► populates an NdxEventsNWBFile ──► .nwb.zarr (NwbSession)
- Processor — every processor subclasses
AbstractProcessor, implementing_compute()and (optionally)nwbize().compute()wraps_compute()and stamps provenance (packaging_version,data_contract_version,dataset_version,processor) into the DataFrame'sattrs. - DataFrame — the common in-memory representation. One row per unit of the output (e.g. one trial-table row = one site).
- Parquet —
pipeline.run_session()callscompute()on each processor and writes a parquet per processor, promotingdf.attrsto first-class parquet metadata (readable from DuckDB, Polars, R arrow, Spark, …). - NWB —
NwbSessionbuilds a singleNdxEventsNWBFilefrom AIND metadata, then calls each processor'snwbize()to fill it, and writes NWB-Zarr.
Version dispatch is automatic: datasets with schema version < 0.6.0 receive
legacy processor variants.
Examples
- Runnable script covering the parquet workflows (all-at-once, single stream, load-back): scripts/example_parquet_pipeline.py
- The NWB workflow: docs/knowledge/architecture/nwb-packaging.md
- Full architecture docs: docs/knowledge/ (start at overview.md)
Get a trials table
Install straight from GitHub with uv:
# into a uv project
uv add "git+https://github.com/AllenNeuralDynamics/Aind.Behavior.VrForaging.Packaging.git"
# or into the current environment
uv pip install "git+https://github.com/AllenNeuralDynamics/Aind.Behavior.VrForaging.Packaging.git"
Then load a session and compute the trials table (one row per site):
from aind_behavior_vr_foraging.data_contract import dataset
from aind_behavior_vr_foraging_packaging.pipeline import get_trial_table_processor
ds = dataset("path/to/session") # load the raw session
trials_df = get_trial_table_processor(ds).compute()
trials_df.to_parquet("trials.parquet") # optional: persist to disk
print(f"{len(trials_df)} sites, {trials_df['has_reward'].sum()} rewarded")
get_trial_table_processor automatically picks the current or legacy variant
based on the dataset's schema version. To produce every table at once, use
run_session(ds, "output_dir") instead — it writes trials.parquet,
position_velocity.parquet, and the rest, and returns them keyed by name.
Contributors
Contributions to this repository are welcome! However, please ensure that your code adheres to the recommended DevOps practices below:
Linting
We use ruff as our primary linting tool.
Testing
Attempt to add tests when new features are added.
To run the currently available tests, run uv run pytest from the root of the repository.
Integration tests
Integration tests run the parser end-to-end against real datasets stored in a public S3 bucket. They are gated by a pytest marker so they don't run by default.
Run locally:
uv run pytest -m integration
The first run downloads datasets (~100 MB per dataset) to tests/integration/.cache/. Subsequent runs reuse the cache when the S3 ETag matches. The cache directory is gitignored.
Trigger on a PR:
Integration tests do not run on every PR. To run them for a specific PR, add the run-integration label via the GitHub UI (open the PR, click Labels in the right-hand sidebar, and select run-integration) or with:
gh pr edit <PR_NUMBER> --add-label run-integration
The integration job runs automatically on push to main and on release: published. A release cannot ship without the integration suite passing.
Adding a dataset:
Add an entry to tests/integration/datasets.yml. The manifest schema and full field documentation are in tests/integration/model.py (Pydantic model). The rationale field is required and is printed alongside any test failure to make triage fast.
Lock files
We use uv to manage our lock files and therefore encourage everyone to use uv as a package manager as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aind_behavior_vr_foraging_packaging-0.0.4.tar.gz.
File metadata
- Download URL: aind_behavior_vr_foraging_packaging-0.0.4.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fb68f70b845e854d431ba19216038b691904af59ebd739b297692b5d30f05da
|
|
| MD5 |
6e27b6a8168b21271a63b648240de264
|
|
| BLAKE2b-256 |
b24f3015a6455b25c1bc75fc87e990084b9dd08590cce5fabbe972c7641b5bd9
|
File details
Details for the file aind_behavior_vr_foraging_packaging-0.0.4-py3-none-any.whl.
File metadata
- Download URL: aind_behavior_vr_foraging_packaging-0.0.4-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a54c8fd0838a2435f12afc8dd28cdcc293174de2233d8fa904ab30387e9bfb04
|
|
| MD5 |
53e9fa08946965d32d451b5e2e8fc7f4
|
|
| BLAKE2b-256 |
4e96d55013214edf96c82f9f719b0a0e12b362921895e6bb0af6c8322107cda5
|