CalcAllFlaresThread: switch to executor.map
This commit is contained in:
@@ -5,15 +5,8 @@ import lightkurve as lk
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
||||||
|
|
||||||
def getFlareCount(filesDictList):
|
def getFlareCount(filesDict):
|
||||||
sapPeaksL = []
|
lc = lk.read(filesDict["FilePath"])
|
||||||
sapPeaksCountL = []
|
|
||||||
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.flux_err = lc["sap_flux_err"]
|
lc.flux_err = lc["sap_flux_err"]
|
||||||
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||||
@@ -21,26 +14,19 @@ def getFlareCount(filesDictList):
|
|||||||
lc.flux_err = lc["pdcsap_flux_err"]
|
lc.flux_err = lc["pdcsap_flux_err"]
|
||||||
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
|
||||||
|
|
||||||
sapPeaksL.append(sapPeaks)
|
filesDict["sapPeaks"] = sapPeaks
|
||||||
sapPeaksCountL.append(len(sapPeaks))
|
filesDict["sapPeaksCount"] = len(sapPeaks)
|
||||||
sapFitsL.append(sapFits)
|
filesDict["sapFits"] = sapFits
|
||||||
pdcsapPeaksL.append(pdcsapPeaks)
|
filesDict["pdcsapPeaks"] = pdcsapPeaks
|
||||||
pdcsapPeaksCountL.append(len(pdcsapPeaks))
|
filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
|
||||||
pdcsapFitsL.append(pdcsapFits)
|
filesDict["pdcsapFits"] = pdcsapFits
|
||||||
del lc
|
del lc
|
||||||
|
|
||||||
filesDictList["sapPeaks"] = sapPeaksL
|
return filesDict
|
||||||
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)
|
||||||
finished = pyqtSignal(list)
|
finished = pyqtSignal(pd.DataFrame)
|
||||||
|
|
||||||
def __init__(self, allFlaresDictList):
|
def __init__(self, allFlaresDictList):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -51,11 +37,7 @@ class CalcAllFlaresThread(QThread):
|
|||||||
cpuCount = multiprocessing.cpu_count()
|
cpuCount = multiprocessing.cpu_count()
|
||||||
splitList = [self.allFlaresDictList[i:i + cpuCount] for i in range(0, len(self.allFlaresDictList), cpuCount)]
|
splitList = [self.allFlaresDictList[i:i + cpuCount] for i in range(0, len(self.allFlaresDictList), cpuCount)]
|
||||||
executor = concurrent.futures.ProcessPoolExecutor(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