CalcAllFlaresThread: switch to executor.map
This commit is contained in:
@@ -5,42 +5,28 @@ import lightkurve as lk
|
||||
import pandas as pd
|
||||
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
||||
|
||||
def getFlareCount(filesDictList):
|
||||
sapPeaksL = []
|
||||
sapPeaksCountL = []
|
||||
sapFitsL = []
|
||||
pdcsapPeaksL = []
|
||||
pdcsapPeaksCountL = []
|
||||
pdcsapFitsL = []
|
||||
for ind in filesDictList.index:
|
||||
lc = lk.read(filesDictList["FilePath"][ind])
|
||||
lc.flux = lc["sap_flux"]
|
||||
lc.flux_err = lc["sap_flux_err"]
|
||||
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||
lc.flux = lc["pdcsap_flux"]
|
||||
lc.flux_err = lc["pdcsap_flux_err"]
|
||||
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||
def getFlareCount(filesDict):
|
||||
lc = lk.read(filesDict["FilePath"])
|
||||
lc.flux = lc["sap_flux"]
|
||||
lc.flux_err = lc["sap_flux_err"]
|
||||
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||
lc.flux = lc["pdcsap_flux"]
|
||||
lc.flux_err = lc["pdcsap_flux_err"]
|
||||
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||
|
||||
sapPeaksL.append(sapPeaks)
|
||||
sapPeaksCountL.append(len(sapPeaks))
|
||||
sapFitsL.append(sapFits)
|
||||
pdcsapPeaksL.append(pdcsapPeaks)
|
||||
pdcsapPeaksCountL.append(len(pdcsapPeaks))
|
||||
pdcsapFitsL.append(pdcsapFits)
|
||||
del lc
|
||||
filesDict["sapPeaks"] = sapPeaks
|
||||
filesDict["sapPeaksCount"] = len(sapPeaks)
|
||||
filesDict["sapFits"] = sapFits
|
||||
filesDict["pdcsapPeaks"] = pdcsapPeaks
|
||||
filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
|
||||
filesDict["pdcsapFits"] = pdcsapFits
|
||||
del lc
|
||||
|
||||
filesDictList["sapPeaks"] = sapPeaksL
|
||||
filesDictList["sapPeaksCount"] = sapPeaksCountL
|
||||
filesDictList["sapFits"] = sapFitsL
|
||||
filesDictList["pdcsapPeaks"] = pdcsapPeaksL
|
||||
filesDictList["pdcsapPeaksCount"] = pdcsapPeaksCountL
|
||||
filesDictList["pdcsapFits"] = pdcsapFitsL
|
||||
|
||||
return filesDictList
|
||||
return filesDict
|
||||
|
||||
class CalcAllFlaresThread(QThread):
|
||||
progress = pyqtSignal(int)
|
||||
finished = pyqtSignal(list)
|
||||
finished = pyqtSignal(pd.DataFrame)
|
||||
|
||||
def __init__(self, allFlaresDictList):
|
||||
super().__init__()
|
||||
@@ -51,11 +37,7 @@ class CalcAllFlaresThread(QThread):
|
||||
cpuCount = multiprocessing.cpu_count()
|
||||
splitList = [self.allFlaresDictList[i:i + cpuCount] for i in range(0, len(self.allFlaresDictList), cpuCount)]
|
||||
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
|
||||
futures = [executor.submit(getFlareCount, starDictPartList) for starDictPartList in splitList]
|
||||
concurrent.futures.wait(futures)
|
||||
ret = pd.DataFrame()
|
||||
for future in futures:
|
||||
retFrame = future.result()
|
||||
ret = pd.concat([ret, retFrame], ingore_index=True)
|
||||
|
||||
self.finished.emit(ret)
|
||||
resFrame = pd.DataFrame(executor.map(getFlareCount, self.allFlaresDictList.to_dict(orient="records")))
|
||||
|
||||
self.finished.emit(resFrame)
|
||||
Reference in New Issue
Block a user