Skip to content
Open
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
3 changes: 2 additions & 1 deletion doc/source/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ and may not be the current affiliation of a contributor.
* Axel Coiffard-Donaty
* Anthony Mercer
* Aaron Kanzer [53]
* Vladyslav Ivanov [54]

1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Université Claude Bernard Lyon 1
2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France
Expand Down Expand Up @@ -162,7 +163,7 @@ and may not be the current affiliation of a contributor.
51. Stony Brook University, Stony Brook, NY, USA
52. University of Sussex, Brighton, UK
53. Scigantic, USA

54. German Primate Centre, Göttingen, Germany


If we've somehow missed you off the list we're very sorry - please let us know.
Expand Down
27 changes: 23 additions & 4 deletions neo/rawio/spikegadgetsrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
coordinates) for each hwChan, but the column-to-byte-position mapping is
the identity: column i reads byte pair i, with hwChan i's data.

* NRIC recordings (`device="neuropixelsNRIC"`, the amplifier chip of the SpikeGadgets
Pixie384 headstage): hwChan ascending order, identical to Neuropixels recordings;
the NRIC chip is the same amplifier generation as Neuropixels probes, so the reader
treats the two identically. Only `deviceSubType="10"` has been verified against
hardware so far. The HardwareConfiguration of NRIC files also declares a
`neuropixels_LFP` Device without Channel children: its numBytes contribute to the
packet size, but its rotating subsampled LFP samples (lfpSubsamplingInterval) are
not decoded and not exposed as a stream.

Author: Samuel Garcia
"""

Expand All @@ -107,6 +116,12 @@
)
from neo.core import NeoReadWriteError

# SpikeConfiguration devices whose ephys region the MCU firmware emits in
# hwChan-ascending byte order. The NRIC chip (SpikeGadgets Pixie384 headstage)
# is the same amplifier generation as Neuropixels probes and shares this layout;
# only deviceSubType "10" has been verified against hardware so far.
_HWCHAN_ASCENDING_DEVICES = ("neuropixels1", "neuropixels2", "neuropixelsNRIC")


class SpikeGadgetsRawIO(BaseRawIO):
extensions = ["rec"]
Expand Down Expand Up @@ -137,6 +152,10 @@ def __init__(self, filename="", selected_streams=None):
This will not affect functions that do not rely on the data having physical units,
e.g., _get_analogsignal_chunk, but functions such as rescale_signal_raw_to_float
will be inaccurate.
The ephys channel layout depends on the headstage declared by
SpikeConfiguration.device: Intan chip-interleaved (``"intan"`` or absent),
Neuropixels 1.0/2.0 and NRIC (Pixie384) hwChan-ascending. See the module
docstring for the per-device byte layouts.

Examples
--------
Expand Down Expand Up @@ -330,14 +349,14 @@ def _parse_header(self):
# declared in SpikeConfiguration.device.
# - Intan recordings are chip-interleaved by the MCU (main control unit), so we
# reproduce that ordering from the chip layout.
# - Neuropixels recordings are emitted in hwChan ascending order: byte pair i
# holds the sample from the electrode whose hwChan = i.
# - Neuropixels and NRIC recordings are emitted in hwChan ascending order:
# byte pair i holds the sample from the electrode whose hwChan = i.
spike_device = sconf.attrib.get("device")
if spike_device in (None, "intan"):
hwchans_in_binary_order = self._intan_hwchans_in_binary_order(
sconf, num_ephy_channels, num_ephy_channels_xml
)
elif spike_device in ("neuropixels1", "neuropixels2"):
elif spike_device in _HWCHAN_ASCENDING_DEVICES:
xml_hwchans = {int(schan.attrib["hwChan"]) for trode in sconf for schan in trode}
expected = set(range(num_ephy_channels))
if xml_hwchans != expected:
Expand Down Expand Up @@ -368,7 +387,7 @@ def _parse_header(self):
gain = 1.0
units = ""

if spike_device in ("neuropixels1", "neuropixels2"):
if spike_device in _HWCHAN_ASCENDING_DEVICES:
chan_id = f"hwChan{hw_chan}"
sorting_group = schan.attrib.get("spikeSortingGroup", "0")
name = f"probe{sorting_group}_chan{hw_chan}"
Expand Down
53 changes: 53 additions & 0 deletions neo/test/rawiotest/test_spikegadgetsrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path
import tempfile

import numpy as np

from neo.rawio.spikegadgetsrawio import SpikeGadgetsRawIO
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
from numpy.testing import assert_array_equal
Expand All @@ -19,6 +21,7 @@ class TestSpikeGadgetsRawIO(
"spikegadgets/SpikeGadgets_test_data_2xNpix1.0_20240318_173658.rec",
"spikegadgets/neuropixels2_4shank/20260122_134412_merged_cropped_1min_NP2.rec",
"spikegadgets/msh_1024ch/msh_1024ch.rec",
"spikegadgets/SpikeGadgets_test_data_Pixie384_20261104_cropped.rec",
]

def test_parse_header_missing_channels(self):
Expand Down Expand Up @@ -82,6 +85,56 @@ def test_neuropixels_uses_hwchan_ids(self):
groups = {n.split("_")[0] for n in trodes_names}
self.assertEqual(groups, {"probe0", "probe1"})

def test_nric_uses_hwchan_ids(self):
# NRIC (Pixie384 headstage, device="neuropixelsNRIC") recordings share the
# Neuropixels hwChan-ascending layout and therefore the same id/name
# semantics: ids are f"hwChan{i}" and names are f"probe{spikeSortingGroup}_chan{i}".
file_path = Path(self.get_local_path("spikegadgets/SpikeGadgets_test_data_Pixie384_20261104_cropped.rec"))
reader = SpikeGadgetsRawIO(filename=file_path)
reader.parse_header()

trodes_mask = reader.header["signal_channels"]["stream_id"] == "trodes"
trodes_ids = list(reader.header["signal_channels"]["id"][trodes_mask])
trodes_names = list(reader.header["signal_channels"]["name"][trodes_mask])

self.assertEqual(len(trodes_ids), 384)
self.assertEqual(trodes_ids[0], "hwChan0")
self.assertEqual(trodes_ids[-1], "hwChan383")
# all channels of this recording belong to a single spikeSortingGroup "0"
self.assertEqual(trodes_names[0], "probe0_chan0")
self.assertEqual(trodes_names[-1], "probe0_chan383")

# gain comes from the SpikeNTrode spikeScalingToUv attribute
trodes_gains = reader.header["signal_channels"]["gain"][trodes_mask]
trodes_units = reader.header["signal_channels"]["units"][trodes_mask]
self.assertEqual(set(trodes_units), {"uV"})
self.assertTrue(np.allclose(trodes_gains, 0.018311105685598315))

def test_nric_traces_match_trodes_export(self):
# Cross-check the decoded ephys region against Trodes' own export of the same
# recording (raw_group0.dat, Fields: <voltage 384*int16>): this pins the
# hwChan-ascending layout of the NRIC device to an independent decoder.
file_path = Path(self.get_local_path("spikegadgets/SpikeGadgets_test_data_Pixie384_20261104_cropped.rec"))
reader = SpikeGadgetsRawIO(filename=file_path)
reader.parse_header()

stream_index = list(reader.header["signal_streams"]["id"]).index("trodes")
n_samples = 1000
traces = reader.get_analogsignal_chunk(
block_index=0, seg_index=0, i_start=0, i_stop=n_samples, stream_index=stream_index
)
self.assertEqual(traces.dtype, np.dtype("int16"))
self.assertEqual(traces.shape, (n_samples, 384))

dat_path = file_path.with_name("SpikeGadgets_test_data_Pixie384_20261104_trodes_raw_cropped.dat")
with open(dat_path, "rb") as f:
head = f.read(65536)
end = head.find(b"<End settings>")
offset = head.find(b"\n", end) + 1
reference = np.memmap(dat_path, dtype="<i2", mode="r", offset=offset, shape=(n_samples, 384))

assert_array_equal(traces, reference)

def test_opening_gibberish_file(self):
"""Test that parsing a file without </Configuration> raises ValueError instead of infinite loop."""
# Create a temporary file with gibberish content that doesn't have the required tag
Expand Down