flaredetector: add calculateFitForFlare function

this function fits the flare at peakIndex postion from a flattened
lightcurve

returns flattened Peak value, flare fit indices (in original
lightcurve time), and the fit
This commit is contained in:
2024-04-15 15:16:27 +02:00
parent 1814467090
commit 77e23f480a
+13
View File
@@ -8,6 +8,19 @@ def GaussExpo(x, Peak, l, w):
res2 = Peak * np.exp(-l * x[peakX:])
return np.append(res1, res2)
def moveFluxForFit(curPeakIndex, flux):
minInd, maxInd = getFlareRange(flux, curPeakIndex)
flarePoints = np.array(np.linspace(minInd, maxInd, num=maxInd-minInd+1), dtype=int)
flareFitDataPoints = flarePoints - curPeakIndex
Peak = flux[curPeakIndex] - 1
return flarePoints, flareFitDataPoints, Peak
def calculateFitForFlare(lightcurve, peakIndex):
flarePoints, flareFitDataPoints, Peak = moveFluxForFit(peakIndex, lightcurve.flux)
popt, pcov = curve_fit(lambda x, l, w: GaussExpo(x, Peak, l, w), flareFitDataPoints, lightcurve.flux[flarePoints]-1)
fit = GaussExpo(flareFitDataPoints, Peak, *popt)
flareFitDataPoints = flareFitDataPoints + peakIndex
return Peak+1, flareFitDataPoints, fit+1
def getFlareRange(flux, peakIndex):
minInd = -np.inf