def test_inputs_V21(self): """ Test various inputs to BlackrockIO.read_block with version 2.3 file to check for parsing errors. """ filename = self.get_local_path('blackrock/blackrock_2_1/l101210-001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load=5) # Assert IOError is raised when no Blackrock files are available with self.assertRaises(IOError): reader2 = BlackrockIO(filename='nonexistent') # with self.assertRaises(IOError): # reader2 = BlackrockIO(filename=filename, nev_override='nonexistent') # Load data to maximum extent, one None is not given as list block = reader.read_block(load_waveforms=False, signal_group_mode='split-all') lena = len(block.segments[0].analogsignals[0]) numspa = len(block.segments[0].spiketrains[0]) # Load data using a negative time and a time exceeding the end of the # recording too_large_tstop = block.segments[0].analogsignals[0].t_stop + 1 * pq.s buggy_slice = (-100 * pq.ms, too_large_tstop) # This is valid in read_segment seg = reader.read_segment(seg_index=0, time_slice=buggy_slice, strict_slicing=False) # this raise error with self.assertRaises(AssertionError): seg = reader.read_segment(seg_index=0, time_slice=buggy_slice, strict_slicing=True) lenb = len(seg.analogsignals[0]) numspb = len(seg.spiketrains[0]) # Same length of analog signal? # Both should have read the complete data set! self.assertEqual(lena, lenb) # Same length of spike train? # Both should have read the complete data set! self.assertEqual(numspa, numspb) # test 4 Units block = reader.read_block( load_waveforms=True, signal_group_mode='split-all', ) #units_group_mode='all-in-one') self.assertEqual(len(block.segments[0].analogsignals), 96) #self.assertEqual(len(block.channel_indexes[-1].units), 218) #self.assertEqual(len(block.channel_indexes[-1].units), # len(block.segments[0].spiketrains)) anasig = block.segments[0].analogsignals[0] self.assertIsNotNone(anasig.file_origin)
def test_inputs_V21(self): """ Test various inputs to BlackrockIO.read_block with version 2.3 file to check for parsing errors. """ filename = self.get_filename_path('blackrock_2_1/l101210-001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load=5) # Assert IOError is raised when no Blackrock files are available with self.assertRaises(IOError): reader2 = BlackrockIO(filename='nonexistent') # with self.assertRaises(IOError): # reader2 = BlackrockIO(filename=filename, nev_override='nonexistent') # Load data to maximum extent, one None is not given as list block = reader.read_block(load_waveforms=False, signal_group_mode='split-all') lena = len(block.segments[0].analogsignals[0]) numspa = len(block.segments[0].spiketrains[0]) # Load data using a negative time and a time exceeding the end of the # recording too_large_tstop = block.segments[0].analogsignals[0].t_stop + 1 * pq.s buggy_slice = (-100 * pq.ms, too_large_tstop) # This is valid in read_segment seg = reader.read_segment(seg_index=0, time_slice=buggy_slice, strict_slicing=False) # this raise error with self.assertRaises(AssertionError): seg = reader.read_segment(seg_index=0, time_slice=buggy_slice, strict_slicing=True) lenb = len(seg.analogsignals[0]) numspb = len(seg.spiketrains[0]) # Same length of analog signal? # Both should have read the complete data set! self.assertEqual(lena, lenb) # Same length of spike train? # Both should have read the complete data set! self.assertEqual(numspa, numspb) # test 4 Units block = reader.read_block(load_waveforms=True, signal_group_mode='split-all', units_group_mode='all-in-one') self.assertEqual(len(block.segments[0].analogsignals), 96) self.assertEqual(len(block.channel_indexes[-1].units), 218) self.assertEqual(len(block.channel_indexes[-1].units), len(block.segments[0].spiketrains)) anasig = block.segments[0].analogsignals[0] self.assertIsNotNone(anasig.file_origin)
def test_inputs_V23(self): """ Test various inputs to BlackrockIO.read_block with version 2.3 file to check for parsing errors. """ filename = self.get_filename_path('FileSpec2.3001') reader = BlackrockIO( filename=filename, verbose=False, nsx_to_load=5, ) # Load data to maximum extent, one None is not given as list block = reader.read_block(load_waveforms=False) lena = len(block.segments[0].analogsignals[0]) numspa = len(block.segments[0].spiketrains[0]) # Load data using a negative time and a time exceeding the end of the # recording too_large_tstop = block.segments[0].analogsignals[0].t_stop + 1 * pq.s buggy_slice = (-100 * pq.ms, too_large_tstop) # this is valid in read_segment because seg_index is specified seg = reader.read_segment(seg_index=0, time_slice=buggy_slice) lenb = len(seg.analogsignals[0]) numspb = len(seg.spiketrains[0]) # Same length of analog signal? # Both should have read the complete data set! self.assertEqual(lena, lenb) # Same length of spike train? # Both should have read the complete data set! self.assertEqual(numspa, numspb) # test 4 Units block = reader.read_block(load_waveforms=True, units_group_mode='all-in-one') self.assertEqual(len(block.segments[0].analogsignals), 10) self.assertEqual(len(block.channel_indexes[-1].units), 4) self.assertEqual(len(block.channel_indexes[-1].units), len(block.segments[0].spiketrains)) anasig = block.segments[0].analogsignals[0] self.assertIsNotNone(anasig.file_origin)
def test_load_muliple_nsx(self): """ Test if multiple nsx signals can be loaded at the same time. """ filename = self.get_filename_path('blackrock_2_1/l101210-001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load='all') # number of different sampling rates corresponds to number of nsx signals, because # single nsx contains only signals of identical sampling rate block = reader.read_block(load_waveforms=False) sampling_rates = np.unique([ a.sampling_rate.rescale('Hz') for a in block.filter(objects='AnalogSignal') ]) self.assertEqual(len(sampling_rates), 2) segment = reader.read_segment() sampling_rates = np.unique([ a.sampling_rate.rescale('Hz') for a in segment.filter(objects='AnalogSignal') ]) self.assertEqual(len(sampling_rates), 2) # load only ns5 reader = BlackrockIO(filename=filename, nsx_to_load=5) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (109224, 96)) # load only ns2 reader = BlackrockIO(filename=filename, nsx_to_load=2) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (3640, 6)) # load only ns2 reader = BlackrockIO(filename=filename, nsx_to_load=[2]) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) # load ns2 + ns5 reader = BlackrockIO(filename=filename, nsx_to_load=[2, 5]) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 2) self.assertEqual(seg.analogsignals[0].shape, (3640, 6)) self.assertEqual(seg.analogsignals[1].shape, (109224, 96)) # load only ns5 reader = BlackrockIO(filename=filename, nsx_to_load='max') seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (109224, 96))
def test_load_muliple_nsx(self): """ Test if multiple nsx signals can be loaded at the same time. """ filename = self.get_filename_path('blackrock_2_1/l101210-001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load='all') # number of different sampling rates corresponds to number of nsx signals, because # single nsx contains only signals of identical sampling rate block = reader.read_block(load_waveforms=False) sampling_rates = np.unique( [a.sampling_rate.rescale('Hz') for a in block.filter(objects='AnalogSignal')]) self.assertEqual(len(sampling_rates), len(reader._selected_nsx)) segment = reader.read_segment() sampling_rates = np.unique( [a.sampling_rate.rescale('Hz') for a in segment.filter(objects='AnalogSignal')]) self.assertEqual(len(sampling_rates), len(reader._selected_nsx))
def test_load_muliple_nsx(self): """ Test if multiple nsx signals can be loaded at the same time. """ filename = self.get_filename_path('blackrock_2_1/l101210-001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load='all') # number of different sampling rates corresponds to number of nsx signals, because # single nsx contains only signals of identical sampling rate block = reader.read_block(load_waveforms=False) sampling_rates = np.unique( [a.sampling_rate.rescale('Hz') for a in block.filter(objects='AnalogSignal')]) self.assertEqual(len(sampling_rates), 2) segment = reader.read_segment() sampling_rates = np.unique( [a.sampling_rate.rescale('Hz') for a in segment.filter(objects='AnalogSignal')]) self.assertEqual(len(sampling_rates), 2) # load only ns5 reader = BlackrockIO(filename=filename, nsx_to_load=5) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (109224, 96)) # load only ns2 reader = BlackrockIO(filename=filename, nsx_to_load=2) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (3640, 6)) # load only ns2 reader = BlackrockIO(filename=filename, nsx_to_load=[2]) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) # load ns2 + ns5 reader = BlackrockIO(filename=filename, nsx_to_load=[2, 5]) seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 2) self.assertEqual(seg.analogsignals[0].shape, (3640, 6)) self.assertEqual(seg.analogsignals[1].shape, (109224, 96)) # load only ns5 reader = BlackrockIO(filename=filename, nsx_to_load='max') seg = reader.read_segment() self.assertEqual(len(seg.analogsignals), 1) self.assertEqual(seg.analogsignals[0].shape, (109224, 96))
def test_inputs_V23(self): """ Test various inputs to BlackrockIO.read_block with version 2.3 file to check for parsing errors. """ filename = self.get_filename_path('FileSpec2.3001') reader = BlackrockIO( filename=filename, verbose=False, nsx_to_load=5, ) # Load data to maximum extent, one None is not given as list block = reader.read_block(time_slices=None, load_waveforms=False) lena = len(block.segments[0].analogsignals[0]) numspa = len(block.segments[0].spiketrains[0]) # Load data using a negative time and a time exceeding the end of the # recording raise an error too_large_tstop = block.segments[0].analogsignals[0].t_stop + 1 * pq.s buggy_slice = (-100 * pq.ms, too_large_tstop) #this raise error in read_block with self.assertRaises(ValueError): block = reader.read_block(time_slices=[buggy_slice]) #but this is valid in read_segment because seg_index is specified seg = reader.read_segment(seg_index=0, time_slice=buggy_slice) lenb = len(seg.analogsignals[0]) numspb = len(seg.spiketrains[0]) # Same length of analog signal? # Both should have read the complete data set! self.assertEqual(lena, lenb) # Same length of spike train? # Both should have read the complete data set! self.assertEqual(numspa, numspb) # n_starts and n_stops not given as list # verifies identical length of returned signals given equal durations # as input ns5_unit = block.segments[0].analogsignals[0].sampling_period time_slice = (100 * ns5_unit, 200 * ns5_unit) block = reader.read_block(time_slices=[time_slice]) lena = len(block.segments[0].analogsignals[0]) time_slice = (100 * ns5_unit, 200 * ns5_unit) block = reader.read_block(time_slices=[time_slice]) lenb = len(block.segments[0].analogsignals[0]) # Same length? self.assertEqual(lena, lenb) # Length should be 100 samples exactly self.assertEqual(lena, 100) # test 4 Units time_slices = [(0, 1000 * pq.ms), (3000 * pq.ms, 4000 * pq.ms)] block = reader.read_block(time_slices=time_slices, load_waveforms=True, units_group_mode='all-in-one') self.assertEqual(len(block.segments), 2) self.assertEqual(len(block.segments[0].analogsignals), 10) self.assertEqual(len(block.channel_indexes[-1].units), 4) self.assertEqual(len(block.channel_indexes[-1].units), len(block.segments[0].spiketrains)) anasig = block.segments[0].analogsignals[0] self.assertIsNotNone(anasig.file_origin)
def test_inputs_V23(self): """ Test various inputs to BlackrockIO.read_block with version 2.3 file to check for parsing errors. """ filename = self.get_filename_path('FileSpec2.3001') reader = BlackrockIO(filename=filename, verbose=False, nsx_to_load=5,) # Load data to maximum extent, one None is not given as list block = reader.read_block(time_slices=None, load_waveforms=False) lena = len(block.segments[0].analogsignals[0]) numspa = len(block.segments[0].spiketrains[0]) # Load data using a negative time and a time exceeding the end of the # recording raise an error too_large_tstop = block.segments[0].analogsignals[0].t_stop + 1 * pq.s buggy_slice = (-100 * pq.ms, too_large_tstop) #this raise error in read_block with self.assertRaises(ValueError): block = reader.read_block(time_slices=[buggy_slice]) #but this is valid in read_segment because seg_index is specified seg = reader.read_segment(seg_index=0, time_slice=buggy_slice) lenb = len(seg.analogsignals[0]) numspb = len(seg.spiketrains[0]) # Same length of analog signal? # Both should have read the complete data set! self.assertEqual(lena, lenb) # Same length of spike train? # Both should have read the complete data set! self.assertEqual(numspa, numspb) # n_starts and n_stops not given as list # verifies identical length of returned signals given equal durations # as input ns5_unit = block.segments[0].analogsignals[0].sampling_period time_slice = (100 * ns5_unit, 200 * ns5_unit) block = reader.read_block(time_slices=[time_slice]) lena = len(block.segments[0].analogsignals[0]) time_slice = (100 * ns5_unit, 200 * ns5_unit) block = reader.read_block(time_slices=[time_slice]) lenb = len(block.segments[0].analogsignals[0]) # Same length? self.assertEqual(lena, lenb) # Length should be 100 samples exactly self.assertEqual(lena, 100) # test 4 Units time_slices=[(0, 1000*pq.ms), (3000*pq.ms, 4000*pq.ms)] block = reader.read_block(time_slices=time_slices, load_waveforms=True, units_group_mode='all-in-one') self.assertEqual(len(block.segments), 2) self.assertEqual(len(block.segments[0].analogsignals), 10) self.assertEqual(len(block.channel_indexes[-1].units), 4) self.assertEqual(len(block.channel_indexes[-1].units), len(block.segments[0].spiketrains)) anasig = block.segments[0].analogsignals[0] self.assertIsNotNone(anasig.file_origin)