way too many updates

This commit is contained in:
2024-09-19 12:02:21 +02:00
parent 631fd901b1
commit 3d128d8ecc
9 changed files with 1378 additions and 282 deletions
+86 -37
View File
@@ -64,6 +64,10 @@ class AstrodataGUI(QtWidgets.QMainWindow):
self.flaredetectorPreview.periodsCalculated.connect(self.updatePeriods)
self.flaredetectorPreview.epochCalculated.connect(self.updateEpochPeriod)
self.rbLinearFit.toggled.connect(self.rbFoldedPlotTypeChanged)
self.rbSineFit.toggled.connect(self.rbFoldedPlotTypeChanged)
self.rbPolynomialFit.toggled.connect(self.rbFoldedPlotTypeChanged)
self.setupCustomSimbadQueries()
self.show()
self.loadDB()
@@ -109,51 +113,52 @@ class AstrodataGUI(QtWidgets.QMainWindow):
if not diag.exec():
return
try:
result = self.simbad.query_object(diag.starIdentifier)
results = self.simbad.query_object(diag.starIdentifier)
except:
self.showErrorMessage("Simbad Error", "Failed to fetcch information from Simbad, aborting...")
return
results = results.split(";")
for result in results:
try:
mainName = result["MAIN_ID"][0]
except:
self.showErrorMessage("Main Identifier Error", "Failed to grab main identifier, aborting...")
return
try:
mainName = result["MAIN_ID"][0]
except:
self.showErrorMessage("Main Identifier Error", "Failed to grab main identifier, aborting...")
return
try:
altNames = Simbad.query_objectids(mainName)
except:
self.showErrorMessage("Identifier Error", "Failed to grab all identifiers, aborting...")
return
try:
altNames = Simbad.query_objectids(mainName)
except:
self.showErrorMessage("Identifier Error", "Failed to grab all identifiers, aborting...")
return
try:
specType = result["SP_TYPE"][0]
if(specType == ""):
try:
specType = result["SP_TYPE"][0]
if(specType == ""):
specType = "-"
except:
print("No spectral type found")
specType = "-"
except:
print("No spectral type found")
specType = "-"
rotVel = -1
rotVelUnit = ""
try:
if(result["RVZ_TYPE"][0] == "v"):
rotVel = result["RV_VALUE"][0]
rotVelUnit = str(result["RV_VALUE"].unit)
except:
print("No radial velocity found")
rotVel = -1
rotVelUnit = ""
try:
if(result["RVZ_TYPE"][0] == "v"):
rotVel = result["RV_VALUE"][0]
rotVelUnit = str(result["RV_VALUE"].unit)
except:
print("No radial velocity found")
try:
dist = float(result["Distance_distance"][0])
if(np.isnan(dist)):
try:
dist = float(result["Distance_distance"][0])
if(np.isnan(dist)):
dist = -1
distUnit = result["Distance_unit"][0]
except:
dist = -1
distUnit = result["Distance_unit"][0]
except:
dist = -1
distUnit = ""
distUnit = ""
self.starDB.insertStar(mainName, altNames, diag.productManifest,
specType, rotVel, rotVelUnit, dist, distUnit)
self.starDB.insertStar(mainName, altNames, diag.productManifest,
specType, rotVel, rotVelUnit, dist, distUnit)
self.updateStarList()
@@ -184,14 +189,41 @@ class AstrodataGUI(QtWidgets.QMainWindow):
else:
self.lbDistance.setText("-")
def updateStarFoldedFitType(self, foldedFitType):
self.rbLinearFit.blockSignals(True)
self.rbSineFit.blockSignals(True)
self.rbPolynomialFit.blockSignals(True)
if(foldedFitType == "linear"):
self.rbLinearFit.setChecked(True)
self.rbSineFit.setChecked(False)
self.rbPolynomialFit.setChecked(False)
elif(foldedFitType == "sine"):
self.rbLinearFit.setChecked(False)
self.rbSineFit.setChecked(True)
self.rbPolynomialFit.setChecked(False)
elif(foldedFitType == "poly"):
self.rbLinearFit.setChecked(False)
self.rbSineFit.setChecked(False)
self.rbPolynomialFit.setChecked(True)
else:
self.rbLinearFit.setChecked(False)
self.rbSineFit.setChecked(False)
self.rbPolynomialFit.setChecked(False)
self.rbLinearFit.blockSignals(False)
self.rbSineFit.blockSignals(False)
self.rbPolynomialFit.blockSignals(False)
def starSelected(self, item):
self.currentStarMainName = item.text()
seqs = self.starDB.getStarSequences(item.text())
infos = self.starDB.getStarInfos(item.text())
altNames = self.starDB.getStarAltNames(item.text())
self.foldedFitType = self.starDB.getFoldedFitType(item.text())
self.lbMainID.setText(item.text())
self.updateSequenceList(seqs)
self.updateStarInfo(infos)
self.updateStarAltNames(altNames)
self.updateStarFoldedFitType(self.foldedFitType)
def sequenceSelected(self, item):
self.gbPlotOptions.setEnabled(True)
@@ -202,6 +234,21 @@ class AstrodataGUI(QtWidgets.QMainWindow):
seq = seqText[1]
filePath = self.starDB.getFilePath(mainName, source, seq)
self.flaredetectorPreview.setFitsFile(filePath, mainName)
self.flaredetectorPreview.setFoldedFitType(self.foldedFitType)
def rbFoldedPlotTypeChanged(self, state):
if(state):
print("Folded fit type changed")
self.foldedFitType = ""
match(self.sender()):
case self.rbLinearFit:
self.foldedFitType = "linear"
case self.rbSineFit:
self.foldedFitType = "sine"
case self.rbPolynomialFit:
self.foldedFitType = "poly"
self.starDB.updateFoldedFitType(self.currentStarMainName, self.foldedFitType)
self.flaredetectorPreview.setFoldedFitType(self.foldedFitType)
def updatePeriods(self, periods: list):
self.edPlotFoldPeriod.setText(str(periods[0].value))
@@ -378,18 +425,20 @@ class AstrodataGUI(QtWidgets.QMainWindow):
"DistanceUnit",
"Source",
"Sequence",
"FilePath"])
"FilePath",
"FitType"])
for starName in self.starDB.getAllStars():
sequences = self.starDB.getStarSequences(starName)
infos = self.starDB.getStarInfos(starName)
fitType = self.starDB.getFoldedFitType(starName)
for sourceSeq in sequences:
source = sourceSeq["Source"]
seq = sourceSeq["Sequence"]
filePath = self.starDB.getFilePath(starName, source, seq)
allStarsDictList.loc[len(allStarsDictList.index)] = \
[starName, infos["SpType"], infos["RotVel"], infos["RotVelUnit"],
infos["Distance"], infos["DistanceUnit"], source, seq, filePath]
infos["Distance"], infos["DistanceUnit"], source, seq, filePath, fitType]
self.calcAllFlaresThread = CalcAllFlaresThread(allStarsDictList)
self.calcAllFlaresThread.finished.connect(self.btCountAllFlaresClickedDone)
+80 -68
View File
@@ -6,76 +6,88 @@ import pandas as pd
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
from ..flaredetector.util import *
import warnings
warnings.filterwarnings("ignore")
def getFlareCount(filesDict):
lc = read(filesDict["FilePath"])
lc.flux = lc["sap_flux"]
lc.flux_err = lc["sap_flux_err"]
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
sapValSec, sapTds = getTotalValidDataInSeconds(lc, "sap_flux")
sapPeriodogram = lc.to_periodogram()
sapPeakPeriod = sapPeriodogram.period[findMaxIndices(sapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
sapEpochTime = getEpochTime(lc)
sapFoldedLC = lc.fold(period=sapPeakPeriod, epoch_time=sapEpochTime)
sapPhase, sapSineFit, sapFitType = getFoldedBestFit(sapFoldedLC)
sapMinima, sapMaxima = getFoldedFitPeakValley(sapSineFit)
sapminPhasesBounds, sapmaxPhasesBounds = getPhaseRangesNearPeak((sapMinima, sapMaxima), sapPhase, returnPhaseValue=True)
sapFoldedPeaks = []
sapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(sapFoldedLC, peak["StandardIndex"])
sapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
sapFoldedPeaksPhasePair.append({"Phase": sapFoldedLC.phase[sapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
try:
print(f"Starting {filesDict['StarName']}, {filesDict['Sequence']}")
lc = read(filesDict["FilePath"])
lc.flux = lc["sap_flux"]
lc.flux_err = lc["sap_flux_err"]
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
sapValSec, sapTds = getTotalValidDataInSeconds(lc, "sap_flux")
sapPeriodogram = lc.to_periodogram()
sapPeakPeriod = sapPeriodogram.period[findMaxIndices(sapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
sapEpochTime = getEpochTime(lc)
sapFoldedLC = lc.fold(period=sapPeakPeriod, epoch_time=sapEpochTime)
sapPhase, sapSineFit, sapFitType = getFoldedBestFit(sapFoldedLC, fitType=filesDict["FitType"])
sapMinima, sapMaxima = getFoldedFitPeakValley(sapSineFit)
sapminPhasesBounds, sapmaxPhasesBounds = getPhaseRangesNearPeak((sapMinima, sapMaxima), sapPhase, returnPhaseValue=True)
sapFoldedPeaks = []
sapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(sapFoldedLC, peak["StandardIndex"])
sapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
sapFoldedPeaksPhasePair.append({"Phase": sapFoldedLC.phase[sapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
lc.flux = lc["pdcsap_flux"]
lc.flux_err = lc["pdcsap_flux_err"]
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
pdcsapPeriodogram = lc.to_periodogram()
pdcsapPeakPeriod = pdcsapPeriodogram.period[findMaxIndices(pdcsapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
pdcsapEpochTime = getEpochTime(lc)
pdcsapFoldedLC = lc.fold(period=pdcsapPeakPeriod, epoch_time=pdcsapEpochTime)
pdcsapPhase, pdcsapSineFit, pdcsapFitType = getFoldedBestFit(pdcsapFoldedLC)
pdcsapMinima, pdcsapMaxima = getFoldedFitPeakValley(pdcsapSineFit)
pdcsapminPhasesBounds, pdcsapmaxPhasesBounds = getPhaseRangesNearPeak((pdcsapMinima, pdcsapMaxima), pdcsapPhase, returnPhaseValue=True)
pdcsapFoldedPeaks = []
pdcsapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(pdcsapFoldedLC, peak["StandardIndex"])
pdcsapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapFoldedPeaksPhasePair.append({"Phase": pdcsapFoldedLC.phase[pdcsapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
lc.flux = lc["pdcsap_flux"]
lc.flux_err = lc["pdcsap_flux_err"]
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
pdcsapPeriodogram = lc.to_periodogram()
pdcsapPeakPeriod = pdcsapPeriodogram.period[findMaxIndices(pdcsapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
pdcsapEpochTime = getEpochTime(lc)
pdcsapFoldedLC = lc.fold(period=pdcsapPeakPeriod, epoch_time=pdcsapEpochTime)
pdcsapPhase, pdcsapSineFit, pdcsapFitType = getFoldedBestFit(pdcsapFoldedLC, fitType=filesDict["FitType"])
pdcsapMinima, pdcsapMaxima = getFoldedFitPeakValley(pdcsapSineFit)
pdcsapminPhasesBounds, pdcsapmaxPhasesBounds = getPhaseRangesNearPeak((pdcsapMinima, pdcsapMaxima), pdcsapPhase, returnPhaseValue=True)
pdcsapFoldedPeaks = []
pdcsapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(pdcsapFoldedLC, peak["StandardIndex"])
pdcsapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapFoldedPeaksPhasePair.append({"Phase": pdcsapFoldedLC.phase[pdcsapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
filesDict["sapPeaks"] = sapPeaks
filesDict["sapPeaksCount"] = len(sapPeaks)
filesDict["sapFits"] = sapFits
filesDict["sapValidTimespans"] = sapTds
filesDict["sapValidSeconds"] = sapValSec
filesDict["sapFoldedCycle"] = sapFoldedLC.cycle
#filesDict["sapFoldedPhase"] = sapFoldedLC.phase.value
#filesDict["sapFoldedFitPhase"] = sapPhase
filesDict["sapFoldedFitPhaseStarEnd"] = (sapFoldedLC.phase.value[0], sapFoldedLC.phase.value[-1])
filesDict["sapFoldedPeaksPhasePair"] = sapFoldedPeaksPhasePair
filesDict["sapPeriod"] = sapPeakPeriod.value
filesDict["sapPeriodMinima"] = sapMinima
filesDict["sapPeriodMinimaBoundaries"] = sapminPhasesBounds
filesDict["sapPeriodMaxima"] = sapMaxima
filesDict["sapPeriodMaximaBoundaries"] = sapmaxPhasesBounds
filesDict["pdcsapPeaks"] = pdcsapPeaks
filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
filesDict["pdcsapFits"] = pdcsapFits
filesDict["pdcsapValidTimespans"] = pdcsapTds
filesDict["pdcsapValidSeconds"] = pdcsapValSec
filesDict["pdcsapFoldedCycle"] = sapFoldedLC.cycle
#filesDict["pdcsapFoldedPhase"] = sapFoldedLC.phase.value
#filesDict["pdcsapFoldedFitPhase"] = pdcsapPhase
filesDict["pdcsapFoldedFitPhaseStarEnd"] = (pdcsapFoldedLC.phase.value[0], pdcsapFoldedLC.phase.value[-1])
filesDict["pdcsapFoldedPeaksPhasePair"] = pdcsapFoldedPeaksPhasePair
filesDict["pdcsapPeriod"] = pdcsapPeakPeriod.value
filesDict["pdcsapPeriodMinima"] = pdcsapMinima
filesDict["pdcsapPeriodMinimaBoundaries"] = pdcsapminPhasesBounds
filesDict["pdcsapPeriodMaxima"] = pdcsapMaxima
filesDict["pdcsapPeriodMaximaBoundaries"] = pdcsapmaxPhasesBounds
del lc
return filesDict
filesDict["sapPeaks"] = sapPeaks
filesDict["sapPeaksCount"] = len(sapPeaks)
filesDict["sapFits"] = sapFits
filesDict["sapValidTimespans"] = sapTds
filesDict["sapValidSeconds"] = sapValSec
filesDict["sapFoldedCycle"] = sapFoldedLC.cycle
#filesDict["sapFoldedPhase"] = sapFoldedLC.phase.value
#filesDict["sapFoldedFitPhase"] = sapPhase
filesDict["sapFoldedFitPhaseStarEnd"] = (sapFoldedLC.phase.value[0], sapFoldedLC.phase.value[-1])
filesDict["sapFoldedPeaksPhasePair"] = sapFoldedPeaksPhasePair
filesDict["sapPeriod"] = sapPeakPeriod.value
filesDict["sapPeriodMinima"] = sapMinima
filesDict["sapPeriodMinimaBoundaries"] = sapminPhasesBounds
filesDict["sapPeriodMaxima"] = sapMaxima
filesDict["sapPeriodMaximaBoundaries"] = sapmaxPhasesBounds
filesDict["pdcsapPeaks"] = pdcsapPeaks
filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
filesDict["pdcsapFits"] = pdcsapFits
filesDict["pdcsapValidTimespans"] = pdcsapTds
filesDict["pdcsapValidSeconds"] = pdcsapValSec
filesDict["pdcsapFoldedCycle"] = sapFoldedLC.cycle
#filesDict["pdcsapFoldedPhase"] = sapFoldedLC.phase.value
#filesDict["pdcsapFoldedFitPhase"] = pdcsapPhase
filesDict["pdcsapFoldedFitPhaseStarEnd"] = (pdcsapFoldedLC.phase.value[0], pdcsapFoldedLC.phase.value[-1])
filesDict["pdcsapFoldedPeaksPhasePair"] = pdcsapFoldedPeaksPhasePair
filesDict["pdcsapPeriod"] = pdcsapPeakPeriod.value
filesDict["pdcsapPeriodMinima"] = pdcsapMinima
filesDict["pdcsapPeriodMinimaBoundaries"] = pdcsapminPhasesBounds
filesDict["pdcsapPeriodMaxima"] = pdcsapMaxima
filesDict["pdcsapPeriodMaximaBoundaries"] = pdcsapmaxPhasesBounds
del lc
print(f"Finished {filesDict['StarName']}, {filesDict['Sequence']}")
return filesDict
except Exception as e:
print("------------------------------------------------------------------------")
print(f"Exception in {filesDict['StarName']}, {filesDict['Sequence']}")
print(e)
print("------------------------------------------------------------------------")
return None
class CalcAllFlaresThread(QThread):
progress = pyqtSignal(int)
@@ -89,7 +101,7 @@ class CalcAllFlaresThread(QThread):
def run(self):
cpuCount = multiprocessing.cpu_count()
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
#resFrame = pd.DataFrame([getFlareCount(entry) for entry in self.allFlaresDictList.to_dict(orient="records")])
resFrame = pd.DataFrame(executor.map(getFlareCount, self.allFlaresDictList.to_dict(orient="records")))
self.finished.emit(resFrame)
File diff suppressed because it is too large Load Diff
+80 -36
View File
@@ -968,6 +968,13 @@
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Alt. IDs:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="lbSpType">
<property name="sizePolicy">
@@ -981,23 +988,10 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="lbRotVel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Alt. IDs:</string>
<string>Spectral Type: </string>
</property>
</widget>
</item>
@@ -1021,13 +1015,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Spectral Type: </string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
@@ -1035,19 +1022,6 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="lbMainID">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
@@ -1077,6 +1051,73 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="lbRotVel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="lbMainID">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Fit Type:</string>
</property>
</widget>
</item>
<item row="5" column="2">
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QRadioButton" name="rbLinearFit">
<property name="text">
<string>Linear</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bgFitType</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbSineFit">
<property name="text">
<string>Sine</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bgFitType</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbPolynomialFit">
<property name="text">
<string>Poly</string>
</property>
<attribute name="buttonGroup">
<string notr="true">bgFitType</string>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@@ -1156,4 +1197,7 @@
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="bgFitType"/>
</buttongroups>
</ui>
+17 -9
View File
@@ -1,7 +1,7 @@
from enum import Enum
import sqlite3
supportedFitTypes = ["sine", "linear", "poly"]
supportedFoldedFitTypes = ["sine", "linear", "poly"]
class StarDBError(Enum):
NO_ERROR = 0
@@ -153,11 +153,12 @@ class StarDB():
self.connection.commit()
def updateFitType(self, mainName, fitType: str):
def updateFoldedFitType(self, mainName, fitType: str):
if(fitType in supportedFoldedFitTypes):
self.dbCursor.execute(f"""UPDATE starFoldedFitType
SET foldedFitType = '{fitType}'
WHERE mainName = '{mainName}';""")
print("Updating fit type for ", mainName, " to ", fitType)
self.dbCursor.execute(f"""INSERT OR REPLACE INTO
starFoldedFitType (mainName, foldedFitType)
VALUES ('{mainName}', '{fitType}');""")
self.connection.commit()
else:
raise Exception(f"Fit type {fitType} not supported, must be one of {supportedFitTypes}")
@@ -214,8 +215,15 @@ class StarDB():
def getFoldedFitType(self, mainName):
res = self.dbCursor.execute(f"""SELECT foldedFitType FROM starFoldedFitType
WHERE mainName = \"{mainName}\";""")
ret = res.fetchone()[0]
if(ret in supportedFoldedFitTypes):
return ret
else:
try:
ret = res.fetchone()[0]
print("Fit type for star ", mainName, ": ",ret)
if(ret in supportedFoldedFitTypes):
return ret
else:
print("fit type not supported, return default")
return "sine"
except Exception as e:
print("No custom fit type found, return default")
print(e)
return "sine"
+23 -4
View File
@@ -9,6 +9,7 @@ import lightkurve as lk
from ...flaredetector.util import *
from ...flaredetector.flaredetector import calculateFlareFitsForLightcurve
from ...astrodatagui.db.StarsDB import supportedFoldedFitTypes
class FlaredetectorWidget(QtWidgets.QWidget):
@@ -64,6 +65,8 @@ class FlaredetectorWidget(QtWidgets.QWidget):
def setFitsFile(self, fitsFilePath, mainName: str):
print(f"Plotting: {fitsFilePath}")
self.currentLC = lk.read(fitsFilePath)
if(isinstance(self.currentLC, lk.lightcurve.KeplerLightCurve)):
print(f"Kepler Quarter: {self.currentLC.hdu[0].header['QUARTER']}")
self.currentLCCollection = None
self.currentMainName = mainName
self.updateFit()
@@ -184,6 +187,17 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.ShowQualityState["Enabled"] = enabled
self.updatePlot()
def setFoldedFitType(self, foldedFitType):
print("Setting folded Fit Type")
if(foldedFitType in supportedFoldedFitTypes):
self.foldedFitType = foldedFitType
else:
print("Unsupported fit type:", foldedFitType)
print("Setting default: sine")
self.foldedFitType = "sine"
if(hasattr(self, "currentLC")):
self.updatePlot()
def normalizeStichedLightCurve(self, lc):
lc.flux = lc[self.fluxType]
lc.flux_err = lc[self.fluxErrType]
@@ -254,10 +268,15 @@ class FlaredetectorWidget(QtWidgets.QWidget):
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(lc, peak["StandardIndex"])
self.figureAxis.plot(lc.phase[lc.cycle == cycle][foldedIndex].value,
lc.flux[lc.cycle == cycle][foldedIndex], "x", color="red")
phase, sineFit, _ = getFoldedBestFit(lc)
self.figureAxis.plot(phase, sineFit, color="red")
minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase)
plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis)
try:
phase, sineFit, _ = getFoldedBestFit(lc, fitType=self.foldedFitType)
self.figureAxis.plot(phase, sineFit, color="red")
print(phase, sineFit)
minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase)
plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis)
except Exception as e:
print("Failed to get fit")
print(e)
elif(self.PeriodogramState["Enabled"]):
lc.plot(label=label, ax=self.figureAxis, view=self.PeriodogramState["View"])
if(self.PeriodogramState["View"] == "period"):
+15 -9
View File
@@ -3,6 +3,8 @@ from PyQt5.QtWidgets import QDialog, QListWidgetItem
from PyQt5 import uic
import os
from astropy.table import vstack
from ...astrodatadownloader.astrodatadownloader import (ObservationSource,
getStarObservations, downloadStarProducts)
@@ -49,16 +51,20 @@ class NewStarDialog(QDialog):
k2Kadences = [self.cbK2ShortCadence.isChecked(),
self.cbK2LongCadence.isChecked()]
obs = getStarObservations(star, keplerKadences, k2Kadences, sources)
if(len(obs) == 0):
self.showErrorMessage("No observations found",
"No observationnal data has been found with the current filters")
return
allObs = []
stars = star.split(";")
self.listPreview.clear()
for o in obs:
print(o)
self.listPreview.addItem(QListWidgetItem(f"{star} - {o['obs_collection']} - {o['sequence_number']}"))
for s in stars:
s = s.strip()
obs = getStarObservations(s, keplerKadences, k2Kadences, sources)
if(len(obs) == 0):
self.showErrorMessage("No observations found",
"No observationnal data has been found with the current filters")
return
allObs.append(obs)
for o in obs:
self.listPreview.addItem(QListWidgetItem(f"{s} - {o['obs_collection']} - {o['sequence_number']}"))
obs = vstack(allObs)
self.currentObservations = obs
self.starIdentifier = star