示例#1
0
 def test_write_clusters(self):
     io = ExdirIO(self.fname)
     ex = io._processing.require_group('electrophysiology')
     ex = ex.require_group('elgroup')
     io.write_clusters([sptr for sptr in self.blk.segments[0].spiketrains],
                       ex.name,
                       test_key=4)
     assert ex['Clustering'].attrs['test_key'] == 4
示例#2
0
 def test_write_epoch(self):
     io = ExdirIO(self.fname)
     epo = self.blk.segments[0].epochs[0]
     io.write_epoch(epo, io._epochs.name, 'epo1')
     io.write_epoch(epo, io._epochs.name, 'epo2')
     np.testing.assert_array_equal(io._epochs['epo1']['timestamps'].data,
                                   epo.times)
     np.testing.assert_array_equal(io._epochs['epo1']['durations'].data,
                                   epo.durations)
     np.testing.assert_array_equal(io._epochs['epo1']['data'].data,
                                   epo.labels)
示例#3
0
 def test_write_event_waveform(self):
     io = ExdirIO(self.fname)
     ex = io._processing.require_group('electrophysiology')
     ex = ex.require_group('elgroup')
     sptrs = [sptr for sptr in self.blk.segments[0].spiketrains]
     io.write_event_waveform(sptrs, ex.name, test_key=4)
     wfgroup = ex['EventWaveform']['waveform_timeseries']
     assert wfgroup.attrs['test_key'] == 4
     assert wfgroup['data'].data.shape == (
         3 * self.n_spikes, self.n_channels,
         self.n_samples), wfgroup['data'].data.shape
示例#4
0
 def test_write_analogsignal(self):
     io = ExdirIO(self.fname)
     ex = io._processing.require_group('electrophysiology')
     ex = ex.require_group('elgroup')
     ana = self.blk.segments[0].analogsignals[0]
     io.write_analogsignal(ana, ex.name, 'timeseries')
     ana_group = ex[ana.description]['timeseries']
     np.testing.assert_array_equal(ana_group['data'].data, ana.magnitude)
     np.testing.assert_equal(ana_group.attrs['start_time'], ana.t_start)
     np.testing.assert_equal(ana_group.attrs['stop_time'], ana.t_stop)
     np.testing.assert_equal(ana_group.attrs['sample_rate'],
                             ana.sampling_rate)
示例#5
0
 def test_write_spiketimes(self):
     io = ExdirIO(self.fname)
     ex = io._processing.require_group('electrophysiology')
     ex = ex.require_group('elgroup').require_group('UnitTimes')
     ex = ex.require_group('0')
     sptr = self.blk.segments[0].spiketrains[0]
     io.write_spiketimes(sptr, ex.name, test_key=4)
     assert ex['times'].attrs['test_key'] == 4
     assert ex['times'].attrs['name'] == sptr.name
     assert ex['times'].attrs['description'] == sptr.description
     assert ex['times'].attrs['start_time'] == sptr.t_start
     assert ex['times'].attrs['stop_time'] == sptr.t_stop
示例#6
0
    def test_write_block(self):
        io = ExdirIO(self.fname)
        io.write_block(self.blk, elphys_directory_name='elphys')
        elphys = io._processing['elphys']
        chxs = {
            tuple(chx.channel_ids): chx
            for chx in self.blk.channel_indexes
        }
        save_chxs = {
            tuple(chgrp.attrs['electrode_identities']): chgrp
            for chgrp in elphys.values()
        }
        np.testing.assert_equal(len(chxs), len(save_chxs))
        for key, chx in chxs.items():
            ex = save_chxs[key]
            for ana in chx.analogsignals:
                ana_group = ex[ana.description]['timeseries']
                np.testing.assert_array_equal(ana_group['data'].data,
                                              ana.magnitude)
                np.testing.assert_equal(ana_group.attrs['start_time'],
                                        ana.t_start)
                np.testing.assert_equal(ana_group.attrs['stop_time'],
                                        ana.t_stop)
                np.testing.assert_equal(ana_group.attrs['sample_rate'],
                                        ana.sampling_rate)

            unit_times_group = ex['UnitTimes']
            unit_dict = {unit.name: unit.spiketrains[0] for unit in chx.units}
            for unit in chx.units:
                for unit_group in unit_times_group.values():
                    name = unit_group.attrs['name']
                    np.testing.assert_array_equal(unit_dict[name].times,
                                                  unit_group['times'].data)
                    sptr = unit_dict[name]
                    assert unit_group['times'].attrs['name'] == sptr.name
                    assert unit_group['times'].attrs[
                        'description'] == sptr.description
                    assert unit_group['times'].attrs[
                        'start_time'] == sptr.t_start
                    assert unit_group['times'].attrs[
                        'stop_time'] == sptr.t_stop
            sptrs = [sptr for sptr in unit_dict.values()]
            wfgroup = ex['EventWaveform']['waveform_timeseries']
            assert wfgroup['data'].data.shape == (
                len(sptrs) * self.n_spikes, self.n_channels,
                self.n_samples), wfgroup['data'].data.shape
示例#7
0
 def test_write_read_block_ana_equal(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     exdir_dir = exdir.File(self.fname)
     lfp_group = exdir_dir['/processing/electrophysiology/channel_group_0']
     ana = self.blk.segments[0].analogsignals[0]
     io.write_analogsignal(ana, lfp_group.name)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     anas = {ana.name: ana for ana in self.blk.segments[0].analogsignals}
     anas_load = {ana.name: ana for ana in blk.segments[0].analogsignals}
     for key in anas.keys():
         np.testing.assert_array_equal(anas[key], anas_load[key])
         np.testing.assert_equal(anas[key].name, anas_load[key].name)
示例#8
0
 def test_write_read_block_chxs_equal(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     np.testing.assert_equal(len(self.blk.channel_indexes),
                             len(blk.channel_indexes))
示例#9
0
 def test_write_read_block(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     np.testing.assert_equal(len(blk.segments[0].spiketrains),
                             len(self.blk.segments[0].spiketrains))
示例#10
0
 def test_write_unit_times(self):
     io = ExdirIO(self.fname)
     ex = io._processing.require_group('electrophysiology')
     ex = ex.require_group('elgroup')
     units = [
         unit for chx in self.blk.channel_indexes for unit in chx.units
     ]
     unit_dict = {unit.name: unit.spiketrains[0] for unit in units}
     io.write_unit_times(units, ex.name, test_key=4)
     unit_times_group = ex['UnitTimes']
     assert unit_times_group.attrs['test_key'] == 4
     for unit_group in unit_times_group.values():
         name = unit_group.attrs['name']
         np.testing.assert_array_equal(unit_dict[name].times,
                                       unit_group['times'].data)
         sptr = unit_dict[name]
         assert unit_group['times'].attrs['name'] == sptr.name
         assert unit_group['times'].attrs['description'] == sptr.description
         assert unit_group['times'].attrs['start_time'] == sptr.t_start
         assert unit_group['times'].attrs['stop_time'] == sptr.t_stop
示例#11
0
 def test_write_read_block_epo_equal(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     epos = {epo.name: epo for epo in self.blk.segments[0].epochs}
     epos_load = {epo.name: epo for epo in blk.segments[0].epochs}
     for key in epos.keys():
         np.testing.assert_array_equal(epos[key], epos_load[key])
         np.testing.assert_array_equal(epos[key].durations,
                                       epos_load[key].durations)
         np.testing.assert_equal(epos[key].name, epos_load[key].name)
示例#12
0
 def test_write_read_block_units_equal(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     units = {unit.name: unit for unit in self.blk.channel_indexes[0].units}
     units_load = {unit.name: unit for unit in blk.channel_indexes[0].units}
     for key in units.keys():
         np.testing.assert_equal(len(units[key].spiketrains[0]),
                                 len(units_load[key].spiketrains[0]))
         sptr = units[key].spiketrains[0]
         sptr_load = units_load[key].spiketrains[0]
         np.testing.assert_array_equal(sptr, sptr_load)
         np.testing.assert_equal(units[key].name, units_load[key].name)
示例#13
0
 def test_write_read_block_sptr_equal(self):
     io = ExdirIO(self.fname)
     io.write_block(self.blk)
     io = ExdirIO(self.fname)
     blk = io.read_block()
     sptrs = {
         sptr.annotations['id']: sptr
         for sptr in self.blk.segments[0].spiketrains
     }
     sptrs_load = {
         sptr.annotations['id']: sptr
         for sptr in blk.segments[0].spiketrains
     }
     for key in sptrs.keys():
         np.testing.assert_array_equal(sptrs[key], sptrs_load[key])
         np.testing.assert_equal(sptrs[key].name, sptrs_load[key].name)
         np.testing.assert_equal(sptrs[key].description,
                                 sptrs_load[key].description)
         for k, v in sptrs[key].annotations.items():
             if k == 'description' or k == 'name':
                 continue
             np.testing.assert_equal(v, sptrs_load[key].annotations[k])
         np.testing.assert_array_equal(sptrs[key].channel_index.index,
                                       sptrs_load[key].channel_index.index)