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:
@@ -8,6 +8,19 @@ def GaussExpo(x, Peak, l, w):
|
|||||||
res2 = Peak * np.exp(-l * x[peakX:])
|
res2 = Peak * np.exp(-l * x[peakX:])
|
||||||
return np.append(res1, res2)
|
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):
|
def getFlareRange(flux, peakIndex):
|
||||||
minInd = -np.inf
|
minInd = -np.inf
|
||||||
|
|||||||
Reference in New Issue
Block a user