def test1():
    bl = generate_block_for_sorting(nb_unit = 6,
                                                        duration = 10.*pq.s,
                                                        noise_ratio = 0.7,
                                                        nb_segment = 2,
                                                        )
    rcg = bl.recordingchannelgroups[0]

    spikesorter = SpikeSorter(rcg)

    spikesorter.ButterworthFilter( f_low = 200.)
    spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 3.5,noise_estimation = 'MAD', threshold_mode = 'peak', peak_span = 0.4*pq.ms)
    spikesorter.AlignWaveformOnPeak(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, sign = '-', peak_method = 'biggest_amplitude')
    spikesorter.PcaFeature(n_components = 4)
    spikesorter.SklearnGaussianMixtureEm(n_cluster = 5)
    
    

    
    spikesorter.check_display_attributes()
    from OpenElectrophy.gui.spikesorting import FilteredBandSignal, AverageWaveforms
    app = QApplication([ ])
    w1 = AverageWaveforms(spikesorter = spikesorter)
    w1.refresh()
    w1.show()
    
    w2 = FilteredBandSignal(spikesorter = spikesorter)
    w2.refresh()
    w2.show()
    app.exec_()
def test1():
    bl = generate_block_for_sorting(
        nb_unit=6,
        duration=10. * pq.s,
        noise_ratio=0.2,
        nb_segment=2,
    )
    rcg = bl.recordingchannelgroups[0]

    spikesorter = SpikeSorter(rcg)

    #~ spikesorter.ButterworthFilter( f_low = 200.)
    #~ spikesorter.DerivativeFilter()
    spikesorter.SlidingMedianFilter(window_size=50. * pq.ms,
                                    sliding_step=25. * pq.ms,
                                    interpolation='spline')

    spikesorter.RelativeThresholdDetection(sign='-',
                                           relative_thresh=4.,
                                           noise_estimation='MAD',
                                           threshold_mode='peak',
                                           peak_span=0.5 * pq.ms)

    print spikesorter

    spikesorter.check_display_attributes()

    from OpenElectrophy.gui.spikesorting import FilteredBandSignal

    app = QApplication([])
    w1 = FilteredBandSignal(spikesorter=spikesorter)
    w1.refresh()
    w1.show()
    app.exec_()
Example #3
0
def test1():
    bl = generate_block_for_sorting(
        nb_unit=6,
        duration=10. * pq.s,
        noise_ratio=0.2,
        nb_segment=2,
    )
    rcg = bl.recordingchannelgroups[0]

    spikesorter = SpikeSorter(rcg)

    spikesorter.ButterworthFilter(f_low=200.)
    spikesorter.RelativeThresholdDetection(sign='-',
                                           relative_thresh=4.,
                                           noise_estimation='MAD',
                                           threshold_mode='crossing')
    #~ spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 4.,noise_estimation = 'MAD', threshold_mode = 'peak')

    spikesorter.AlignWaveformOnDetection(left_sweep=1 * pq.ms,
                                         right_sweep=2 * pq.ms,
                                         sign='-')
    #~ spikesorter.AlignWaveformOnPeak(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, sign = '-', peak_method = 'biggest_amplitude')
    #~ spikesorter.AlignWaveformOnPeak(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, sign = '-', peak_method = 'closer')
    #~ spikesorter.AlignWaveformOnCentralWaveform(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, )

    #~ print spikesorter.spike_waveforms.shape
    #~ s0 = spikesorter.spike_waveforms.shape[0]
    #~ wf2 = spikesorter.spike_waveforms.reshape(s0, -1)
    #~ from matplotlib import pyplot
    #~ pyplot.plot(wf2[:-10, :].transpose())
    #~ pyplot.show()

    print spikesorter

    spikesorter.check_display_attributes()
    from OpenElectrophy.gui.spikesorting import AverageWaveforms, AllWaveforms

    app = QApplication([])
    w1 = AverageWaveforms(spikesorter=spikesorter)
    w1.refresh()
    w1.show()
    w2 = AllWaveforms(spikesorter=spikesorter)
    w2.refresh()
    w2.show()
    app.exec_()
def test1():
    bl = generate_block_for_sorting(
        nb_unit=6,
        duration=10. * pq.s,
        noise_ratio=0.2,
        nb_segment=2,
    )
    rcg = bl.recordingchannelgroups[0]

    spikesorter = SpikeSorter(rcg)

    spikesorter.ButterworthFilter(f_low=200.)
    #~ spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 4.,noise_estimation = 'MAD', threshold_mode = 'crossing')
    spikesorter.RelativeThresholdDetection(sign='-',
                                           relative_thresh=4.,
                                           noise_estimation='MAD',
                                           threshold_mode='peak')

    spikesorter.AlignWaveformOnDetection(left_sweep=1.5 * pq.ms,
                                         right_sweep=2.5 * pq.ms,
                                         sign='-')
    spikesorter.PcaFeature(n_components=4)
    spikesorter.SklearnKMeans(n_cluster=3)

    #~ spikesorter.AlignWaveformOnPeak(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, sign = '-', peak_method = 'biggest_amplitude')
    #~ spikesorter.AlignWaveformOnPeak(left_sweep = 1*pq.ms , right_sweep = 2*pq.ms, sign = '-', peak_method = 'closer')
    spikesorter.AlignWaveformOnCentralWaveform(
        left_sweep=1 * pq.ms,
        right_sweep=2 * pq.ms,
        shift_estimation_method='taylor order1',
        #~ shift_estimation_method = 'taylor order2',
        #~ shift_estimation_method ='optimize',
        #~ shift_method = 'spline',
        shift_method='sinc',
        max_iter=3)

    step = spikesorter.history[-1]
    instance = step['methodInstance']

    fig = pyplot.figure()
    instance.plot_iterative_centers(fig, spikesorter)

    pyplot.show()
Example #5
0
def test1():
    bl = generate_block_for_sorting(
        nb_unit=6,
        duration=10. * pq.s,
        noise_ratio=0.7,
        nb_segment=2,
    )
    rcg = bl.recordingchannelgroups[0]

    spikesorter = SpikeSorter(rcg)

    spikesorter.ButterworthFilter(f_low=200.)
    #~ spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 3.5,noise_estimation = 'MAD', threshold_mode = 'crossing',
    #~ consistent_across_channels = False,
    #~ consistent_across_segments = True,
    #~ )
    #~ print spikesorter
    spikesorter.RelativeThresholdDetection(sign='-',
                                           relative_thresh=3.5,
                                           noise_estimation='MAD',
                                           threshold_mode='peak',
                                           peak_span=0.53 * pq.ms)
    print spikesorter.detection_thresholds
    print spikesorter
    #~ spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 3.5,noise_estimation = 'STD', threshold_mode = 'crossing', )
    #~ print spikesorter
    #~ spikesorter.RelativeThresholdDetection(sign= '-', relative_thresh = 3.5,noise_estimation = 'STD', threshold_mode = 'peak', peak_span = 0.3*pq.ms )
    #~ print spikesorter
    spikesorter.populate_recordingchannelgroup(with_waveforms=False)

    spikesorter.check_display_attributes()
    from OpenElectrophy.gui.spikesorting import FilteredBandSignal
    app = QApplication([])
    w2 = FilteredBandSignal(spikesorter=spikesorter)
    w2.refresh()
    w2.show()
    app.exec_()
Example #6
0
def test1():
    # open DB and create new column
    url = 'sqlite:///test_spikesorter.sqlite'
    dbinfo = open_db(
        url=url,
        use_global_session=True,
        myglobals=globals(),
    )
    session = dbinfo.Session()

    for attrname, attrtype in dbinfo.classes_by_name[
            'SpikeTrain'].usable_attributes.items():
        print attrname, attrtype

    #Create acolumn on table SpikeTrain (maybe this could be store at Unit level)
    create_column_if_not_exists(dbinfo.metadata.tables['SpikeTrain'],
                                'detection_thresholds', np.ndarray)

    #test is creation is OK
    for attrname, attrtype in dbinfo.classes_by_name[
            'SpikeTrain'].usable_attributes.items():
        print attrname, attrtype

    # re open DB for sorting
    url = 'sqlite:///test_spikesorter.sqlite'
    dbinfo = open_db(
        url=url,
        use_global_session=True,
        myglobals=globals(),
    )
    session = dbinfo.Session()
    print dbinfo.classes_by_name['SpikeTrain']
    for attrname, attrtype in dbinfo.classes_by_name[
            'SpikeTrain'].usable_attributes.items():
        print attrname, attrtype

    neobl = generate_block_for_sorting(
        nb_unit=6,
        duration=10. * pq.s,
        noise_ratio=0.2,
        nb_segment=2,
    )
    neorcg = neobl.recordingchannelgroups[0]
    bl = OEBase.from_neo(neobl, dbinfo.mapped_classes, cascade=True)
    bl.save()
    rcg = OEBase.from_neo(neorcg, dbinfo.mapped_classes, cascade=True)
    rcg_id = rcg.id

    # spike sorting chain
    spikesorter = SpikeSorter(neorcg)
    spikesorter.ButterworthFilter(f_low=200.)
    spikesorter.RelativeThresholdDetection(
        sign='-',
        relative_thresh=6.,
    )
    spikesorter.AlignWaveformOnPeak(left_sweep=1 * pq.ms,
                                    right_sweep=2 * pq.ms,
                                    sign='-')
    spikesorter.PcaFeature(n_components=4)
    spikesorter.CombineFeature(use_peak=True,
                               use_peak_to_valley=True,
                               n_pca=3,
                               n_ica=3,
                               n_haar=3,
                               sign='-')
    spikesorter.SklearnKMeans(n_cluster=3)
    spikesorter.save_in_database(session, dbinfo)

    # Note that threshold is per channel/segment
    for unit in rcg.units:
        for sptr in unit.spiketrains:
            print 'writte threshold on spiketrain.id', sptr.id
            print spikesorter.detection_thresholds
            sptr.detection_thresholds = spikesorter.detection_thresholds
    session.commit()

    # re open DB for sorting for reading
    dbinfo = open_db(
        url=url,
        use_global_session=True,
        myglobals=globals(),
    )
    session = dbinfo.Session()
    rcg = RecordingChannelGroup.load(rcg_id)
    for unit in rcg.units:
        for sptr in unit.spiketrains:
            print 'read threshold on spiketrain.id', sptr.id
            print sptr.detection_thresholds