From 31dfaebc3e4f47823ca3cea5f6ffd18532308ff4 Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Thu, 25 Apr 2024 15:49:44 +0200 Subject: [PATCH] flaredetector: use correct peak index for checking if flare is valid --- main/flaredetector/flaredetector.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main/flaredetector/flaredetector.py b/main/flaredetector/flaredetector.py index 89cef9c..96f4509 100644 --- a/main/flaredetector/flaredetector.py +++ b/main/flaredetector/flaredetector.py @@ -16,19 +16,18 @@ def moveFluxForFit(curPeakIndex, flux): flarePoints = np.array(np.linspace(minInd, maxInd, num=maxInd-minInd+1), dtype=int) flareFitDataPoints = flarePoints - curPeakIndex Peak = flux[curPeakIndex] - 1 - return flarePoints, flareFitDataPoints, Peak + return flarePoints, flareFitDataPoints, Peak, maxInd - curPeakIndex -def isValidFlarePoint(flareData): +def isValidFlarePoint(flareData, newPeakIndex): threshold = 0.005 - peakIndex = np.argmax(flareData) - if((flareData[peakIndex-1] > threshold and flareData[peakIndex+1] > threshold) or - (flareData[peakIndex+1] > threshold and flareData[peakIndex+2] > threshold)): + if((flareData[newPeakIndex-1] > threshold and flareData[newPeakIndex+1] > threshold) or + (flareData[newPeakIndex+1] > threshold and flareData[newPeakIndex+2] > threshold)): return True return False def calculateFitForFlare(lightcurve, peakIndex): - flarePoints, flareFitDataPoints, Peak = moveFluxForFit(peakIndex, lightcurve.flux) - if(not isValidFlarePoint(lightcurve.flux[flarePoints]-1)): + flarePoints, flareFitDataPoints, Peak, newPeakIndex = moveFluxForFit(peakIndex, lightcurve.flux) + if(not isValidFlarePoint(lightcurve.flux[flarePoints]-1, newPeakIndex)): raise Exception("Flare not valid: not enough datapoints above mean") popt, pcov = curve_fit(lambda x, l, w: GaussExpo(x, Peak, l, w), flareFitDataPoints, lightcurve.flux[flarePoints]-1) fit = GaussExpo(flareFitDataPoints, Peak, *popt)