way too many updates
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
@@ -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>
|
||||
|
||||
@@ -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"
|
||||
@@ -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"):
|
||||
|
||||
@@ -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
|
||||
|
||||
+182
-46
@@ -94,8 +94,8 @@ def fitPolynomial(phase, flux, degree):
|
||||
def linear(t, k, d):
|
||||
return k*t + d
|
||||
|
||||
def fitLinear(phase, flux, degree):
|
||||
popt, _ = curve_fit(linear, phase, flux, maxfev=300)
|
||||
def fitLinear(phase, flux):
|
||||
popt, _ = curve_fit(linear, phase, flux, maxfev=3000)
|
||||
return linear(phase, *popt)
|
||||
|
||||
def compureRSS(fit, flux):
|
||||
@@ -122,14 +122,23 @@ def getFoldedBestFit(foldedLc, fitType="sine"):
|
||||
flux = flux[filt]
|
||||
polyDegree = 7
|
||||
fitThreshold = 0.0
|
||||
smoothed_flux = np.convolve(flux, np.ones(len(flux)//100)/(len(flux)//100), mode="valid")
|
||||
peaks, _ = find_peaks(smoothed_flux, height=np.mean(smoothed_flux))
|
||||
#print("Num peaks: ", peaks)
|
||||
|
||||
if(fitType == "sine"):
|
||||
retFit = fitSingleSine(phase, flux)
|
||||
try:
|
||||
print("using sine")
|
||||
retFit = fitSingleSine(phase, flux)
|
||||
except: # if its supposed to be a sine, but we cant find one, use a polynomial
|
||||
print("Use polynomial instead")
|
||||
retFit = fitPolynomial(phase, flux, polyDegree)
|
||||
fitType = "poly"
|
||||
elif(fitType == "poly"):
|
||||
retFit = fitPolynomial(phase, flux, polyDegree)
|
||||
try:
|
||||
print("using poly")
|
||||
retFit = fitPolynomial(phase, flux, polyDegree)
|
||||
except: # other way around for poly to sine
|
||||
print("Use sine instead")
|
||||
retFit = fitSingleSine(phase, flux)
|
||||
fitType = "sine"
|
||||
elif(fitType == "linear"):
|
||||
retFit = fitLinear(phase, flux)
|
||||
else:
|
||||
@@ -174,6 +183,27 @@ def getFoldedFitPeakValley(sineFit):
|
||||
else:
|
||||
maxima = np.array((len(sineFit)-1), ndmin=1)
|
||||
|
||||
# TODO: if theres a minima and maxima extremely close to the edge of data, remove them
|
||||
if(len(minima) > 1 and len(maxima) > 1):
|
||||
lenArray = len(sineFit)
|
||||
minBorder = lenArray * 0.05
|
||||
maxBorder = lenArray - minBorder
|
||||
minInBorder = -1
|
||||
maxInBorder = -1
|
||||
for mini in minima:
|
||||
if(mini < minBorder or mini > maxBorder):
|
||||
minInBorder = mini
|
||||
break
|
||||
for maxi in maxima:
|
||||
if(maxi < minBorder or maxi > maxBorder):
|
||||
maxInBorder = maxi
|
||||
break
|
||||
if(minInBorder > 0 and maxInBorder > 0):
|
||||
indMin = np.argwhere(minima == minInBorder)
|
||||
indMax = np.argwhere(maxima == maxInBorder)
|
||||
minima = np.delete(minima, indMin)
|
||||
maxima = np.delete(maxima, indMax)
|
||||
|
||||
return minima, maxima
|
||||
|
||||
def findNearestIndexOfValue(array, value):
|
||||
@@ -185,47 +215,153 @@ def getPhaseRangesNearPeak(maxArgs, phase, returnPhaseValue=False):
|
||||
minPhases = phase[maxArgs[0]]
|
||||
maxPhases = phase[maxArgs[1]]
|
||||
totalPhase = abs(phase[0]) + abs(phase[-1])
|
||||
|
||||
phasePart = totalPhase * 0.3 / (len(minPhases) + len(maxPhases))
|
||||
minPhasesBounds = []
|
||||
for minPhase in minPhases:
|
||||
minPhaseBounds = []
|
||||
if(minPhase - phasePart < phase[0]):
|
||||
minPhaseBounds.append((phase[0], minPhase + phasePart))
|
||||
minPhaseBounds.append((phase[-1] + (minPhase - phasePart - phase[0]), phase[-1]))
|
||||
elif(minPhase + phasePart > phase[-1]):
|
||||
minPhaseBounds.append((minPhase - phasePart, phase[-1]))
|
||||
minPhaseBounds.append((phase[0], phase[0] + (minPhase + phasePart - phase[-1])))
|
||||
else:
|
||||
minPhaseBounds.append((minPhase - phasePart, minPhase + phasePart))
|
||||
minPhasesBounds.append(minPhaseBounds)
|
||||
|
||||
maxPhasesBounds = []
|
||||
for maxPhase in maxPhases:
|
||||
maxPhaseBounds = []
|
||||
if(maxPhase - phasePart < phase[0]):
|
||||
maxPhaseBounds.append((phase[0], maxPhase + phasePart))
|
||||
maxPhaseBounds.append((phase[-1] + (maxPhase - phasePart - phase[0]), phase[-1]))
|
||||
elif(maxPhase + phasePart > phase[-1]):
|
||||
maxPhaseBounds.append((maxPhase - phasePart, phase[-1]))
|
||||
maxPhaseBounds.append((phase[0], phase[0] + (maxPhase + phasePart - phase[-1])))
|
||||
else:
|
||||
maxPhaseBounds.append((maxPhase - phasePart, maxPhase + phasePart))
|
||||
maxPhasesBounds.append(maxPhaseBounds)
|
||||
|
||||
minPhasesBoundsIndices = []
|
||||
for minPhaseBounds in minPhasesBounds:
|
||||
minPhaseBoundsIndices = []
|
||||
for l in minPhaseBounds:
|
||||
minPhaseBoundsIndices.append([phase[findNearestIndexOfValue(phase, lv)] if returnPhaseValue else findNearestIndexOfValue(phase, lv) for lv in l])
|
||||
minPhasesBoundsIndices.append(minPhaseBoundsIndices)
|
||||
|
||||
maxPhasesBoundsIndices = []
|
||||
for maxPhaseBounds in maxPhasesBounds:
|
||||
maxPhaseBoundsIndices = []
|
||||
for l in maxPhaseBounds:
|
||||
maxPhaseBoundsIndices.append([phase[findNearestIndexOfValue(phase, lv)] if returnPhaseValue else findNearestIndexOfValue(phase, lv) for lv in l])
|
||||
maxPhasesBoundsIndices.append(maxPhaseBoundsIndices)
|
||||
|
||||
if((len(minPhases) + len(maxPhases)) > 0):
|
||||
phasePart = totalPhase * 0.4 / (len(minPhases) + len(maxPhases))
|
||||
minPhasesBounds = []
|
||||
for minPhase in minPhases:
|
||||
minPhaseBounds = []
|
||||
if(minPhase - phasePart < phase[0]):
|
||||
minPhaseBounds.append([phase[0], minPhase + phasePart])
|
||||
minPhaseBounds.append([phase[-1] + minPhase - phasePart - phase[0], phase[-1]])
|
||||
elif(minPhase + phasePart > phase[-1]):
|
||||
minPhaseBounds.append([minPhase - phasePart, phase[-1]])
|
||||
minPhaseBounds.append([phase[0], phase[0] + minPhase + phasePart - phase[-1]])
|
||||
else:
|
||||
minPhaseBounds.append([minPhase - phasePart, minPhase + phasePart])
|
||||
minPhasesBounds.append(minPhaseBounds)
|
||||
|
||||
maxPhasesBounds = []
|
||||
for maxPhase in maxPhases:
|
||||
maxPhaseBounds = []
|
||||
if(maxPhase - phasePart < phase[0]):
|
||||
maxPhaseBounds.append([phase[0], maxPhase + phasePart])
|
||||
maxPhaseBounds.append([phase[-1] + maxPhase - phasePart - phase[0], phase[-1]])
|
||||
elif(maxPhase + phasePart > phase[-1]):
|
||||
maxPhaseBounds.append([maxPhase - phasePart, phase[-1]])
|
||||
maxPhaseBounds.append([phase[0], phase[0] + maxPhase + phasePart - phase[-1]])
|
||||
else:
|
||||
maxPhaseBounds.append([maxPhase - phasePart, maxPhase + phasePart])
|
||||
maxPhasesBounds.append(maxPhaseBounds)
|
||||
|
||||
i = 0; j = 0
|
||||
while i < len(minPhasesBounds) and j < len(maxPhasesBounds):
|
||||
#print(f"i: {i}", f"j: {j}")
|
||||
if(len(minPhasesBounds[i]) == 1):
|
||||
start_min, end_min = minPhasesBounds[i][0]
|
||||
elif(len(minPhasesBounds[i]) == 2):
|
||||
start_min, end_min = minPhasesBounds[i]
|
||||
|
||||
if(len(maxPhasesBounds[j]) == 1):
|
||||
start_max, end_max = maxPhasesBounds[j][0]
|
||||
elif(len(maxPhasesBounds[j]) == 2):
|
||||
start_max, end_max = maxPhasesBounds[j]
|
||||
|
||||
#print(f"start_min type {type(start_min)}, {start_min}")
|
||||
#print(f"end_min type {type(end_min)}, {end_min}")
|
||||
#print(f"start_max type {type(start_max)}, {start_max}")
|
||||
#print(f"end_max type {type(end_max)}, {end_max}")
|
||||
|
||||
if(isinstance(start_min, np.float64) and isinstance(end_min, np.float64) and
|
||||
isinstance(start_max, np.float64) and isinstance(end_max, np.float64)):
|
||||
#print("Case 1")
|
||||
if(start_max < end_min and start_max > start_min):
|
||||
overlap_start = max(start_min, start_max)
|
||||
overlap_end = min(end_min, end_max)
|
||||
midpoint = (overlap_start + overlap_end) / 2
|
||||
|
||||
minPhasesBounds[i] = [[start_min, midpoint - 0.01]]
|
||||
maxPhasesBounds[j] = [[midpoint + 0.01, end_max]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
elif(start_min < end_max and start_max < start_min):
|
||||
overlap_start = max(start_min, start_max)
|
||||
overlap_end = min(end_min, end_max)
|
||||
midpoint = (overlap_start + overlap_end) / 2
|
||||
|
||||
minPhasesBounds[i] = [[midpoint + 0.01, end_min]]
|
||||
maxPhasesBounds[j] = [[start_max, midpoint - 0.01]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
else:
|
||||
if end_min < start_max:
|
||||
i += 1
|
||||
elif end_max < start_min:
|
||||
j += 1
|
||||
elif(isinstance(start_max, np.float64) and isinstance(end_max, np.float64)): # Case 2
|
||||
#print("Case 2")
|
||||
if(start_min[0] < end_min[0]):
|
||||
start_min1, end_min1 = start_min[0], start_min[1]
|
||||
start_min2, end_min2 = end_min[0], end_min[1]
|
||||
else:
|
||||
start_min2, end_min2 = start_min[0], start_min[1]
|
||||
start_min1, end_min1 = end_min[0], end_min[1]
|
||||
if(start_max < start_min2 and end_max > start_min2): # 1
|
||||
midpoint = (start_min2 + end_max) / 2
|
||||
|
||||
minPhasesBounds[i] = [[start_min1, end_min1], [midpoint + 0.01, end_min2]]
|
||||
maxPhasesBounds[j] = [[start_max, midpoint - 0.01]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
elif(start_max > start_min1 and start_max < end_min1): # 2
|
||||
midpoint = (start_max + end_min1) / 2
|
||||
|
||||
minPhasesBounds[i] = [[start_min1, midpoint - 0.01], [start_min2, end_min2]]
|
||||
maxPhasesBounds[j] = [[midpoint + 0.01, end_max]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
else:
|
||||
i += 1
|
||||
j += 1
|
||||
elif(isinstance(start_min, np.float64) and isinstance(end_min, np.float64)): # Case 3
|
||||
#print("Case 3")
|
||||
if(start_max[0] < end_max[0]):
|
||||
start_max1, end_max1 = start_max[0], start_max[1]
|
||||
start_max2, end_max2 = end_max[0], end_max[1]
|
||||
else:
|
||||
start_max2, end_max2 = start_max[0], start_max[1]
|
||||
start_max1, end_max1 = end_max[0], end_max[1]
|
||||
if(start_min > start_max1 and start_min < end_max1): # 1
|
||||
midpoint = (start_min + end_max1) / 2
|
||||
|
||||
minPhasesBounds[i] = [[midpoint + 0.01, end_min]]
|
||||
maxPhasesBounds[j] = [[start_max1, midpoint - 0.01], [start_max2, end_max2]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
elif(start_min < start_max2 and end_min > start_max2): # 2
|
||||
midpoint = (start_max2 + end_min) / 2
|
||||
|
||||
minPhasesBounds[i] = [[start_min, midpoint - 0.01]]
|
||||
maxPhasesBounds[j] = [[start_max1, end_max1], [midpoint + 0.01, end_max2]]
|
||||
|
||||
i += 1
|
||||
j += 1
|
||||
else:
|
||||
i += 1
|
||||
j += 1
|
||||
else:
|
||||
print("Rare case of both going over the border, this shouldnt happen, remove them")
|
||||
minPhasesBounds.pop(i)
|
||||
maxPhasesBounds.pop(j)
|
||||
|
||||
for minPhaseBounds in minPhasesBounds:
|
||||
minPhaseBoundsIndices = []
|
||||
for l in minPhaseBounds:
|
||||
minPhaseBoundsIndices.append([phase[findNearestIndexOfValue(phase, lv)] if returnPhaseValue else findNearestIndexOfValue(phase, lv) for lv in l])
|
||||
minPhasesBoundsIndices.append(minPhaseBoundsIndices)
|
||||
|
||||
for maxPhaseBounds in maxPhasesBounds:
|
||||
maxPhaseBoundsIndices = []
|
||||
for l in maxPhaseBounds:
|
||||
maxPhaseBoundsIndices.append([phase[findNearestIndexOfValue(phase, lv)] if returnPhaseValue else findNearestIndexOfValue(phase, lv) for lv in l])
|
||||
maxPhasesBoundsIndices.append(maxPhaseBoundsIndices)
|
||||
|
||||
return minPhasesBoundsIndices, maxPhasesBoundsIndices
|
||||
|
||||
|
||||
Reference in New Issue
Block a user