Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ndi/app/stimulus/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ndi/app/stimulus/ndi_matlab_python_bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/ndi/daq/metadatareader/ndi_matlab_python_bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/test_app_stimulus_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading