from scipy.signal import savgol_filter from scipy.interpolate import interp1d if len(disp_curves) == 0: print("no new correlations found to be processed!") else: f = np.array([]) avg = np.array([]) sterr = np.array([]) for frequency in dictionary: f = np.append(f, float(frequency)) avg = np.append(avg, np.mean(dictionary[frequency])) sterr = np.append(sterr, np.std(dictionary[frequency])) avg = avg[f.argsort()] sterr = sterr[f.argsort()] f = f[f.argsort()] minf = f[0] maxf = f[-1] func = interp1d(f, avg) f2 = np.arange(int( (maxf - minf) / 0.002)) * 0.002 + (int(minf * 1000) + 1) / 1000. avg_ip = func(f2) if len(avg_ip) > 91: smooth_curve1 = savgol_filter(avg_ip, 91, 3) else: smooth_curve1 = avg_ip a, b, c, d, e = np.polyfit(f, avg, 4)