updated functions for easier power spectrum computation
This commit is contained in:
parent
c995ed7a3b
commit
4db4e5f899
@ -113,18 +113,14 @@ def firing_rate(binary_spikes, dt = 0.000025, box_width = 0.01):
|
|||||||
rate = np.convolve(binary_spikes, box, mode = 'same')
|
rate = np.convolve(binary_spikes, box, mode = 'same')
|
||||||
return rate
|
return rate
|
||||||
|
|
||||||
def power_spectrum(spike_times, duration, dt):
|
def power_spectrum(stimulus):
|
||||||
'''
|
'''
|
||||||
Computes a power spectrum based on the spike times
|
Computes a power spectrum based from a stimulus
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
spike_times : np.array
|
stimulus : Stimulus object or rlxnix.base.repro module
|
||||||
The spike times.
|
The stimulus from which the data is needed.
|
||||||
duration : float
|
|
||||||
The trial duration:
|
|
||||||
dt : float
|
|
||||||
The temporal resolution.
|
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -134,8 +130,9 @@ def power_spectrum(spike_times, duration, dt):
|
|||||||
Power of the frequencies calculated.
|
Power of the frequencies calculated.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
spikes, duration, dt = spike_times(stimulus)
|
||||||
# binarizes spikes
|
# binarizes spikes
|
||||||
binary = binary_spikes(spike_times, duration, dt)
|
binary = binary_spikes(spikes, duration, dt)
|
||||||
# computes firing rates
|
# computes firing rates
|
||||||
rate = firing_rate(binary, dt = dt)
|
rate = firing_rate(binary, dt = dt)
|
||||||
# creates power spectrum
|
# creates power spectrum
|
||||||
@ -225,4 +222,32 @@ def sam_data(sam):
|
|||||||
sam_eodf = np.mean(eodfs)
|
sam_eodf = np.mean(eodfs)
|
||||||
sam_nyquist = np.mean(ny_freqs)
|
sam_nyquist = np.mean(ny_freqs)
|
||||||
sam_stim = np.mean(stim_freqs)
|
sam_stim = np.mean(stim_freqs)
|
||||||
return sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim
|
return sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim
|
||||||
|
|
||||||
|
def spike_times(stim):
|
||||||
|
"""
|
||||||
|
Reads out the spike times and other necessary parameters
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
stim : Stimulus object or rlxnix.base.repro module
|
||||||
|
The stimulus from which the spike times should be calculated.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
spike_times : np.array
|
||||||
|
The spike times of the stimulus.
|
||||||
|
stim_dur : float
|
||||||
|
The duration of the stimulus.
|
||||||
|
dt : float
|
||||||
|
Time interval between two data points.
|
||||||
|
|
||||||
|
"""
|
||||||
|
# reads out the spike times
|
||||||
|
spike_times, _ = stim.trace_data('Spikes-1')
|
||||||
|
# reads out the duration
|
||||||
|
stim_dur = stim.duration
|
||||||
|
# get the stimulus interval
|
||||||
|
ti = stim.trace_info("V-1")
|
||||||
|
dt = ti.sampling_interval
|
||||||
|
return spike_times, stim_dur, dt
|
Loading…
Reference in New Issue
Block a user