Skip to content

Unify impedance CSV output across streaming and non-streaming paths#187

Merged
calvinleng-science merged 5 commits into
mainfrom
maxr/unify-impedance-csv
Jun 26, 2026
Merged

Unify impedance CSV output across streaming and non-streaming paths#187
calvinleng-science merged 5 commits into
mainfrom
maxr/unify-impedance-csv

Conversation

@namthor9

Copy link
Copy Markdown
Contributor

Summary

Makes synapsectl query and synapsectl query --stream produce identical impedance CSVs, fixes pre-existing format discrepancies, and adds a peripheral metadata header line.

Unified format (both paths):

Peripheral: NYX1-512
Electrode ID,Magnitude (Ohms),Phase (degrees),Status
8,5523878.0,-83.439453125,1
10,5462193.0,-84.0098648071289,1

Changes

  • New shared module synapse/cli/impedance_csv.py — single source of truth for the header, columns, row format, and peripheral-name resolution. Both paths use it, so output is byte-identical (LF line endings forced).
  • New Peripheral: <name> header line. The name is resolved from device.info(), preferring the peripheral_id named in the query, falling back to the broadband (recording) source, then the first peripheral, else Unknown.
  • Fixed streaming discrepancies. The streaming path previously wrote a different header (Electrode ID,Magnitude,Phase), omitted the (Ohms)/(degrees) units, and had no Status column. It now matches the non-streaming format.
  • Streaming now records failed measurements with Status=0 (success = 1). Previously failed electrodes were dropped from the CSV entirely.

Notes

  • Peripheral name comes from device.info(), not the impedance response. For a single-recording-device setup this is exact; with multiple broadband sources and no peripheral_id in the query it picks the first. Returning the peripheral in the response itself would require a synapse-api proto change (out of scope here).
  • peripheral_id lookup uses getattr(..., "peripheral_id", 0) so it's robust to older protos that lack the field on ImpedanceQuery.

Testing

  • py_compile passes on all three files. Generated *_pb2.py are gitignored, so full runtime exercise requires a built environment / device.

Both synapsectl query and synapsectl query --stream now write identical
impedance CSVs via a shared synapse.cli.impedance_csv module:

  Peripheral: <name>
  Electrode ID,Magnitude (Ohms),Phase (degrees),Status
  <electrode_id>,<magnitude>,<phase>,<status>

Changes:
- Add a 'Peripheral: <name>' metadata header line, resolved from the
  device's peripheral list (preferring the query's peripheral_id, else
  the broadband recording source).
- Fix streaming CSV discrepancies: it previously wrote a different header
  ('Electrode ID,Magnitude,Phase'), omitted units, and had no Status
  column. It now matches the non-streaming format.
- Streaming now also writes failed measurements with Status=0 (success=1);
  previously failed measurements were dropped from the CSV entirely.
@namthor9 namthor9 force-pushed the maxr/unify-impedance-csv branch 2 times, most recently from 6106171 to 91fede5 Compare June 24, 2026 21:46
namthor9 added 3 commits June 24, 2026 15:47
Use 'Peripheral,<name>' (a valid 2-column CSV row) instead of the
colon-separated 'Peripheral: <name>' line, so standard CSV parsers handle
the metadata line gracefully.
@calvinleng-science

Copy link
Copy Markdown
Contributor

Make info() resolution consistent across both paths. The streaming case resolves the peripheral name before stream_query(), and the non-streaming case resolves it after.

We should make both resolve the peripheral name prior to the query, as if something happens to the probe to make it unenumerate after the query, we will not be able to correctly resolve the peripheral name. Just more robust this way.

@calvinleng-science calvinleng-science merged commit dc98cc9 into main Jun 26, 2026
2 checks passed
@calvinleng-science calvinleng-science deleted the maxr/unify-impedance-csv branch June 26, 2026 22:02
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.

2 participants