Skip to content

Commit e92de38

Browse files
committed
zach feedback
1 parent 19b76e3 commit e92de38

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,32 @@ def _parse_header(self):
132132
new_channels = []
133133
for chan_info in info["channels"]:
134134
chan_id = chan_info["channel_name"]
135+
136+
units = chan_info["units"]
137+
if units == "":
138+
# When units are not provided they are microvolts for neural channels and volts for ADC channels
139+
# See https://open-ephys.github.io/gui-docs/User-Manual/Recording-data/Binary-format.html#continuous
140+
units = "uV" if "ADC" not in chan_id else "V"
141+
142+
# Special cases for stream
135143
if "SYNC" in chan_id and not self.load_sync_channel:
136144
# the channel is removed from stream but not the buffer
137145
stream_id = ""
138146

139-
if chan_info["units"] == "":
140-
# in some cases for some OE version the unit is "", but the gain is to "uV"
141-
units = "uV"
142-
else:
143-
units = chan_info["units"]
144-
145-
if "ADC" in chan_id:
147+
if "ADC" in chan_id:
146148
# These are non-neural channels and their stream should be separated
147149
# We defined their stream_id as the stream_index of neural data plus the number of neural streams
148150
# This is to not break backwards compatbility with the stream_id numbering
149151
stream_id = str(stream_index + len(sig_stream_names))
150-
# For ADC channels multiplying by the bit_volts when units are not provided converts to Volts
151-
units = "V" if units == "" else units
152-
153-
gain = chan_info["bit_volts"]
152+
153+
gain = float(chan_info["bit_volts"])
154+
sampling_rate = float(info["sample_rate"])
154155
offset = 0.0
155156
new_channels.append(
156157
(
157158
chan_info["channel_name"],
158159
chan_id,
159-
float(info["sample_rate"]),
160+
sampling_rate,
160161
info["dtype"],
161162
units,
162163
gain,
@@ -224,9 +225,10 @@ def _parse_header(self):
224225
)
225226

226227
# Check if ADC and non-ADC channels are contiguous
227-
is_adc = ["ADC" in ch["channel_name"] for ch in info["channels"]]
228-
first_adc = is_adc.index(True) if True in is_adc else len(is_adc)
229-
if any(not x for x in is_adc[first_adc:]):
228+
is_channel_adc = ["ADC" in ch["channel_name"] for ch in info["channels"]]
229+
first_adc_index = is_channel_adc.index(True) if any(is_channel_adc) else len(is_channel_adc)
230+
non_adc_channels_after_adc_channels = [not flag for flag in is_channel_adc[first_adc_index:]]
231+
if any(non_adc_channels_after_adc_channels):
230232
raise ValueError(
231233
"Interleaved ADC and non-ADC channels are not supported. "
232234
"ADC channels must be contiguous. Open an issue in python-neo to request this feature."

0 commit comments

Comments
 (0)