Repository navigation
vhlabvisspike2: decode stimulus events from stimtimes.txt and stims.mat - #351
Merged
Merged
Conversation
The Python reader was a bare subclass of the CED Spike2 reader, so the mk1-mk3 / e1-e3 stimulus channels were looked up in spike2data.smr instead of being decoded from the epoch directory. Port MATLAB's epochclock, getchannelsepoch, samplerate and readevents_epochsamples_native: - read stimtimes.txt and stims.mat through vhlib.StimDecode (read_stimtimes_txt, getstimscript) from vhlab-library-python, an existing dependency, rather than reimplementing them; - apply stimtimes2stimtimes_mapping.txt and mti2stimtimes_mapping.txt (1-based indices to keep, NaN dropped); - raise if the trigger counts differ, and raise VHLabVisSpike2StimulusMismatchError (identifier ndi:setup:daq:reader:mfdaq:stimulus:vhlabvisspike2:StimulusMismatch) if a trial's Spike2 id differs from mod(mti.stimid, 256), with the wording of VH-Lab/NDI-matlab#1114; - map setup/off/clear into Spike2 time via stimtimes(i) - startStopTimes(2). Adds a bridge file for ndi.setup.daq.reader.mfdaq.stimulus with the vhlabvisspike2 entry, and tests on a synthetic epoch directory: records agree, count mismatch, id mismatch naming the epoch, and a mapping file fixing a run that stopped early. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011v7R5uJJtaq8SVB4eEwnBR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ndi.setup.daq.reader.mfdaq.stimulus.vhlabvisspike2was a bare subclass of the CED Spike2 reader. Themk1–mk3ande1–e3stimulus channels were therefore looked up as channel numbers inspike2data.smr. MATLAB instead decodes them from the epoch directory.Change
This ports
+ndi/+setup/+daq/+reader/+mfdaq/+stimulus/vhlabvisspike2.m, coveringepochclock,getchannelsepoch,samplerateandreadevents_epochsamples_native:stimtimes.txtandstims.mat(MTI2) throughvhlib.StimDecode.read_stimtimes_txt/getstimscriptand usesvlt.data.dropnan. These come from vhlab-library-python and vhlab-toolbox-python, which are already dependencies, so nothing is reimplemented. vhlab-NewStim-python is not needed because only thestimidandstartStopTimesfields ofMTI2are read.ndi.daq.metadatareader.NewStimStimsreads stimulus parameters from the same file and does not overlap with this.stimtimes2stimtimes_mapping.txtandmti2stimtimes_mapping.txtwhen they are present. Each lists 1-based indices to keep, and NaN entries are dropped.ValueErrorwith MATLAB's wording.mod(mti.stimid,256)it raisesVHLabVisSpike2StimulusMismatchError. This is aValueErrorsubclass whose.identifierisndi:setup:daq:reader:mfdaq:stimulus:vhlabvisspike2:StimulusMismatch. The message follows vhlab importer: robust handling of legacy cell intervals and cell names VH-Lab/NDI-matlab#1114 (9fe55861a):Epoch t00006: stimulus number N does not line up …, followed by the path and a pointer to the mapping files.timeshift = stimtimes(i) - startStopTimes(2), and results are limited to the windowt0 <= t <= t1.Bridge
INTERFACE UPDATE: this adds a new
src/ndi/setup/daq/reader/mfdaq/stimulus/ndi_matlab_python_bridge.yamlwith avhlabvisspike2class entry, examined against NDI-matlabfe64a9f53. It records:matlab_branchis deliberately not set, because the file is already on main. When #1114 merges, the drift check will flag the entry for re-examination;{i}vs{end+1}).Tests
tests/test_setup_vhlabvisspike2.pybuilds synthetic epoch directories containingstimtimes.txtand a minimalstims.mat. It covers:stims.mathas 5);black --check,ruff checkand the fullpytest tests/all pass. The bridge tests also pass when run against a full NDI-matlab checkout.Follow-up
VH-Lab/NDI-matlab#1114 has not merged yet. Once it does:
setupentry in the root bridge (src/ndi/ndi_matlab_python_bridge.yaml) saying that #1114's other changes are all in+ndi/+setup/+conv/+vhlab, which has no Python port;Generated by Claude Code