From 4e28ec48b4b2b06d42cff3537ddaeed80772e786 Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Mon, 22 Apr 2024 10:09:11 +0200 Subject: [PATCH] flaredetector: flares need to have a certain duration either have 1 point before and after the peak above a threshold or have 2 points after the peak above a threhold --- main/flaredetector/flaredetector.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main/flaredetector/flaredetector.py b/main/flaredetector/flaredetector.py index 1ec7bba..89cef9c 100644 --- a/main/flaredetector/flaredetector.py +++ b/main/flaredetector/flaredetector.py @@ -18,8 +18,18 @@ def moveFluxForFit(curPeakIndex, flux): Peak = flux[curPeakIndex] - 1 return flarePoints, flareFitDataPoints, Peak +def isValidFlarePoint(flareData): + 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)): + return True + return False + def calculateFitForFlare(lightcurve, peakIndex): flarePoints, flareFitDataPoints, Peak = moveFluxForFit(peakIndex, lightcurve.flux) + if(not isValidFlarePoint(lightcurve.flux[flarePoints]-1)): + 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) flareFitDataPoints = flareFitDataPoints + peakIndex