def _run_model(model, dbspl, cf, model_pars): duration = 100e-3 onset = 10e-3 fs = model_pars.setdefault('fs', 100e3) model_pars.setdefault('anf_num', (250,250,250)) model_pars.setdefault('seed', 0) sound = wv.ramped_tone( fs=fs, freq=cf, duration=duration, pad=0, dbspl=dbspl ) anf = model( sound=sound, cf=cf, **model_pars ) ### We want to make sure the the output CF is equal to the desired ### CF. real_cf, = np.unique(anf['cf']) assert real_cf == cf hsr = anf[anf['type']=='hsr'] hsr = th.trim(hsr, onset, None) si_hsr = th.vector_strength(hsr, cf) msr = anf[anf['type']=='msr'] msr = th.trim(msr, onset, None) si_msr = th.vector_strength(msr, cf) lsr = anf[anf['type']=='lsr'] lsr = th.trim(lsr, onset, None) si_lsr = th.vector_strength(lsr, cf) # print(si_hsr) # th.plot_raster(anf) # th.show() vss = { 'hsr': si_hsr, 'msr': si_msr, 'lsr': si_lsr, } return vss
def _run_model(model, dbspl, cf, model_pars): duration = 100e-3 onset = 10e-3 fs = model_pars.setdefault('fs', 100e3) model_pars.setdefault('anf_num', (250, 250, 250)) model_pars.setdefault('seed', 0) sound = wv.ramped_tone(fs=fs, freq=cf, duration=duration, pad=0, dbspl=dbspl) anf = model(sound=sound, cf=cf, **model_pars) # th.plot_raster(anf) # th.show() # We want to make sure the the output CF is equal to the desired # CF. real_cf, = np.unique(anf['cf']) assert real_cf == cf vss = {} for typ, group in anf.groupby('type'): trimmed = th.trim(group, onset, None) vs = th.vector_strength(trimmed, cf) vss[typ] = vs return vss
def _run_model(model, fm, cf, dbspl, model_pars, m): duration = 0.6 onset = 10e-3 fs = model_pars.setdefault('fs', 100e3) model_pars.setdefault('anf_num', (250, 0, 0)) model_pars.setdefault('seed', 0) sound = wv.amplitude_modulated_tone( fs=fs, fm=fm, fc=cf, m=m, duration=duration, dbspl=dbspl, ) anf = model(sound=sound, cf=cf, **model_pars) trimmed = th.trim(anf, onset) vs = th.vector_strength(trimmed, fm) gain = 20 * np.log10(2 * vs / m) return gain
def _run_model(model, fm, cf, dbspl, model_pars, m): duration = 0.6 onset = 10e-3 fs = model_pars.setdefault('fs', 100e3) model_pars.setdefault('anf_num', (250, 0, 0)) model_pars.setdefault('seed', 0) sound = wv.amplitude_modulated_tone( fs=fs, fm=fm, fc=cf, m=m, duration=duration, dbspl=dbspl, ) anf = model( sound=sound, cf=cf, **model_pars ) trimmed = th.trim(anf, onset) vs = th.vector_strength(trimmed, fm) gain = 20 * np.log10(2*vs / m) return gain
def main(): ### Load spike trains spike_trains = load_anf_zilany2014() print(spike_trains.head()) ### Calculate vector strength cf, = spike_trains.cf.unique() onset = 10e-3 # ms trimmed = th.trim(spike_trains, onset, None) vs = th.vector_strength(trimmed, freq=cf) print() print("Vector strength: {}".format(vs)) ### Plot raster plot th.plot_raster(spike_trains) ### Show the plot th.show() # Equivalent to plt.show()
def test_vector_strength(): ### Uniform spikes trains = th.make_trains( [np.arange(0, 1, 1/3600)] ) si = th.vector_strength( trains, freq=10 ) assert_almost_equal(si, 0) ### Perfect synchrony trains = th.make_trains( [np.zeros(100)], duration=0.1 ) si = th.vector_strength( trains, freq=10 ) assert_equal(si, 1) ### Carefully chosen trains = th.make_trains( [np.tile([0, 0.25], 10)] ) si = th.vector_strength( trains, freq=1 ) assert_equal(si, np.sqrt(2)/2)
def _run_model(model, dbspl, cf, model_pars): duration = 100e-3 onset = 10e-3 fs = model_pars.setdefault('fs', 100e3) model_pars.setdefault('anf_num', (250,250,250)) model_pars.setdefault('seed', 0) sound = wv.ramped_tone( fs=fs, freq=cf, duration=duration, pad=0, dbspl=dbspl ) anf = model( sound=sound, cf=cf, **model_pars ) # th.plot_raster(anf) # th.show() ### We want to make sure the the output CF is equal to the desired ### CF. real_cf, = np.unique(anf['cf']) assert real_cf == cf vss = {} for typ,group in anf.groupby('type'): trimmed = th.trim(group, onset, None) vs = th.vector_strength(trimmed, cf) vss[typ] = vs return vss
def main(): # Load spike trains spike_trains = load_anf_zilany2014() print(spike_trains.head()) # Calculate vector strength cf, = spike_trains.cf.unique() onset = 10e-3 trimmed = th.trim(spike_trains, onset, None) vs = th.vector_strength(trimmed, freq=cf) print() print("Vector strength: {}".format(vs)) # Plot raster plot th.plot_raster(spike_trains) # Show the plot th.show() # Equivalent to plt.show()