From 69d04e6062dfde7bb05ad76102d92811f9b68fd0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 15:46:36 +0000 Subject: [PATCH 1/2] Treat a single ingested parameter dict as one stimulus in parse_stimuli Mirrors VH-Lab/NDI-matlab#1239: ingested metadata can decode to a single struct rather than a list. Iterating a dict would walk its keys and record each key as a stimulus; wrap it in a list instead. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011v7R5tmYTvR18nFhD2nvuA --- src/ndi/app/stimulus/decoder.py | 8 +++++++- tests/test_app_stimulus_decoder.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ndi/app/stimulus/decoder.py b/src/ndi/app/stimulus/decoder.py index af8a072e..ac4c4d4c 100644 --- a/src/ndi/app/stimulus/decoder.py +++ b/src/ndi/app/stimulus/decoder.py @@ -178,7 +178,13 @@ def _presentation_document( data = data or {} t = t or {} - stimuli = [{"parameters": p} for p in data.get("parameters", [])] + parameters = data.get("parameters", []) + if isinstance(parameters, dict): + # Ingested metadata can decode to a single struct rather than a + # list of them (MATLAB's jsondecode gives a struct array); iterating + # a dict would walk its keys, so wrap it as MATLAB's guard does. + parameters = [parameters] + stimuli = [{"parameters": p} for p in (parameters or [])] presentation_time = _presentation_time(t, timeref) from ...database_fun import write_presentation_time_structure diff --git a/tests/test_app_stimulus_decoder.py b/tests/test_app_stimulus_decoder.py index 3b55c72b..0e6c9cb8 100644 --- a/tests/test_app_stimulus_decoder.py +++ b/tests/test_app_stimulus_decoder.py @@ -179,6 +179,21 @@ def test_the_document_records_the_order_and_the_stimuli(self): assert presentation["presentation_order"] == [1, 2, 1, 2] assert presentation["stimuli"][0]["parameters"] == {"isblank": 0, "angle": 30} + def test_a_single_parameter_struct_is_one_stimulus_not_its_keys(self): + """Ingested metadata can come back as one dict rather than a list; + MATLAB guards the same case (a struct array) in parse_stimuli.""" + + class OneStim(FakeStimulator): + def readtimeseriesepoch(self, epoch, t0, t1): + data, t, ref = super().readtimeseriesepoch(epoch, t0, t1) + data["parameters"] = {"isblank": 0, "angle": 30} + return data, t, ref + + session, element_id = real_session() + newdocs, _ = ndi_app_stimulus_decoder(session).parse_stimuli(OneStim(element_id)) + stimuli = newdocs[0].document_properties["stimulus_presentation"]["stimuli"] + assert stimuli == [{"parameters": {"isblank": 0, "angle": 30}}] + def test_it_depends_on_the_element_it_decoded(self): session, element_id = real_session() newdocs, _ = ndi_app_stimulus_decoder(session).parse_stimuli(FakeStimulator(element_id)) From d0ff89e9aa2588c6c33ef9137fe8f94559c77b4d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 15:50:11 +0000 Subject: [PATCH 2/2] Bridge: bump decoder and metadatareader to NDI-matlab 9ded19a Clears the drift check against the paired NDI-matlab branch (VH-Lab/NDI-matlab#1239). decoder is ported in this PR; metadatareader needs no Python change, recorded in its decision_log. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011v7R5tmYTvR18nFhD2nvuA --- src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml | 2 +- src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml b/src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml index 5b28dd26..9d8cc64a 100644 --- a/src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml +++ b/src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml @@ -17,7 +17,7 @@ classes: - name: decoder type: class matlab_path: "src/ndi/+ndi/+app/+stimulus/decoder.m" - matlab_last_sync_hash: "0e2caa0" + matlab_last_sync_hash: "9ded19a" python_path: "ndi/app/stimulus/decoder.py" python_class: "ndi_app_stimulus_decoder" inherits: "ndi.app" diff --git a/src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml b/src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml index 05d2781a..dd79d303 100644 --- a/src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml +++ b/src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml @@ -17,10 +17,15 @@ classes: - name: metadatareader type: class matlab_path: "+ndi/+daq/metadatareader.m" - matlab_last_sync_hash: "fe64a9f5" + matlab_last_sync_hash: "9ded19a" python_path: "ndi/daq/metadatareader/__init__.py" python_class: "ndi_daq_metadatareader" inherits: "ndi.ido" + decision_log: > + Examined NDI-matlab 9ded19a (readmetadata_ingested now converts a struct + array to a cell array of structs). No Python change needed: + readmetadata_ingested here already returns a list of dicts, wrapping a + single dict in a list. properties: - name: tab_separated_file_parameter