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