astrodatagui: FlaredetectorWidget: only generate fits when new fits file is selected

This commit is contained in:
2024-04-22 14:27:19 +02:00
parent 4e28ec48b4
commit 4a09d3a757
+11 -12
View File
@@ -60,6 +60,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.currentLC = lk.read(fitsFilePath) self.currentLC = lk.read(fitsFilePath)
self.currentLCCollection = None self.currentLCCollection = None
self.currentMainName = mainName self.currentMainName = mainName
self.updateFit()
self.updatePlot() self.updatePlot()
def setFitsFiles(self, mainName: str, fitsFilePaths: list[str]): def setFitsFiles(self, mainName: str, fitsFilePaths: list[str]):
@@ -80,6 +81,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.currentLCCollection = lk.LightCurveCollection(lcList) self.currentLCCollection = lk.LightCurveCollection(lcList)
self.currentLC = self.currentLCCollection.stitch() self.currentLC = self.currentLCCollection.stitch()
self.currentMainName = mainName self.currentMainName = mainName
self.updateFit()
self.updatePlot() self.updatePlot()
def setFluxType(self, fluxType: str): def setFluxType(self, fluxType: str):
@@ -130,6 +132,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
if(self.FlattenState["Enabled"]): if(self.FlattenState["Enabled"]):
self.FoldState["Enabled"] = False self.FoldState["Enabled"] = False
self.PeriodogramState["Enabled"] = False self.PeriodogramState["Enabled"] = False
self.updateFit()
self.updatePlot() self.updatePlot()
def setFoldState(self, enabled: bool, period: float, epoch: float): def setFoldState(self, enabled: bool, period: float, epoch: float):
@@ -166,6 +169,10 @@ class FlaredetectorWidget(QtWidgets.QWidget):
lc.flux = lc[self.fluxType] lc.flux = lc[self.fluxType]
return lc.normalize(unit=self.NormalizeState["Scale"]) return lc.normalize(unit=self.NormalizeState["Scale"])
def updateFit(self):
self.peaks, self.fits = calculateFlareFitsForLightcurve(self.currentLC.flatten(window_length=self.FlattenState["WindowLength"],
polyorder=self.FlattenState["PolynomialOrder"]), num=100)
def updatePlot(self): def updatePlot(self):
lc = self.currentLC lc = self.currentLC
label = f"{self.currentMainName}" label = f"{self.currentMainName}"
@@ -193,7 +200,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
polyorder=self.FlattenState["PolynomialOrder"]) polyorder=self.FlattenState["PolynomialOrder"])
label += " - flattened" label += " - flattened"
maxPowers = findMaxIndices(lc, 100, height=1.005, distance=1) #maxPowers = findMaxIndices(lc, 100, height=1.005, distance=1)
if(self.FoldState["Enabled"]): if(self.FoldState["Enabled"]):
lc = lc.fold(period=self.FoldState["Period"], lc = lc.fold(period=self.FoldState["Period"],
epoch_time=self.FoldState["EpochTime"]) epoch_time=self.FoldState["EpochTime"])
@@ -211,14 +218,6 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.periodogramInfoGroupBox.setVisible(self.PeriodogramState["Enabled"]) self.periodogramInfoGroupBox.setVisible(self.PeriodogramState["Enabled"])
if(not self.FlattenState["Enabled"] and
not self.FoldState["Enabled"] and
not self.PeriodogramState["Enabled"]):
peaks, fits = calculateFlareFitsForLightcurve(lc.flatten(window_length=self.FlattenState["WindowLength"],
polyorder=self.FlattenState["PolynomialOrder"]), num=100)
elif(self.FlattenState["Enabled"]):
peaks, fits = calculateFlareFitsForLightcurve(lc, num=100)
self.figureAxis.clear() self.figureAxis.clear()
time_support() time_support()
if(self.FoldState["Enabled"]): if(self.FoldState["Enabled"]):
@@ -231,8 +230,8 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.figureAxis.plot(lc.frequency[maxPowers], lc.power[maxPowers], "x") self.figureAxis.plot(lc.frequency[maxPowers], lc.power[maxPowers], "x")
else: else:
lc.plot(label=label, ax=self.figureAxis) lc.plot(label=label, ax=self.figureAxis)
plotFlarePeaks(self.figureAxis, peaks, lc.flux) plotFlarePeaks(self.figureAxis, self.peaks, lc.flux)
markFlare(self.figureAxis, fits, lc.flux) markFlare(self.figureAxis, self.fits, lc.flux)
if(self.FlattenState["Enabled"]): if(self.FlattenState["Enabled"]):
plotFlareFits(self.figureAxis, fits) plotFlareFits(self.figureAxis, self.fits)
self.figure.canvas.draw_idle() self.figure.canvas.draw_idle()