From 77e23f480a7f9d0e642134a30cc9b75eb652dec7 Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Mon, 15 Apr 2024 15:16:27 +0200 Subject: [PATCH] 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 --- main/flaredetector/flaredetector.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main/flaredetector/flaredetector.py b/main/flaredetector/flaredetector.py index 2a0a467..55c5e56 100644 --- a/main/flaredetector/flaredetector.py +++ b/main/flaredetector/flaredetector.py @@ -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