Skip to content

Commit d096f8b

Browse files
authored
Merge branch 'master' into remove-copy
2 parents e5b0fd1 + eaa6903 commit d096f8b

File tree

6 files changed

+50
-38
lines changed

6 files changed

+50
-38
lines changed

neo/rawio/brainvisionrawio.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,22 @@ def _parse_header(self):
9292
channel_desc = channel_infos[f"Ch{c+1}"]
9393
except KeyError:
9494
channel_desc = channel_infos[f"ch{c + 1}"]
95-
name, ref, res, units = channel_desc.split(",")
96-
units = units.replace("µ", "u")
95+
# split up channel description, handling default values
96+
cds = channel_desc.split(",")
97+
name = cds[0]
98+
if len(cds) >= 2:
99+
ref = cds[1]
100+
else:
101+
ref = ""
102+
if len(cds) >= 3:
103+
res = cds[2]
104+
else:
105+
res = "1.0"
106+
if len(cds) == 4:
107+
units = cds[3]
108+
else:
109+
units = "u"
110+
units = units.replace("µ", "u") # Brainvision spec for specific unicode
97111
chan_id = str(c + 1)
98112
if sig_dtype == np.int16 or sig_dtype == np.int32:
99113
gain = float(res)

neo/rawio/plexon2rawio/plexon2rawio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ def _parse_header(self):
234234

235235
# In a PL2 spike channel header, the field "m_NumberOfUnits" denotes the number
236236
# of units to which spikes detected on that channel have been assigned. It does
237-
# not account for unsorted spikes, i.e., spikes that have not been assigned to
238-
# a unit. It is Plexon's convention to assign unsorted spikes to channel_unit_id=0,
239-
# and sorted spikes to channel_unit_id's 1, 2, 3...etc. Therefore, for a given value of
240-
# m_NumberOfUnits, there are m_NumberOfUnits+1 channel_unit_ids to consider - 1
241-
# unsorted channel_unit_id (0) + the m_NumberOfUnits sorted channel_unit_ids.
242-
for channel_unit_id in range(schannel_info.m_NumberOfUnits+1):
237+
# not account for unsorted spikes, i.e., spikes that have not been assigned to
238+
# a unit. It is Plexon's convention to assign unsorted spikes to channel_unit_id=0,
239+
# and sorted spikes to channel_unit_id's 1, 2, 3...etc. Therefore, for a given value of
240+
# m_NumberOfUnits, there are m_NumberOfUnits+1 channel_unit_ids to consider - 1
241+
# unsorted channel_unit_id (0) + the m_NumberOfUnits sorted channel_unit_ids.
242+
for channel_unit_id in range(schannel_info.m_NumberOfUnits + 1):
243243
unit_name = f"{schannel_info.m_Name.decode()}.{channel_unit_id}"
244244
unit_id = f"unit{schannel_info.m_Channel}.{channel_unit_id}"
245245
wf_units = schannel_info.m_Units

neo/rawio/plexonrawio.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
from neo.core.baseneo import NeoReadWriteError
4747

48+
4849
class PlexonRawIO(BaseRawIO):
4950
extensions = ["plx"]
5051
rawmode = "one-file"
@@ -232,18 +233,18 @@ def _parse_header(self):
232233

233234
# signals channels
234235
source_id = []
235-
236+
236237
# Scanning sources and populating signal channels at the same time. Sources have to have
237238
# same sampling rate and number of samples to belong to one stream.
238239
signal_channels = []
239240
channel_num_samples = []
240-
241+
241242
# We will build the stream ids based on the channel prefixes
242243
# The channel prefixes are the first characters of the channel names which have the following format:
243244
# WB{number}, FPX{number}, SPKCX{number}, AI{number}, etc
244245
# We will extract the prefix and use it as stream id
245246
regex_prefix_pattern = r"^\D+" # Match any non-digit character at the beginning of the string
246-
247+
247248
if self.progress_bar:
248249
chan_loop = trange(nb_sig_chan, desc="Parsing signal channels", leave=True)
249250
else:
@@ -271,7 +272,7 @@ def _parse_header(self):
271272
offset = 0.0
272273
channel_prefix = re.match(regex_prefix_pattern, name).group(0)
273274
stream_id = channel_prefix
274-
275+
275276
signal_channels.append((name, str(chan_id), sampling_rate, sig_dtype, units, gain, offset, stream_id))
276277

277278
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
@@ -312,7 +313,7 @@ def _parse_header(self):
312313
self._stream_index_to_stream_id[stream_index] = stream_id
313314

314315
mask = signal_channels["stream_id"] == stream_id
315-
316+
316317
signal_num_samples = np.unique(channel_num_samples[mask])
317318
if signal_num_samples.size > 1:
318319
raise NeoReadWriteError(f"Channels in stream {stream_id} don't have the same number of samples")
@@ -322,7 +323,7 @@ def _parse_header(self):
322323
if signal_sampling_frequency.size > 1:
323324
raise NeoReadWriteError(f"Channels in stream {stream_id} don't have the same sampling frequency")
324325
self._stream_id_sampling_frequency[stream_id] = signal_sampling_frequency[0]
325-
326+
326327
self._global_ssampling_rate = global_header["ADFrequency"]
327328

328329
# Determine number of units per channels
@@ -425,8 +426,6 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
425426
if i_stop is None:
426427
i_stop = self._stream_id_samples[stream_id]
427428

428-
429-
430429
mask = signal_channels["stream_id"] == stream_id
431430
signal_channels = signal_channels[mask]
432431
if channel_indexes is not None:

neo/test/rawiotest/test_brainvisionrawio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TestBrainVisionRawIO(
2020
"brainvision/File_brainvision_3_float32.vhdr",
2121
"brainvision/File_brainvision_3_int16.vhdr",
2222
"brainvision/File_brainvision_3_int32.vhdr",
23+
"brainvision/File_brainvision_4_float32.vhdr",
2324
]
2425

2526
entities_to_download = ["brainvision"]

neo/test/rawiotest/test_neuralynxrawio.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,19 +361,19 @@ def test_equality(self):
361361
self.assertNotEqual(ns0, ns1)
362362

363363

364-
# I comment this now and will put it back when files will be in gin.g-node
365-
# class TestNlxHeader(TestNeuralynxRawIO, unittest.TestCase):
366-
# def test_no_date_time(self):
367-
# filename = self.get_local_path("neuralynx/NoDateHeader/NoDateHeader.nev")
364+
class TestNlxHeader(TestNeuralynxRawIO, unittest.TestCase):
365+
def test_no_date_time(self):
366+
filename = self.get_local_path("neuralynx/NoDateHeader/NoDateHeader.nev")
368367

369-
# with self.assertRaises(IOError):
370-
# hdr = NlxHeader(filename)
368+
with self.assertRaises(IOError):
369+
hdr = NlxHeader(filename)
370+
371+
hdr = NlxHeader(filename, props_only=True)
371372

372-
# hdr = NlxHeader(filename, props_only=True)
373+
self.assertEqual(len(hdr), 11) # 9 properties plus channel_ids and channel_names
374+
self.assertEqual(hdr["ApplicationName"], "Pegasus")
375+
self.assertEqual(hdr["FileType"], "Event")
373376

374-
# self.assertEqual(len(hdr), 11)
375-
# self.assertEqual(hdr['ApplicationName'], 'Pegasus')
376-
# self.assertEqual(hdr['FileType'], 'Event')
377377

378378
if __name__ == "__main__":
379379
unittest.main()

neo/test/rawiotest/test_plexon2rawio.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,24 @@ class TestPlexon2RawIO(
2626
):
2727
rawioclass = Plexon2RawIO
2828
entities_to_download = ["plexon"]
29-
entities_to_test = ["plexon/4chDemoPL2.pl2",
30-
"plexon/NC16FPSPKEVT_1m.pl2"
31-
]
32-
29+
entities_to_test = ["plexon/4chDemoPL2.pl2", "plexon/NC16FPSPKEVT_1m.pl2"]
3330

3431
def test_check_enabled_flags(self):
3532
"""
3633
This test loads a 1-minute PL2 file with 16 channels' each
37-
of field potential (FP), and spike (SPK) data. The channels
38-
cycle through 4 possible combinations of m_ChannelEnabled
39-
and m_ChannelRecordingEnabled - (True, True), (True, False),
40-
(False, True), and (False, False). With 16 channels for each
41-
source, each combination of flags occurs 4 times. Only the
34+
of field potential (FP), and spike (SPK) data. The channels
35+
cycle through 4 possible combinations of m_ChannelEnabled
36+
and m_ChannelRecordingEnabled - (True, True), (True, False),
37+
(False, True), and (False, False). With 16 channels for each
38+
source, each combination of flags occurs 4 times. Only the
4239
first combination (True, True) causes data to be recorded to
4340
disk. Therefore, we expect the following channels to be loaded by
4441
Neo: FP01, FP05, FP09, FP13, SPK01, SPK05, SPK09, and SPK13.
45-
42+
4643
Note: the file contains event (EVT) data as well. Although event
4744
channel headers do contain m_ChannelEnabled and m_ChannelRecording-
4845
Enabled flags, the UI for recording PL2 files does not expose any
49-
controls by which these flags can be changed from (True, True).
46+
controls by which these flags can be changed from (True, True).
5047
Therefore, no test for event channels is necessary here.
5148
"""
5249

@@ -58,13 +55,14 @@ def test_check_enabled_flags(self):
5855

5956
# Check that the names of the loaded signal channels match what we expect
6057
signal_channel_names = reader.header["signal_channels"]["name"].tolist()
61-
expected_signal_channel_names = ["FP01","FP05","FP09","FP13"]
58+
expected_signal_channel_names = ["FP01", "FP05", "FP09", "FP13"]
6259
assert_equal(signal_channel_names, expected_signal_channel_names)
6360

6461
# Check that the names of the loaded spike channels match what we expect
6562
spike_channel_names = reader.header["spike_channels"]["name"].tolist()
6663
expected_spike_channel_names = ["SPK01.0", "SPK05.0", "SPK09.0", "SPK13.0"]
6764
assert_equal(spike_channel_names, expected_spike_channel_names)
6865

66+
6967
if __name__ == "__main__":
7068
unittest.main()

0 commit comments

Comments
 (0)