Skip to content

3 add change detection events and trials table#5

Merged
arielleleon merged 17 commits into
mainfrom
3-add-change-detection-events-and-trials-table
Jul 17, 2026
Merged

3 add change detection events and trials table#5
arielleleon merged 17 commits into
mainfrom
3-add-change-detection-events-and-trials-table

Conversation

@arielleleon

@arielleleon arielleleon commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator
  • packages change detection task into NWB file

arielleleon and others added 10 commits July 9, 2026 18:10
build_events_table initialized lick_classification, bout_start, and
reward_type with np.nan (float64), then _classify_rewards/_classify_licks
assigned strings into them. Older pandas silently upcast to object;
pandas 3.0 enforces the dtype and raises "Invalid value ... for dtype
float64" when packaging a change-detection session.

Initialize these three columns as object dtype up front, preserving the
NaN sentinels the NWB layer reads via pd.notna.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
pynwb 4.0 moved events/HED support into core, so the native NWBFile
`events` field collides with the one the standalone ndx-events adds via
NdxEventsNWBFile, raising "NdxEventsNWBFile.__init__: names duplicated:
['events']". The library was declared with unbounded deps, so a plain
pip install resolved pynwb 4 and broke.

Add version bounds (pynwb <4, ndx-events <0.5, ndx-hed <0.3) matching the
standalone-extension / pynwb 3.x line the code targets, and re-lock.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract encoder lookup into `_encoder_from_pkl` and add an `encoder_keys`
argument to `compute_running_speed` (default `("behavior",)`, unchanged for
change-detection). The passive SweepStim path passes `("foraging", "behavior")`
so it can read the foraging-item encoder, falling back to behavior.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port the capsule's `sweepstim_packaging` into the library, refactored into
the two-layer architecture:

- load_data/sweepstim.py: `classify_sweepstim_session`,
  `compute_sweepstim_timestamp_alignment`, and `build_sweepstim_session`
  returning a new `SweepStimData` (presentation + epoch DataFrames + timing).
  Pure numpy/pandas/h5py; HED is left to the nwb layer.
- nwb/sweepstim.py: subject/file builder, `stimulus_presentations` and flat
  `intervals` TimeIntervals builders, sidecar, `assemble_sweepstim_nwbfile`,
  and the one-call `package_sweepstim_nwb` (NWB-Zarr + events.json), mirroring
  `package_nwb`.

HED fragments/helpers for passive sessions live in nwb/hed_tags.py (single
source of truth). Classification/session builders are re-exported eagerly;
`package_sweepstim_nwb` is lazy (pynwb). Full synthetic pkl+sync fixtures and
tests keep flake8, interrogate (100%), and coverage (100%) green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
package_nwb is change-detection-only, so a passive SweepStim pkl (no
items['behavior']) fails deep inside the Stage-1 extractor with a confusing
KeyError. Add package_session, which loads the pkl, classifies it with
classify_sweepstim_session, and dispatches to package_sweepstim_nwb (passive)
or package_nwb (change-detection), forwarding all keyword arguments. This lets
a mixed batch be packaged through one entry point without knowing each
session's type up front.

- nwb/__init__.py: new package_session + __all__/docstring updates.
- __init__.py: lazy root re-export (pynwb stays off the eager import path).
- tests/test_package_session.py: routing (both branches via the real
  classifier) + kwargs-forwarding.

Gates green: flake8, interrogate 100%, 152 tests, coverage 100%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arielleleon
arielleleon requested a review from matchings July 17, 2026 21:36
@arielleleon arielleleon linked an issue Jul 17, 2026 that may be closed by this pull request

@matchings matchings left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noted a few places where task parameter descriptions could be changed but i dont think that needs to block merge of this PR, as long as they are noted for the future.

@arielleleon
arielleleon merged commit e3223a1 into main Jul 17, 2026
3 checks passed
@arielleleon
arielleleon deleted the 3-add-change-detection-events-and-trials-table branch July 17, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add change detection events and trials table

2 participants