bug fix mean_freq plus time trace, add function to find time window for f point detections
This commit is contained in:
parent
0dfff5768c
commit
ba464b3f5e
@ -4,6 +4,7 @@ from thunderfish.eventdetection import detect_peaks, threshold_crossing_times, t
|
||||
from scipy.optimize import curve_fit
|
||||
import functions as fu
|
||||
from numba import jit
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def fit_clipped_line(x, y):
|
||||
@ -193,7 +194,8 @@ def calculate_mean_of_frequency_traces(trial_time_traces, trial_frequency_traces
|
||||
latest_start = max(starts)
|
||||
earliest_end = min(ends)
|
||||
|
||||
shortened_time = np.arange(latest_start, earliest_end, sampling_interval)
|
||||
length = int(round((earliest_end - latest_start) / sampling_interval))
|
||||
shortened_time = (np.arange(0, length) * sampling_interval) + latest_start
|
||||
|
||||
shortened_freqs = []
|
||||
for i in range(len(trial_frequency_traces)):
|
||||
@ -204,6 +206,21 @@ def calculate_mean_of_frequency_traces(trial_time_traces, trial_frequency_traces
|
||||
|
||||
mean_freq = [sum(e) / len(e) for e in zip(*shortened_freqs)]
|
||||
|
||||
# for i in range(len(trial_time_traces)):
|
||||
# if i > 5:
|
||||
# break
|
||||
# plt.plot(trial_time_traces[i], trial_frequency_traces[i])
|
||||
#
|
||||
# plt.plot(shortened_time, mean_freq, color="black")
|
||||
# plt.show()
|
||||
# plt.close()
|
||||
|
||||
|
||||
# if len(mean_freq) == len(shortened_time):
|
||||
# print("time and freq trace worked out.")
|
||||
# else:
|
||||
# print("time and freq trace were different length. time- freq:" + str(len(shortened_time)-len(mean_freq)))
|
||||
|
||||
return shortened_time, mean_freq
|
||||
|
||||
|
||||
@ -437,12 +454,11 @@ def __vector_strength__(relative_spike_times: np.ndarray, eod_durations: np.ndar
|
||||
|
||||
|
||||
def detect_f_zero_in_frequency_trace(time, frequency, stimulus_start, sampling_interval, peak_buffer_percent=0.05, buffer=0.025):
|
||||
stimulus_start = stimulus_start - time[0] # time start is generally != 0 and != delay
|
||||
|
||||
freq_before = frequency[int(buffer/sampling_interval):int((stimulus_start - buffer) / sampling_interval)]
|
||||
freq_before = frequency[int(time[0]+buffer/sampling_interval):int((stimulus_start - time[0] - buffer) / sampling_interval)]
|
||||
|
||||
if len(freq_before) < 3:
|
||||
print("mäh")
|
||||
print("Length of reference frequency before the stimulus too short (< 3 points)")
|
||||
return 0
|
||||
|
||||
min_before = min(freq_before)
|
||||
@ -450,8 +466,7 @@ def detect_f_zero_in_frequency_trace(time, frequency, stimulus_start, sampling_i
|
||||
mean_before = np.mean(freq_before)
|
||||
|
||||
# time where the f-zero is searched in
|
||||
start_idx = int((stimulus_start-0.1*buffer) / sampling_interval)
|
||||
end_idx = int((stimulus_start + buffer) / sampling_interval)
|
||||
start_idx, end_idx = time_window_detect_f_zero(time[0], stimulus_start, sampling_interval, buffer)
|
||||
|
||||
min_during_start_of_stim = min(frequency[start_idx:end_idx])
|
||||
max_during_start_of_stim = max(frequency[start_idx:end_idx])
|
||||
@ -480,22 +495,39 @@ def detect_f_zero_in_frequency_trace(time, frequency, stimulus_start, sampling_i
|
||||
return f_zero
|
||||
|
||||
|
||||
def time_window_detect_f_zero(time_start, stimulus_start, sampling_interval, buffer=0.025):
|
||||
stimulus_start = stimulus_start - time_start
|
||||
start_idx = int((stimulus_start - 0.5 * buffer) / sampling_interval)
|
||||
end_idx = int((stimulus_start + buffer) / sampling_interval)
|
||||
return start_idx, end_idx
|
||||
|
||||
|
||||
def detect_f_infinity_in_freq_trace(time, frequency, stimulus_start, stimulus_duration, sampling_interval, length=0.1, buffer=0.025):
|
||||
stimulus_end_time = stimulus_start + stimulus_duration - time[0]
|
||||
start_idx, end_idx = time_window_detect_f_infinity(time[0], stimulus_start, stimulus_duration, sampling_interval, length, buffer)
|
||||
return np.mean(frequency[start_idx:end_idx])
|
||||
|
||||
|
||||
def time_window_detect_f_infinity(time_start, stimulus_start, stimulus_duration, sampling_interval, length=0.1, buffer=0.025):
|
||||
stimulus_end_time = stimulus_start + stimulus_duration - time_start
|
||||
|
||||
start_idx = int((stimulus_end_time - length - buffer) / sampling_interval)
|
||||
end_idx = int((stimulus_end_time - buffer) / sampling_interval)
|
||||
return np.mean(frequency[start_idx:end_idx])
|
||||
return start_idx, end_idx
|
||||
|
||||
|
||||
def detect_f_baseline_in_freq_trace(time, frequency, stimulus_start, sampling_interval, buffer=0.025):
|
||||
stim_start = stimulus_start - time[0]
|
||||
start_idx, end_idx = time_window_detect_f_baseline(time[0], stimulus_start, sampling_interval, buffer)
|
||||
f_baseline = np.mean(frequency[start_idx:end_idx])
|
||||
|
||||
return f_baseline
|
||||
|
||||
|
||||
def time_window_detect_f_baseline(time_start, stimulus_start, sampling_interval, buffer=0.025):
|
||||
stim_start = stimulus_start - time_start
|
||||
|
||||
if stim_start < 0.1:
|
||||
warn("FICurve:__calculate_f_baseline__(): Quite short delay at the start.")
|
||||
|
||||
start_idx = int(buffer/sampling_interval)
|
||||
end_idx = int((stim_start-buffer)/sampling_interval)
|
||||
f_baseline = np.mean(frequency[start_idx:end_idx])
|
||||
|
||||
return f_baseline
|
||||
start_idx = int(buffer / sampling_interval)
|
||||
end_idx = int((stim_start - buffer) / sampling_interval)
|
||||
return start_idx, end_idx
|
||||
|
Loading…
Reference in New Issue
Block a user