Skip to content

Commit 1863d55

Browse files
committed
Sam s feedback
1 parent ac508e1 commit 1863d55

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

neo/rawio/baserawio.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,18 @@ def get_analogsignal_chunk(self, block_index=0, seg_index=0, i_start=None, i_sto
550550
np.ndarray and are contiguous
551551
:return: array with raw signal samples
552552
"""
553+
554+
signal_streams = self.header['signal_streams']
555+
signal_channels = self.header['signal_channels']
556+
no_signal_streams = signal_streams.size == 0
557+
no_channels = signal_channels.size == 0
558+
if no_signal_streams or no_channels:
559+
error_message = (
560+
"get_analogsignal_chunk can't be called on a file with no signal streams or channels."
561+
"Double check that your file contains signal streams and channels."
562+
)
563+
raise AttributeError(error_message)
564+
553565
stream_index = self._get_stream_index_from_arg(stream_index)
554566
channel_indexes = self._get_channel_indexes(stream_index, channel_indexes,
555567
channel_names, channel_ids)
@@ -579,7 +591,7 @@ def rescale_signal_raw_to_float(self, raw_signal, dtype='float32', stream_index=
579591
channel_indexes=None, channel_names=None, channel_ids=None):
580592
"""
581593
Rescale a chunk of raw signals which are provided as a Numpy array. These are normally
582-
returned by a call to get_analog_signal_chunk. The channels are specified either by
594+
returned by a call to get_analogsignal_chunk. The channels are specified either by
583595
channel_names, if provided, otherwise by channel_ids, if provided, otherwise by
584596
channel_indexes, if provided, otherwise all channels are selected.
585597

neo/rawio/mearecrawio.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,22 @@ def _parse_header(self):
8383
self._num_channels = self.channel_positions.shape[0]
8484
self._dtype = self.info_dict["recordings"]["dtype"]
8585

86-
signals = [('Signals', '0')]
86+
signals = [('Signals', '0')] if self.load_analogsignal else []
8787
signal_streams = np.array(signals, dtype=_signal_stream_dtype)
8888

8989

9090
sig_channels = []
91-
for c in range(self._num_channels):
92-
ch_name = 'ch{}'.format(c)
93-
chan_id = str(c + 1)
94-
sr = self._sampling_rate # Hz
95-
dtype = self._dtype
96-
units = 'uV'
97-
gain = 1.
98-
offset = 0.
99-
stream_id = '0'
100-
sig_channels.append((ch_name, chan_id, sr, dtype, units, gain, offset, stream_id))
91+
if self.load_analogsignal:
92+
for c in range(self._num_channels):
93+
ch_name = 'ch{}'.format(c)
94+
chan_id = str(c + 1)
95+
sr = self._sampling_rate # Hz
96+
dtype = self._dtype
97+
units = 'uV'
98+
gain = 1.
99+
offset = 0.
100+
stream_id = '0'
101+
sig_channels.append((ch_name, chan_id, sr, dtype, units, gain, offset, stream_id))
101102

102103
sig_channels = np.array(sig_channels, dtype=_signal_channel_dtype)
103104

@@ -180,16 +181,10 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop,
180181

181182
def _spike_count(self, block_index, seg_index, unit_index):
182183

183-
if not self.load_spiketrains:
184-
raise AttributeError("Spiketrains not loaded. Set load_spiketrains=True in MEArecRawIO constructor")
185-
186184
return len(self._spiketrains[unit_index])
187185

188186
def _get_spike_timestamps(self, block_index, seg_index, unit_index, t_start, t_stop):
189187

190-
if not self.load_spiketrains:
191-
raise AttributeError("Spiketrains not loaded. Set load_spiketrains=True in MEArecRawIO constructor")
192-
193188
spike_timestamps = self._spiketrains[unit_index].times.magnitude
194189
if t_start is None:
195190
t_start = self._segment_t_start(block_index, seg_index)

neo/test/rawiotest/test_mearecrawio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def test_not_loading_recordings(self):
4141
rawio.get_spike_timestamps()
4242

4343
# Test that caling anlogsignal chunk raises the right error
44-
error_message = "Recordings not loaded. Set load_analogsignal=True in MEArecRawIO constructor"
45-
with self.assertRaises(AttributeError, msg=error_message):
44+
with self.assertRaises(AttributeError):
4645
rawio.get_analogsignal_chunk()
4746

4847

@@ -60,8 +59,7 @@ def test_not_loading_spiketrain(self):
6059
rawio.get_analogsignal_chunk()
6160

6261
# Test that calling get_spike_timestamps raises an the right error
63-
error_message = "Spiketrains not loaded. Set load_spiketrains=True in MEArecRawIO constructor"
64-
with self.assertRaises(AttributeError, msg=error_message):
62+
with self.assertRaises(AttributeError):
6563
rawio.get_spike_timestamps()
6664

6765
if __name__ == "__main__":

0 commit comments

Comments
 (0)