diff --git a/main/flaredetector/util.py b/main/flaredetector/util.py index d10da27..bed5a87 100644 --- a/main/flaredetector/util.py +++ b/main/flaredetector/util.py @@ -1,5 +1,6 @@ import numpy as np from scipy.signal import find_peaks +from scipy.optimize import curve_fit def findMaxIndices(lc, num=3, distance=100, height=(None, None), sortByHighest=False, minimalLC=False): @@ -79,4 +80,18 @@ def convertStarndardIndexToFoldedIndex(foldedLc, standardIndex): cycle = i break - return cycle, foldedIndex \ No newline at end of file + return cycle, foldedIndex + +def getFoldedBestFit(foldedLc): + def sine(t, A, w, p, c): return A * np.sin(w*t + p) + c + flux = foldedLc.flux + filt = ~np.isnan(flux) + multi = 1 + if(np.mean(flux).value > 10): + multi = float(np.mean(flux).value) + flux = foldedLc.normalize().flux + phase = foldedLc.phase[filt].value + popt, pcov = curve_fit(sine, phase, flux[filt]) + sineFit = sine(foldedLc.phase[filt].value, *popt) + sineFit *= multi + return phase, sineFit \ No newline at end of file