Skip to content

Commit 3f0225c

Browse files
authored
Merge pull request #1274 from JuliaSprenger/fix/asciitests
[AsciiIO] Fix handling of handle channel index array annotations
2 parents d2179d1 + 6ee70f7 commit 3f0225c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

neo/io/asciisignalio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AsciiSignalIO(BaseIO):
3939
column delimiter in file, e.g. '\t', one space, two spaces, ',', ';'
4040
timecolumn:
4141
None or a valid integer that identifies which column contains the time vector
42-
(counting from zero)
42+
(counting from zero, within the list of selected columns, see also `usecols` argument)
4343
units:
4444
units of AnalogSignal can be a str or directly a Quantity
4545
time_units:
@@ -251,13 +251,16 @@ def read_segment(self, lazy=False):
251251
t_start = sig[0, self.timecolumn] * self.time_units
252252

253253
if self.signal_group_mode == 'all-in-one':
254+
channel_index_annotation = self.usecols or np.arange(sig.shape[1])
255+
channel_index_annotation = np.asarray(channel_index_annotation)
254256
if self.timecolumn is not None:
255257
mask = list(range(sig.shape[1]))
256258
if self.timecolumn >= 0:
257259
mask.remove(self.timecolumn)
258260
else: # allow negative column index
259261
mask.remove(sig.shape[1] + self.timecolumn)
260262
signal = sig[:, mask]
263+
channel_index_annotation = channel_index_annotation[mask]
261264
else:
262265
signal = sig
263266
if sampling_rate is None:
@@ -269,7 +272,7 @@ def read_segment(self, lazy=False):
269272
ana_sig = AnalogSignal(signal * self.units, sampling_rate=sampling_rate,
270273
t_start=t_start,
271274
name='multichannel')
272-
ana_sig.array_annotate(channel_index=self.usecols or np.arange(signal.shape[1]))
275+
ana_sig.array_annotate(channel_index=channel_index_annotation)
273276
seg.analogsignals.append(ana_sig)
274277
else:
275278
if self.timecolumn is not None and self.timecolumn < 0:

neo/test/iotest/test_asciisignalio.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def test_csv_expect_success(self):
6161
for row in sample_data:
6262
writer.writerow(row)
6363

64-
io = AsciiSignalIO(filename, usecols=(0, 1, 3), timecolumn=2,
64+
usecols = (0, 1, 3)
65+
timecolumn = 2
66+
io = AsciiSignalIO(filename, usecols=usecols, timecolumn=timecolumn,
6567
# note that timecolumn applies to the remaining columns
6668
# after applying usecols
6769
time_units="ms", delimiter=',', units="mV", method='csv',
@@ -76,6 +78,11 @@ def test_csv_expect_success(self):
7678
decimal=5)
7779
self.assertAlmostEqual(signal.sampling_period, 0.1 * pq.ms)
7880

81+
expected_channel_index = list(usecols)
82+
# remove time column as it is not loaded as signal channel
83+
expected_channel_index.pop(timecolumn)
84+
assert_array_equal(expected_channel_index, signal.array_annotations['channel_index'])
85+
7986
os.remove(filename)
8087
# test_csv_expect_failure
8188

0 commit comments

Comments
 (0)