switched position of functions

This commit is contained in:
mbergmann 2024-10-23 09:17:55 +02:00
parent 43181c037d
commit 1205b376ee

View File

@ -54,6 +54,40 @@ def binary_spikes(spike_times, duration, dt):
binary[spike_indices] = 1 # put the indices into binary
return binary
def calculate_integral(freq, power, point, delta):
"""
Calculate the integral around a single specified point.
Parameters
----------
frequency : np.array
An array of frequencies corresponding to the power values.
power : np.array
An array of power spectral density values.
point : float
The harmonic frequency at which to calculate the integral.
delta : float
Radius of the range for integration around the point.
Returns
-------
integral : float
The calculated integral around the point.
local_mean : float
The local mean value (adjacent integrals).
"""
indices = (freq >= point - delta) & (freq <= point + delta)
integral = np.trapz(power[indices], freq[indices])
left_indices = (freq >= point - 5 * delta) & (freq < point - delta)
right_indices = (freq > point + delta) & (freq <= point + 5 * delta)
l_integral = np.trapz(power[left_indices], freq[left_indices])
r_integral = np.trapz(power[right_indices], freq[right_indices])
local_mean = np.mean([l_integral, r_integral])
return integral, local_mean
def extract_stim_data(stimulus):
'''
extracts all necessary metadata for each stimulus
@ -252,39 +286,6 @@ def spike_times(stim):
dt = ti.sampling_interval
return spikes, stim_dur, dt # se changed spike_times to spikes so its not the same as name of function
def calculate_integral(freq, power, point, delta):
"""
Calculate the integral around a single specified point.
Parameters
----------
frequency : np.array
An array of frequencies corresponding to the power values.
power : np.array
An array of power spectral density values.
point : float
The harmonic frequency at which to calculate the integral.
delta : float
Half-width of the range for integration around the point.
Returns
-------
integral : float
The calculated integral around the point.
local_mean : float
The local mean value (adjacent integrals).
"""
indices = (freq >= point - delta) & (freq <= point + delta)
integral = np.trapz(power[indices], freq[indices])
left_indices = (freq >= point - 5 * delta) & (freq < point - delta)
right_indices = (freq > point + delta) & (freq <= point + 5 * delta)
l_integral = np.trapz(power[left_indices], freq[left_indices])
r_integral = np.trapz(power[right_indices], freq[right_indices])
local_mean = np.mean([l_integral, r_integral])
return integral, local_mean
def valid_integrals(integral, local_mean, threshold, point):
"""