astrodatagui: use pandas instead of lists for faster processing
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
from msilib import sequence
|
|
||||||
from PyQt5 import QtWidgets, uic, Qt
|
from PyQt5 import QtWidgets, uic, Qt
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from astroquery.simbad import Simbad
|
from astroquery.simbad import Simbad
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
from .db.StarsDB import StarDB
|
from .db.StarsDB import StarDB
|
||||||
from .ui.NewStarDialog import NewStarDialog
|
from .ui.NewStarDialog import NewStarDialog
|
||||||
@@ -359,7 +359,15 @@ class AstrodataGUI(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
def btCountAllFlaresClicked(self):
|
def btCountAllFlaresClicked(self):
|
||||||
if(self.calcAllFlaresThread is None):
|
if(self.calcAllFlaresThread is None):
|
||||||
allStarsDictList = []
|
allStarsDictList = pd.DataFrame(columns=["StarName",
|
||||||
|
"SpType",
|
||||||
|
"RotVel",
|
||||||
|
"RotVelUnit",
|
||||||
|
"Distance",
|
||||||
|
"DistanceUnit",
|
||||||
|
"Source",
|
||||||
|
"Sequence",
|
||||||
|
"FilePath"])
|
||||||
|
|
||||||
for starName in self.starDB.getAllStars():
|
for starName in self.starDB.getAllStars():
|
||||||
sequences = self.starDB.getStarSequences(starName)
|
sequences = self.starDB.getStarSequences(starName)
|
||||||
@@ -368,15 +376,9 @@ class AstrodataGUI(QtWidgets.QMainWindow):
|
|||||||
source = sourceSeq["Source"]
|
source = sourceSeq["Source"]
|
||||||
seq = sourceSeq["Sequence"]
|
seq = sourceSeq["Sequence"]
|
||||||
filePath = self.starDB.getFilePath(starName, source, seq)
|
filePath = self.starDB.getFilePath(starName, source, seq)
|
||||||
allStarsDictList.append({"StarName": starName,
|
allStarsDictList.loc[len(allStarsDictList.index)] = \
|
||||||
"SpType": infos["SpType"],
|
[starName, infos["SpType"], infos["RotVel"], infos["RotVelUnit"],
|
||||||
"RotVel": infos["RotVel"],
|
infos["Distance"], infos["DistanceUnit"], source, seq, filePath]
|
||||||
"RotVelUnit": infos["RotVelUnit"],
|
|
||||||
"Distance": infos["Distance"],
|
|
||||||
"DistanceUnit": infos["DistanceUnit"],
|
|
||||||
"Source": source,
|
|
||||||
"Sequence": seq,
|
|
||||||
"FilePath": filePath})
|
|
||||||
|
|
||||||
self.calcAllFlaresThread = CalcAllFlaresThread(allStarsDictList)
|
self.calcAllFlaresThread = CalcAllFlaresThread(allStarsDictList)
|
||||||
self.calcAllFlaresThread.finished.connect(self.btCountAllFlaresClickedDone)
|
self.calcAllFlaresThread.finished.connect(self.btCountAllFlaresClickedDone)
|
||||||
|
|||||||
@@ -2,31 +2,41 @@ from PyQt5.QtCore import pyqtSignal, QThread
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import lightkurve as lk
|
import lightkurve as lk
|
||||||
|
import pandas as pd
|
||||||
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
def getFlareCount(filesDictList):
|
def getFlareCount(filesDictList):
|
||||||
retDictList = []
|
sapPeaksL = []
|
||||||
for filesDict in filesDictList:
|
sapPeaksCountL = []
|
||||||
lc = lk.read(filesDict["FilePath"])
|
sapFitsL = []
|
||||||
|
pdcsapPeaksL = []
|
||||||
|
pdcsapPeaksCountL = []
|
||||||
|
pdcsapFitsL = []
|
||||||
|
for ind in filesDictList.index:
|
||||||
|
lc = lk.read(filesDictList["FilePath"][ind])
|
||||||
lc.flux = lc["sap_flux"]
|
lc.flux = lc["sap_flux"]
|
||||||
lc_flattenend = lc.flatten()
|
lc.flux_err = lc["sap_flux_err"]
|
||||||
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc_flattenend)
|
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||||
lc.flux = lc["pdcsap_flux"]
|
lc.flux = lc["pdcsap_flux"]
|
||||||
lc_flattenend = lc.flatten()
|
lc.flux_err = lc["pdcsap_flux_err"]
|
||||||
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc_flattenend)
|
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||||
|
|
||||||
retDict = filesDict
|
sapPeaksL.append(sapPeaks)
|
||||||
retDict["sapPeaks"] = sapPeaks
|
sapPeaksCountL.append(len(sapPeaks))
|
||||||
retDict["sapPeaksCount"] = len(sapPeaks)
|
sapFitsL.append(sapFits)
|
||||||
retDict["sapFits"] = sapFits
|
pdcsapPeaksL.append(pdcsapPeaks)
|
||||||
retDict["pdcsapPeaks"] = pdcsapPeaks
|
pdcsapPeaksCountL.append(len(pdcsapPeaks))
|
||||||
retDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
|
pdcsapFitsL.append(pdcsapFits)
|
||||||
retDict["pdcsapFits"] = pdcsapFits
|
del lc
|
||||||
retDictList.append(retDict)
|
|
||||||
|
|
||||||
return retDictList
|
filesDictList["sapPeaks"] = sapPeaksL
|
||||||
|
filesDictList["sapPeaksCount"] = sapPeaksCountL
|
||||||
|
filesDictList["sapFits"] = sapFitsL
|
||||||
|
filesDictList["pdcsapPeaks"] = pdcsapPeaksL
|
||||||
|
filesDictList["pdcsapPeaksCount"] = pdcsapPeaksCountL
|
||||||
|
filesDictList["pdcsapFits"] = pdcsapFitsL
|
||||||
|
|
||||||
|
return filesDictList
|
||||||
|
|
||||||
class CalcAllFlaresThread(QThread):
|
class CalcAllFlaresThread(QThread):
|
||||||
progress = pyqtSignal(int)
|
progress = pyqtSignal(int)
|
||||||
@@ -43,10 +53,9 @@ class CalcAllFlaresThread(QThread):
|
|||||||
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
|
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
|
||||||
futures = [executor.submit(getFlareCount, starDictPartList) for starDictPartList in splitList]
|
futures = [executor.submit(getFlareCount, starDictPartList) for starDictPartList in splitList]
|
||||||
concurrent.futures.wait(futures)
|
concurrent.futures.wait(futures)
|
||||||
ret = []
|
ret = pd.DataFrame()
|
||||||
for future in futures:
|
for future in futures:
|
||||||
retList = future.result()
|
retFrame = future.result()
|
||||||
for dic in retList:
|
ret = pd.concat([ret, retFrame], ingore_index=True)
|
||||||
ret.append(dic)
|
|
||||||
|
|
||||||
self.finished.emit(ret)
|
self.finished.emit(ret)
|
||||||
Reference in New Issue
Block a user