stimulus = np.sin(2 * np.pi * frequency * t) * (1 + contrast * np.sin(2 * np.pi * contrastf * t)) #kernel parameters kernelparams = {'sigma': 0.001, 'lenfactor': 8, 'resolution': t_delta} #create kernel kernel, kerneltime = helpers.spike_gauss_kernel(**kernelparams) convolvedspklist = np.zeros([t.shape[0], ntrials]) #initialized list of convolved spikes spiketrains = np.zeros([t.shape[0], ntrials]) #initialized list of spike trains for i in range(ntrials): #run the model for the given stimulus and get spike times spiketimes, spikeISI, meanspkfr = helpers.stimulus_ISI_calculator( cellparams, stimulus, tlength=tlength) convolvedspikes, spikearray = helpers.convolved_spikes( spiketimes, stimulus, t, kernel) convolvedspklist[:, i] = convolvedspikes spiketrains[:, i] = spikearray peristimulustimehist = np.mean(convolvedspklist, axis=1) fig, (axp, axr, axs) = plt.subplots(3, 1, sharex=True) axp.plot(t[t > 0.1] * 1000, peristimulustimehist[t > 0.1]) axp.set_title('Peristimulus time histogram') axp.set_ylabel('Spiking frequency [Hz]') axr.plot(t[t > 0.1] * 1000,
print("File exists and is readable") continue #Amplitude modulation baselinefs, initialfs, steadyfs = helpers.amplitude_modulation( cellparams, EODf, **ampmodinputs) #Histogram frequency = EODf #Electric organ discharge frequency in Hz, used for stimulus t_delta = cellparams["deltat"] #time step in seconds t = np.arange(0, tlength, t_delta) stimulus = np.sin(2 * np.pi * frequency * t) #simple sine wave for the hist __, spikeISI, __ = helpers.stimulus_ISI_calculator(cellparams, stimulus, tlength=tlength) spikeISI = spikeISI * EODf ISIhist, ISIbins = np.histogram(spikeISI, bins=np.arange(0, 20.2, 0.2)) datarate = { 'baselinefs': baselinefs, 'initialfs': initialfs, 'steadyfs': steadyfs, 'contrasts': ampmodinputs['contrasts'] } datahist = {'ISIhist': ISIhist, 'ISIbins': ISIbins[1:]} dataISI = {'spikeISI': spikeISI} prdf = pd.DataFrame(datarate) phistdf = pd.DataFrame(datahist)
tstart = 0.15 #the time point to start plotting (in seconds) tstop = 0.2 #the time point to stop plotting (in seconds) cell_idx = 0 #index of the cell of interest. #Run from here on, if you break and want to re-see what is up. checkertotal = 1 #this to keep looking further to cells after breaking. while checkertotal == 1: cell, EODf, cellparams = helpers.parameters_dictionary_reformatting( cell_idx, parameters) frequency = EODf #Electric organ discharge frequency in Hz, used for stimulus t_delta = cellparams["deltat"] #time step in seconds t = np.arange(0, tlength, t_delta) stimulus = np.sin(2 * np.pi * frequency * t) spikevals = helpers.stimulus_ISI_calculator( cellparams, stimulus, tlength=tlength) #spikevals is spiketimes, #spikeISI, meanspkfr ISIlist.append(spikevals[1]) meanspkfrs.append(spikevals[2]) #mean spike firing rate per second helpers.stimulus_ISI_plotter(cell, t, EODf, stimulus, *spikevals, tstart=tstart, tstop=tstop) checkerplot = 0 while checkerplot == 0: a = input('press enter to continue, write esc to quit \n')