From 6562e2cff8a258ef806c0ee77b790e2160d1896b Mon Sep 17 00:00:00 2001 From: AlexanderOtt Date: Thu, 2 Apr 2020 10:05:22 +0200 Subject: [PATCH] add fit_(function)(x,y) type functions --- helperFunctions.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/helperFunctions.py b/helperFunctions.py index d926007..1d7814b 100644 --- a/helperFunctions.py +++ b/helperFunctions.py @@ -1,6 +1,30 @@ import numpy as np from warnings import warn from thunderfish.eventdetection import detect_peaks, threshold_crossing_times, threshold_crossings +from scipy.optimize import curve_fit +import functions as fu + + +def fit_clipped_line(x, y): + popt, pcov = curve_fit(fu.clipped_line, x, y) + + return popt + + +def fit_boltzmann(x, y): + max_f0 = float(max(y)) + min_f0 = 0.1 # float(min(self.f_zeros)) + mean_int = float(np.mean(x)) + + total_increase = max_f0 - min_f0 + total_change_int = max(x) - min(x) + start_k = float((total_increase / total_change_int * 4) / max_f0) + + popt, pcov = curve_fit(fu.full_boltzmann, x, y, + p0=(max_f0, min_f0, start_k, mean_int), + maxfev=10000, bounds=([0, 0, -np.inf, -np.inf], [np.inf, np.inf, np.inf, np.inf])) + + return popt def merge_similar_intensities(intensities, spiketimes, trans_amplitudes): @@ -437,7 +461,6 @@ def detect_f_infinity_in_freq_trace(time, frequency, stimulus_start, stimulus_du 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])