Compare commits

14 Commits

5 changed files with 764 additions and 678 deletions
+84
View File
@@ -0,0 +1,84 @@
import pandas as pd
import numpy as np
from main.astrodatagui.db.StarsDB import StarDB
db: StarDB = StarDB.getInstance("stars.db")
starMainIDs = db.getAllStars()
resFull = []
resUsed = []
resUnused = []
fullData = pd.read_pickle("datav5.1.cff")
usedMstars = pd.read_csv("../large sized plots/2025-5-31-sine/M/M_starlist.csv", header=0, names=["StarName"])
usedKstars = pd.read_csv("../large sized plots/2025-5-31-sine/K/K_starlist.csv", header=0, names=["StarName"])
usedGstars = pd.read_csv("../large sized plots/2025-5-31-sine/G/G_starlist.csv", header=0, names=["StarName"])
usedFstars = pd.read_csv("../large sized plots/2025-5-31-sine/F/F_starlist.csv", header=0, names=["StarName"])
for mainID in starMainIDs:
altNames = db.getStarAltNames(mainID)
infos = db.getStarInfos(mainID)
kicName = "-"
ticName = "-"
spType = "-"
for name in altNames:
if name[0].startswith("TIC"):
ticName = name[0]
if name[0].startswith("KIC"):
kicName = name[0]
spType = infos["SpType"]
hasValidSineFit = fullData[(fullData["StarName"] == mainID) & (fullData["FitType"] == "sine")]["isValidFold"].any()
hasValidPolyFit = fullData[(fullData["StarName"] == mainID) & (fullData["FitType"] == "poly")]["isValidFold"].any()
hasValidLinearFit = fullData[(fullData["StarName"] == mainID) & (fullData["FitType"] == "linear")]["isValidFold"].any()
fitTypeString = []
if(hasValidSineFit): fitTypeString.append("sine")
if(hasValidPolyFit): fitTypeString.append("poly")
if(hasValidLinearFit): fitTypeString.append("linear")
fitTypeString = ', '.join(fitTypeString)
resFull.append({"MainID": mainID,
"Spectral Type": spType,
"TIC": ticName,
"KIC": kicName,
"Fit Types": fitTypeString})
if((usedMstars["StarName"] == mainID).any() or (usedKstars["StarName"] == mainID).any() or
(usedGstars["StarName"] == mainID).any() or (usedFstars["StarName"] == mainID).any()):
resUsed.append({"MainID": mainID,
"Spectral Type": spType,
"TIC": ticName,
"KIC": kicName,
"Fit Types": fitTypeString})
else:
resUnused.append({"MainID": mainID,
"Spectral Type": spType,
"TIC": ticName,
"KIC": kicName,
"Fit Types": fitTypeString})
resFull = pd.DataFrame(resFull)
resFull.sort_values(by=["Spectral Type", "MainID"])
resUsed = pd.DataFrame(resUsed)
resUsed.sort_values(by=["Spectral Type", "MainID"])
resUnused = pd.DataFrame(resUnused)
resUnused.sort_values(by=["Spectral Type", "MainID"])
for sptype in ["M", "K", "G", "F"]:
texFile = open(f"table_{sptype}_used.tex", "w")
tex = resUsed[resUsed["Spectral Type"].str.startswith(sptype)].sort_values(by=["Spectral Type", "MainID"]).to_latex(index=False)
texFile.write(tex)
texFile.close()
texFile = open(f"table_full.tex", "w")
tex = resFull.sort_values(by=["Spectral Type", "MainID"]).to_latex(index=False)
texFile.write(tex)
texFile.close()
texFile = open(f"table_unused.tex", "w")
tex = resUnused.sort_values(by=["Spectral Type", "MainID"]).to_latex(index=False)
texFile.write(tex)
texFile.close()
+300 -212
View File
@@ -1,3 +1,4 @@
from math import comb
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import itertools import itertools
@@ -9,6 +10,22 @@ from datetime import datetime
from errno import EEXIST from errno import EEXIST
from os import makedirs, path from os import makedirs, path
import shutil import shutil
import multiprocessing
import concurrent.futures
from concurrent.futures import wait, ALL_COMPLETED
from functools import partial
SMALL_SIZE = 16
MEDIUM_SIZE = 18
BIGGER_SIZE = 20
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=MEDIUM_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
def normalizePhase(phase, phaseMin = None, phaseMax = None): def normalizePhase(phase, phaseMin = None, phaseMax = None):
if(phaseMin is None): if(phaseMin is None):
@@ -27,41 +44,6 @@ def mkdir_p(mypath):
pass pass
else: raise else: raise
fileName = "datav5.1.cff"
data = pd.read_pickle(fileName)
binList = [10, 20, 30]
spType = ["M", "K", "G", "F"]
useKepler = True
useK2 = True
useTESS = True
showSourceFilter = np.full(len(data), False)
if(useKepler):
showKepler = data["Source"] == "Kepler"
showSourceFilter |= showKepler
if(useK2):
showK2 = data["Source"] == "K2"
showSourceFilter |= showK2
if(useTESS):
showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS
current = datetime.now()
date = f"{current.year}-{current.month}-{current.day}"
time = f"{current.hour}-{current.minute}-{current.second}"
folderPath = f"../{date}-sine-poly/"
#folderPath = f"G:/Meine Ablage/Masterthesis/{date}/"
mkdir_p(folderPath)
# remove any data that has no period
#data = data[(data["FitType"] == "sine") | (data["FitType"] == "poly")]
data = data[((data["FitType"] == "sine") | (data["FitType"] == "poly")) & (data["isValidFold"])]
validStarPeriodMap = []
starList = set(list(data["StarName"]))
def allValuesWithin3Std(values: list): def allValuesWithin3Std(values: list):
if(not values or len(values) == 1): if(not values or len(values) == 1):
return True return True
@@ -71,19 +53,6 @@ def allValuesWithin3Std(values: list):
def getMeanPeriod(values: list): def getMeanPeriod(values: list):
return np.mean(values) return np.mean(values)
for starName in starList:
periods = list(data[data["StarName"] == starName]["pdcsapPeriod"])
validStarPeriodMap.append({"StarName": starName,
"MeanPeriod": getMeanPeriod(periods),
"PeriodWithinStd": allValuesWithin3Std(periods)})
validStarPeriodMap = pd.DataFrame(validStarPeriodMap)
periodsCutList = [0.5, 1, 1.5, 2, 5, 10, 15, 20]
data = pd.merge(data, validStarPeriodMap, on="StarName")
starDB: StarDB = StarDB.getInstance("stars.db")
def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, title, filename, foldedFits): def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, title, filename, foldedFits):
figHisto, ((axHisto)) = plt.subplots(nrows=1, ncols=1) figHisto, ((axHisto)) = plt.subplots(nrows=1, ncols=1)
y, binEdges, _ = axHisto.hist(PDCSAPdataList, bins, y, binEdges, _ = axHisto.hist(PDCSAPdataList, bins,
@@ -113,10 +82,10 @@ def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, ti
quit() quit()
axHisto.set_ylabel("Num. flares") axHisto.set_ylabel("Num. flares")
axHisto.set_xlabel("Phase") axHisto.set_xlabel("Phase")
axHisto.set_title(title) axHisto.set_title(title, wrap=True)
axHisto.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$')) axHisto.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axHisto.xaxis.set_major_locator(MaxNLocator(5)) axHisto.xaxis.set_major_locator(MaxNLocator(5))
axHisto.legend() axHisto.legend(loc="lower right")
axHistoPhase = axHisto.twinx() axHistoPhase = axHisto.twinx()
if(foldedFits is None): if(foldedFits is None):
@@ -129,9 +98,11 @@ def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, ti
axHistoPhase.plot(fit[0], fit[1], color="blue") axHistoPhase.plot(fit[0], fit[1], color="blue")
fitCol = [fit[1] for fit in foldedFits] fitCol = [fit[1] for fit in foldedFits]
fitCol = np.array(list(itertools.chain.from_iterable(fitCol))) fitCol = np.array(list(itertools.chain.from_iterable(fitCol)))
if(len(fitCol) == 0):
fitCol = np.array([0, 1])
axHistoPhase.set_ylim(np.min(fitCol), np.max(fitCol)*1.2) axHistoPhase.set_ylim(np.min(fitCol), np.max(fitCol)*1.2)
plt.savefig(filename) plt.savefig(filename, bbox_inches="tight")
plt.close() plt.close()
def plotFlarePhasePeakHistogram(xData, yData, bins, maxY, title, filename): def plotFlarePhasePeakHistogram(xData, yData, bins, maxY, title, filename):
@@ -147,8 +118,8 @@ def plotFlarePhasePeakHistogram(xData, yData, bins, maxY, title, filename):
figFlarepeakHist.colorbar(im, label='Counts', ax=axFlarepeakHist) figFlarepeakHist.colorbar(im, label='Counts', ax=axFlarepeakHist)
axFlarepeakHist.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$')) axFlarepeakHist.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarepeakHist.xaxis.set_major_locator(MaxNLocator(5)) axFlarepeakHist.xaxis.set_major_locator(MaxNLocator(5))
axFlarepeakHist.set_title(title) axFlarepeakHist.set_title(title, wrap=True)
plt.savefig(filename) plt.savefig(filename, bbox_inches="tight")
plt.close() plt.close()
def plotFlarePeaks(plotdata, filters, labels, colors, maxY, title, filename): def plotFlarePeaks(plotdata, filters, labels, colors, maxY, title, filename):
@@ -175,15 +146,15 @@ def plotFlarePeaks(plotdata, filters, labels, colors, maxY, title, filename):
axFlarePeaks.set_ylim(0.99, maxY) axFlarePeaks.set_ylim(0.99, maxY)
axFlarePeaks.set_ylabel("Flare peak") axFlarePeaks.set_ylabel("Flare peak")
axFlarePeaks.set_xlabel("Phase") axFlarePeaks.set_xlabel("Phase")
axFlarePeaks.set_title(title) axFlarePeaks.set_title(title, wrap=True)
axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$')) axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5)) axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5))
axFlarePeaks.legend() axFlarePeaks.legend(loc="lower right")
plt.savefig(filename) plt.savefig(filename, bbox_inches="tight")
plt.close() plt.close()
def setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, def setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, pdcsapbinningData,
PDCSAPdataList=None, dataFilter=None): pdcsapbinningDataColumn, PDCSAPdataList=None, dataFilter=None):
xData = pd.DataFrame() xData = pd.DataFrame()
yData = pd.DataFrame() yData = pd.DataFrame()
for aX, aY in zip(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak): for aX, aY in zip(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak):
@@ -194,9 +165,9 @@ def setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
yData = np.asarray(yData.values)[:,0] yData = np.asarray(yData.values)[:,0]
if(PDCSAPdataList is not None): if(PDCSAPdataList is not None):
if(dataFilter is not None): if(dataFilter is not None):
PDCSAPdataList.append(pdcsapbinningData[dataFilter]["PDCSAPNormPhase"]) PDCSAPdataList.append(pdcsapbinningData[dataFilter][pdcsapbinningDataColumn])
else: else:
PDCSAPdataList.append(pdcsapbinningData[:]["PDCSAPNormPhase"]) PDCSAPdataList.append(pdcsapbinningData[:][pdcsapbinningDataColumn])
return xData, yData, PDCSAPdataList return xData, yData, PDCSAPdataList
@@ -219,8 +190,7 @@ def generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, histogramTit
flarePlotFilename = flarePlotFilenameArg.replace("@maxY", str(maxY)) flarePlotFilename = flarePlotFilenameArg.replace("@maxY", str(maxY))
plotFlarePeaks(plotdata, filters, flarePlotLabels, flarePlotColors, maxY, flarePlotTitle, flarePlotFilename) plotFlarePeaks(plotdata, filters, flarePlotLabels, flarePlotColors, maxY, flarePlotTitle, flarePlotFilename)
# All stars def plotStar(data, showSourceFilter, folderPath, starName):
for starName in starDB.getAllStars():
finalData = pd.DataFrame() finalData = pd.DataFrame()
starNameR = starName.replace('*', '_star_') starNameR = starName.replace('*', '_star_')
nameFilter = data["StarName"] == starName nameFilter = data["StarName"] == starName
@@ -228,9 +198,7 @@ for starName in starDB.getAllStars():
finalData = pd.concat([finalData, data[nameFilter]], ignore_index=True) finalData = pd.concat([finalData, data[nameFilter]], ignore_index=True)
pdcsapbinningData = [] pdcsapbinningData = []
pdcsapbinningDataSpotModDiffPeriod = []
foldedFits = [] foldedFits = []
foldedPeriodFits = []
locFolder = f"{folderPath}/stars/{starNameR}/" locFolder = f"{folderPath}/stars/{starNameR}/"
mkdir_p(f"{locFolder}/") mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{starNameR}.csv", "a") csvFile = open(f"{locFolder}/{starNameR}.csv", "a")
@@ -252,25 +220,14 @@ for starName in starDB.getAllStars():
if(peak["FlarePeak"] > 100): if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak") print(row["StarName"], "has over 100 peak")
foldedFits.append([normalizePhase(row["pdcsapFoldedFitPhase"]), row["pdcsapFoldedFit"]]) foldedFits.append([normalizePhase(row["pdcsapFoldedFitPhase"]), row["pdcsapFoldedFit"]])
if(row["pdcsapPeriodFoldedPhase"] is not None):
periodPdcsapVals = pd.DataFrame(row["pdcsapPeriodFoldedPeaksPhasePair"])
for td, peak in zip(periodPdcsapVals["Phase"], periodPdcsapVals["Peak"]):
normPhasePeriod = normalizePhase(td.value, np.abs(row["pdcsapPeriodFoldedFitPhaseStarEnd"][0]), np.abs(row["pdcsapPeriodFoldedFitPhaseStarEnd"][1]))
pdcsapbinningDataSpotModDiffPeriod.append({"SpType": f'{row["SpType"][0:2] if len(row["SpType"]) > 1 else row["SpType"][0]}',
"PDCSAPNormPhasePeriod": normPhasePeriod,
"PeakPeriod": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
foldedPeriodFits.append([normalizePhase(row["pdcsapPeriodFoldedFitPhase"]), row["pdcsapPeriodFoldedFit"]])
csvFile.close() csvFile.close()
pdcsapbinningData = pd.DataFrame(pdcsapbinningData) pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
pdcsapbinningDataSpotModDiffPeriod = pd.DataFrame(pdcsapbinningDataSpotModDiffPeriod) if len(pdcsapbinningDataSpotModDiffPeriod) > 0 else None
PDCSAPdataList = [] PDCSAPdataList = []
PDCSAPlabelList = [] PDCSAPlabelList = []
PDCSAPcolorList = [] PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = [] PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = [] PDCSAPdataList2dhistPeak = []
if(len(pdcsapbinningData) > 0): if(len(pdcsapbinningData) > 0):
if(pdcsapbinningData["SpType"][0][0] == "M"): if(pdcsapbinningData["SpType"][0][0] == "M"):
color = "red" color = "red"
@@ -286,30 +243,64 @@ for starName in starDB.getAllStars():
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[:]["PDCSAPNormPhase"]) PDCSAPdataList2dhistPhase.append(pdcsapbinningData[:]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[:]["Peak"]) PDCSAPdataList2dhistPeak.append(pdcsapbinningData[:]["Peak"])
xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, PDCSAPdataList) xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningData, "PDCSAPNormPhase",
PDCSAPdataList)
PDCSAPlabelList.append(f"{starName}")
PDCSAPcolorList.append(color) PDCSAPcolorList.append(color)
generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarecount-@bins_Bins.png", generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarecount-@bins_Bins.png",
xData, yData, f"Flare peak per phase histogram of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarepeaks-@bins_Bins_maxY-@maxY.png", xData, yData, f"Flare peak per phase histogram of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
pdcsapbinningData, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY.png", pdcsapbinningData, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY.png",
foldedFits) foldedFits)
def plotStarPeriod(data, showSourceFilter, folderPath, starName):
finalData = pd.DataFrame()
starNameR = starName.replace('*', '_star_')
nameFilter = data["StarName"] == starName
nameFilter &= showSourceFilter
finalData = pd.concat([finalData, data[nameFilter]], ignore_index=True)
pdcsapbinningDataSpotModDiffPeriod = []
foldedPeriodFits = []
locFolder = f"{folderPath}/stars/{starNameR}/"
mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{starNameR}_Period.csv", "a")
csvFile.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Spot Modulation,Normalized Phase of Peak,Peak in Period")
csvFile.write("\n")
for ind, row in finalData.reset_index().iterrows():
PDCSAPminOrigPhase = row["pdcsapPeriodFoldedFitPhaseStarEnd"][0]
PDCSAPmaxOrigPhase = row["pdcsapPeriodFoldedFitPhaseStarEnd"][1]
if(len(row["pdcsapPeriodFoldedPeaksPhasePair"]) > 0):
pdcsapVals = pd.DataFrame(row["pdcsapPeriodFoldedPeaksPhasePair"])
for td, peak, pv in zip(pdcsapVals["Phase"], pdcsapVals["Peak"], row["pdcsapPeaks"]):
normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase))
csvFile.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{row['pdcsapSpotModulation']},{normPhase},{peak['FlarePeak']}")
csvFile.write("\n")
pdcsapbinningDataSpotModDiffPeriod.append({"SpType": f'{row["SpType"][0:2] if len(row["SpType"]) > 1 else row["SpType"][0]}',
"PDCSAPNormPhasePeriod": normPhase,
"PeakPeriod": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
foldedPeriodFits.append([normalizePhase(row["pdcsapPeriodFoldedFitPhase"]), row["pdcsapPeriodFoldedFit"]])
csvFile.close()
pdcsapbinningDataSpotModDiffPeriod = pd.DataFrame(pdcsapbinningDataSpotModDiffPeriod) if len(pdcsapbinningDataSpotModDiffPeriod) > 0 else None
if(pdcsapbinningDataSpotModDiffPeriod is not None): if(pdcsapbinningDataSpotModDiffPeriod is not None):
PDCSAPdataList = [] PDCSAPdataListPeriod = []
PDCSAPlabelList = [] PDCSAPlabelList = []
PDCSAPcolorList = [] PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = [] PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = [] PDCSAPdataList2dhistPeak = []
if(pdcsapbinningData["SpType"][0][0] == "M"): if(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "M"):
color = "red" color = "red"
elif(pdcsapbinningData["SpType"][0][0] == "K"): elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "K"):
color = "orange" color = "orange"
elif(pdcsapbinningData["SpType"][0][0] == "G"): elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "G"):
color = "yellow" color = "yellow"
elif(pdcsapbinningData["SpType"][0][0] == "F"): elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "F"):
color = "greenyellow" color = "greenyellow"
else: else:
color = "gray" color = "gray"
@@ -317,19 +308,115 @@ for starName in starDB.getAllStars():
PDCSAPdataList2dhistPhase.append(pdcsapbinningDataSpotModDiffPeriod[:]["PDCSAPNormPhasePeriod"]) PDCSAPdataList2dhistPhase.append(pdcsapbinningDataSpotModDiffPeriod[:]["PDCSAPNormPhasePeriod"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningDataSpotModDiffPeriod[:]["PeakPeriod"]) PDCSAPdataList2dhistPeak.append(pdcsapbinningDataSpotModDiffPeriod[:]["PeakPeriod"])
xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, PDCSAPdataList) xData, yData, PDCSAPdataListPeriod = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningDataSpotModDiffPeriod, "PDCSAPNormPhasePeriod",
PDCSAPdataListPeriod)
PDCSAPlabelList.append(f"{starName}") PDCSAPlabelList.append(f"{starName}")
PDCSAPcolorList.append(color) PDCSAPcolorList.append(color)
generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarecount-@bins_Bins_Period.png", generatePlots(PDCSAPdataListPeriod, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarecount-@bins_Bins_Period.png",
xData, yData, f"Flare peak per phase histogram of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarepeaks-@bins_Bins_maxY-@maxY_Period.png", xData, yData, f"Flare peak per phase histogram of {starName} with @bins bins", f"{locFolder}/{starNameR}-Flarepeaks-@bins_Bins_maxY-@maxY_Period.png",
pdcsapbinningDataSpotModDiffPeriod, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY_Period.png", pdcsapbinningDataSpotModDiffPeriod, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY_Period.png",
foldedPeriodFits) foldedPeriodFits)
for comboLength in range(1, len(spType) + 1): def plotCombo(data, showSourceFilter, folderPath, combo):
for combo in itertools.combinations(spType, comboLength): # all flare peaks
finalDataAllFlarePeaks = pd.DataFrame()
if("M" in combo):
Mfilter = data["SpType"].str.startswith("M")
Mfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Mfilter]], ignore_index=True)
if("K" in combo):
Kfilter = data["SpType"].str.startswith("K")
Kfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Kfilter]], ignore_index=True)
if("G" in combo):
Gfilter = data["SpType"].str.startswith("G")
Gfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Gfilter]], ignore_index=True)
if("F" in combo):
Ffilter = data["SpType"].str.startswith("F")
Ffilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Ffilter]], ignore_index=True)
pdcsapbinningDataAllFlarePeaks = []
locFolder = f"{folderPath}/{''.join(combo)}/"
mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{''.join(combo)}.csv", "a")
csvFile.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Normalized Phase of Peak,Peak in Period")
csvFile.write("\n")
for ind, row in finalDataAllFlarePeaks.reset_index().iterrows():
PDCSAPminOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][0]
PDCSAPmaxOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][1]
if(len(row["pdcsapFoldedPeaksPhasePair"]) > 0):
pdcsapVals = pd.DataFrame(row["pdcsapFoldedPeaksPhasePair"])
for td, peak, pv in zip(pdcsapVals["Phase"], pdcsapVals["Peak"], row["pdcsapPeaks"]):
normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase))
csvFile.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{normPhase},{peak['FlarePeak']}")
csvFile.write("\n")
pdcsapbinningDataAllFlarePeaks.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
csvFile.close()
if(len(pdcsapbinningDataAllFlarePeaks) > 0):
pdcsapbinningDataAllFlarePeaks = pd.DataFrame(pdcsapbinningDataAllFlarePeaks)
numStarsAllFLarePeaks = len(set(pdcsapbinningDataAllFlarePeaks["StarName"]))
pd.DataFrame(set(pdcsapbinningDataAllFlarePeaks["StarName"])).to_csv(f"{locFolder}/{''.join(combo)}_starlist.csv")
PDCSAPdataListDataAllFlarePeaks = []
PDCSAPlabelListDataAllFlarePeaks = []
PDCSAPcolorListDataAllFlarePeaks = []
PDCSAPdataList2dhistPhaseDataAllFlarePeaks = []
PDCSAPdataList2dhistPeakDataAllFlarePeaks = []
PDCSAPlabelList2dhistDataAllFlarePeaks = []
PDCSAPcolorList2dhistDataAllFlarePeaks = []
plotFiltersDataAllFlarePeaks = []
if("M" in combo):
MfilterDataAllFlarePeaks = pdcsapbinningDataAllFlarePeaks["SpType"] == "M"
PDCSAPdataList2dhistPhaseDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[MfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[MfilterDataAllFlarePeaks]["Peak"])
PDCSAPdataListDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[MfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPlabelListDataAllFlarePeaks.append("M Stars")
PDCSAPcolorListDataAllFlarePeaks.append("red")
plotFiltersDataAllFlarePeaks.append(MfilterDataAllFlarePeaks)
if("K" in combo):
KfilterDataAllFlarePeaks = pdcsapbinningDataAllFlarePeaks["SpType"] == "K"
PDCSAPdataList2dhistPhaseDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[KfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[KfilterDataAllFlarePeaks]["Peak"])
PDCSAPdataListDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[KfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPlabelListDataAllFlarePeaks.append("K Stars")
PDCSAPcolorListDataAllFlarePeaks.append("orange")
plotFiltersDataAllFlarePeaks.append(KfilterDataAllFlarePeaks)
if("G" in combo):
GfilterDataAllFlarePeaks = pdcsapbinningDataAllFlarePeaks["SpType"] == "G"
PDCSAPdataList2dhistPhaseDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[GfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[GfilterDataAllFlarePeaks]["Peak"])
PDCSAPdataListDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[GfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPlabelListDataAllFlarePeaks.append("G Stars")
PDCSAPcolorListDataAllFlarePeaks.append("yellow")
plotFiltersDataAllFlarePeaks.append(GfilterDataAllFlarePeaks)
if("F" in combo):
FfilterDataAllFlarePeaks = pdcsapbinningDataAllFlarePeaks["SpType"] == "F"
PDCSAPdataList2dhistPhaseDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[FfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[FfilterDataAllFlarePeaks]["Peak"])
PDCSAPdataListDataAllFlarePeaks.append(pdcsapbinningDataAllFlarePeaks[FfilterDataAllFlarePeaks]["PDCSAPNormPhase"])
PDCSAPlabelListDataAllFlarePeaks.append("F Stars")
PDCSAPcolorListDataAllFlarePeaks.append("greenyellow")
plotFiltersDataAllFlarePeaks.append(FfilterDataAllFlarePeaks)
xDataDataAllFlarePeaks, yDataDataAllFlarePeaks, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseDataAllFlarePeaks, PDCSAPdataList2dhistPeakDataAllFlarePeaks,
pdcsapbinningDataAllFlarePeaks, "PDCSAPNormPhase")
generatePlots(PDCSAPdataListDataAllFlarePeaks, PDCSAPlabelListDataAllFlarePeaks, PDCSAPcolorListDataAllFlarePeaks, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStarsAllFLarePeaks} stars)", f"{locFolder}/{''.join(combo)}-Flarecount-@bins_Bins.png",
xDataDataAllFlarePeaks, yDataDataAllFlarePeaks, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStarsAllFLarePeaks} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
pdcsapbinningDataAllFlarePeaks, plotFiltersDataAllFlarePeaks, PDCSAPlabelListDataAllFlarePeaks, PDCSAPcolorListDataAllFlarePeaks, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStarsAllFLarePeaks} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks_maxY-@maxY.png")
for maxFlarePeak in [1.01, 1.05, 1.1, 1.25, 1.5]: for maxFlarePeak in [1.01, 1.05, 1.1, 1.25, 1.5]:
# max Flare Peak cut # max Flare Peak cut
finalDataMaxFlarePeak = pd.DataFrame() finalDataMaxFlarePeak = pd.DataFrame()
@@ -350,8 +437,6 @@ for comboLength in range(1, len(spType) + 1):
Ffilter &= showSourceFilter Ffilter &= showSourceFilter
finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Ffilter]], ignore_index=True) finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Ffilter]], ignore_index=True)
numStars = len(set(finalDataMaxFlarePeak["StarName"]))
pdcsapbinningDataU = [] pdcsapbinningDataU = []
pdcsapbinningDataO = [] pdcsapbinningDataO = []
locFolderU = f"{folderPath}/{''.join(combo)}/maxFlarePeaks/{maxFlarePeak}/" locFolderU = f"{folderPath}/{''.join(combo)}/maxFlarePeaks/{maxFlarePeak}/"
@@ -376,7 +461,8 @@ for comboLength in range(1, len(spType) + 1):
csvFileU.write("\n") csvFileU.write("\n")
pdcsapbinningDataU.append({"SpType": row["SpType"][0], pdcsapbinningDataU.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase, "PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]}) "Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100): if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak") print(row["StarName"], "has over 100 peak")
else: else:
@@ -385,7 +471,8 @@ for comboLength in range(1, len(spType) + 1):
csvFileO.write("\n") csvFileO.write("\n")
pdcsapbinningDataO.append({"SpType": row["SpType"][0], pdcsapbinningDataO.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase, "PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]}) "Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100): if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak") print(row["StarName"], "has over 100 peak")
@@ -393,6 +480,8 @@ for comboLength in range(1, len(spType) + 1):
csvFileO.close() csvFileO.close()
if(len(pdcsapbinningDataU) > 0): if(len(pdcsapbinningDataU) > 0):
pdcsapbinningDataU = pd.DataFrame(pdcsapbinningDataU) pdcsapbinningDataU = pd.DataFrame(pdcsapbinningDataU)
numStarsFlarePeakU = len(set(pdcsapbinningDataU["StarName"]))
pd.DataFrame(set(pdcsapbinningDataU["StarName"])).to_csv(f"{locFolderU}/{''.join(combo)}_starlist.csv")
PDCSAPdataListU = [] PDCSAPdataListU = []
PDCSAPlabelListU = [] PDCSAPlabelListU = []
PDCSAPcolorListU = [] PDCSAPcolorListU = []
@@ -432,14 +521,16 @@ for comboLength in range(1, len(spType) + 1):
PDCSAPcolorListU.append("greenyellow") PDCSAPcolorListU.append("greenyellow")
plotFiltersU.append(Ffilter) plotFiltersU.append(Ffilter)
xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU) xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU,
generatePlots(PDCSAPdataListU, PDCSAPlabelListU, PDCSAPcolorListU, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarecount-@bins_Bins.png", pdcsapbinningDataU, "PDCSAPNormPhase")
xData, yData, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarepeaks-@bins_Bins_maxY-@maxY.png", generatePlots(PDCSAPdataListU, PDCSAPlabelListU, PDCSAPcolorListU, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStarsFlarePeakU} stars)", f"{locFolderU}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarecount-@bins_Bins.png",
pdcsapbinningDataU, plotFiltersU, PDCSAPlabelListU, PDCSAPcolorListU, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStars} stars)", f"{locFolder}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarepeaks_maxY-@maxY.png") xData, yData, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStarsFlarePeakU} stars)", f"{locFolderU}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
pdcsapbinningDataU, plotFiltersU, PDCSAPlabelListU, PDCSAPcolorListU, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStarsFlarePeakU} stars)", f"{locFolderU}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarepeaks_maxY-@maxY.png")
if(len(pdcsapbinningDataO) > 0): if(len(pdcsapbinningDataO) > 0):
pdcsapbinningDataO = pd.DataFrame(pdcsapbinningDataO) pdcsapbinningDataO = pd.DataFrame(pdcsapbinningDataO)
numStarsFlarePeakO = len(set(pdcsapbinningDataO["StarName"]))
pd.DataFrame(set(pdcsapbinningDataO["StarName"])).to_csv(f"{locFolderO}/{''.join(combo)}_starlist.csv")
PDCSAPdataListO = [] PDCSAPdataListO = []
PDCSAPlabelListO = [] PDCSAPlabelListO = []
PDCSAPcolorListO = [] PDCSAPcolorListO = []
@@ -479,104 +570,13 @@ for comboLength in range(1, len(spType) + 1):
PDCSAPcolorListO.append("greenyellow") PDCSAPcolorListO.append("greenyellow")
plotFiltersO.append(Ffilter) plotFiltersO.append(Ffilter)
xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO) xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO,
generatePlots(PDCSAPdataListO, PDCSAPlabelListO, PDCSAPcolorListO, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarecount-@bins_Bins.png", pdcsapbinningDataO, "PDCSAPNormPhase")
xData, yData, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarepeaks-@bins_Bins_maxY-@maxY.png", generatePlots(PDCSAPdataListO, PDCSAPlabelListO, PDCSAPcolorListO, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStarsFlarePeakO} stars)", f"{locFolderO}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarecount-@bins_Bins.png",
pdcsapbinningDataO, plotFiltersO, PDCSAPlabelListO, PDCSAPcolorListO, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStars} stars)", f"{locFolder}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarepeaks_maxY-@maxY.png") xData, yData, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStarsFlarePeakO} stars)", f"{locFolderO}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
# all flare peaks pdcsapbinningDataO, plotFiltersO, PDCSAPlabelListO, PDCSAPcolorListO, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStarsFlarePeakO} stars)", f"{locFolderO}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}-Flarepeaks_maxY-@maxY.png")
finalDataAllFlarePeaks = pd.DataFrame()
if("M" in combo):
Mfilter = data["SpType"].str.startswith("M")
Mfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Mfilter]], ignore_index=True)
if("K" in combo):
Kfilter = data["SpType"].str.startswith("K")
Kfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Kfilter]], ignore_index=True)
if("G" in combo):
Gfilter = data["SpType"].str.startswith("G")
Gfilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Gfilter]], ignore_index=True)
if("F" in combo):
Ffilter = data["SpType"].str.startswith("F")
Ffilter &= showSourceFilter
finalDataAllFlarePeaks = pd.concat([finalDataAllFlarePeaks, data[Ffilter]], ignore_index=True)
numStars = len(set(finalDataAllFlarePeaks["StarName"])) if(len(combo) == 1):
pdcsapbinningData = []
locFolder = f"{folderPath}/{''.join(combo)}/"
mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{''.join(combo)}.csv", "a")
csvFile.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Normalized Phase of Peak,Peak in Period")
csvFile.write("\n")
for ind, row in finalDataAllFlarePeaks.reset_index().iterrows():
PDCSAPminOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][0]
PDCSAPmaxOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][1]
if(len(row["pdcsapFoldedPeaksPhasePair"]) > 0):
pdcsapVals = pd.DataFrame(row["pdcsapFoldedPeaksPhasePair"])
for td, peak, pv in zip(pdcsapVals["Phase"], pdcsapVals["Peak"], row["pdcsapPeaks"]):
normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase))
csvFile.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{normPhase},{peak['FlarePeak']}")
csvFile.write("\n")
pdcsapbinningData.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
csvFile.close()
if(len(pdcsapbinningData) > 0):
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
PDCSAPdataList = []
PDCSAPlabelList = []
PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = []
PDCSAPlabelList2dhist = []
PDCSAPcolorList2dhist = []
plotFilters = []
if("M" in combo):
Mfilter = pdcsapbinningData["SpType"] == "M"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Mfilter]["Peak"])
PDCSAPdataList.append(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"])
PDCSAPlabelList.append("M Stars")
PDCSAPcolorList.append("red")
plotFilters.append(Mfilter)
if("K" in combo):
Kfilter = pdcsapbinningData["SpType"] == "K"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Kfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Kfilter]["Peak"])
PDCSAPdataList.append(pdcsapbinningData[Kfilter]["PDCSAPNormPhase"])
PDCSAPlabelList.append("K Stars")
PDCSAPcolorList.append("orange")
plotFilters.append(Kfilter)
if("G" in combo):
Gfilter = pdcsapbinningData["SpType"] == "G"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Gfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Gfilter]["Peak"])
PDCSAPdataList.append(pdcsapbinningData[Gfilter]["PDCSAPNormPhase"])
PDCSAPlabelList.append("G Stars")
PDCSAPcolorList.append("yellow")
plotFilters.append(Gfilter)
if("F" in combo):
Ffilter = pdcsapbinningData["SpType"] == "F"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Ffilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Ffilter]["Peak"])
PDCSAPdataList.append(pdcsapbinningData[Ffilter]["PDCSAPNormPhase"])
PDCSAPlabelList.append("F Stars")
PDCSAPcolorList.append("greenyellow")
plotFilters.append(Ffilter)
xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak)
plotdata = pdcsapbinningData
filters = plotFilters
generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}-Flarecount-@bins_Bins.png",
xData, yData, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
plotdata, filters, PDCSAPlabelList, PDCSAPcolorList, f"Flare peaks per phase of {', '.join(combo)} type stars ({numStars} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks_maxY-@maxY.png")
if(comboLength == 1):
mainSpType = combo[0] mainSpType = combo[0]
spTypes = [f"{mainSpType}0", f"{mainSpType}1", f"{mainSpType}2", f"{mainSpType}3", f"{mainSpType}4", f"{mainSpType}5", f"{mainSpType}6", f"{mainSpType}7", f"{mainSpType}8", f"{mainSpType}9"] spTypes = [f"{mainSpType}0", f"{mainSpType}1", f"{mainSpType}2", f"{mainSpType}3", f"{mainSpType}4", f"{mainSpType}5", f"{mainSpType}6", f"{mainSpType}7", f"{mainSpType}8", f"{mainSpType}9"]
match mainSpType: match mainSpType:
@@ -593,7 +593,6 @@ for comboLength in range(1, len(spType) + 1):
finalDataAccSpTypes = pd.DataFrame() finalDataAccSpTypes = pd.DataFrame()
typeFilter = data["SpType"].str.startswith(spTyp) typeFilter = data["SpType"].str.startswith(spTyp)
numStars = len(set(data[typeFilter]["StarName"]))
typeFilter &= showSourceFilter typeFilter &= showSourceFilter
finalDataAccSpTypes = pd.concat([finalDataAccSpTypes, data[typeFilter]], ignore_index=True) finalDataAccSpTypes = pd.concat([finalDataAccSpTypes, data[typeFilter]], ignore_index=True)
@@ -614,12 +613,15 @@ for comboLength in range(1, len(spType) + 1):
csvFile.write("\n") csvFile.write("\n")
pdcsapbinningData.append({"SpType": f'{row["SpType"][0]}{row["SpType"][1]}', pdcsapbinningData.append({"SpType": f'{row["SpType"][0]}{row["SpType"][1]}',
"PDCSAPNormPhase": normPhase, "PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]}) "Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100): if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak") print(row["StarName"], "has over 100 peak")
csvFile.close() csvFile.close()
if(len(pdcsapbinningData) > 0): if(len(pdcsapbinningData) > 0):
pdcsapbinningData = pd.DataFrame(pdcsapbinningData) pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
numStarsAccSpType = len(set(pdcsapbinningData["StarName"]))
pd.DataFrame(set(pdcsapbinningData["StarName"])).to_csv(f"{locFolder}/{spTyp}_starlist.csv")
PDCSAPdataList = [] PDCSAPdataList = []
PDCSAPlabelList = [] PDCSAPlabelList = []
PDCSAPcolorList = [] PDCSAPcolorList = []
@@ -636,13 +638,15 @@ for comboLength in range(1, len(spType) + 1):
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[SpTypefilter]["Peak"]) PDCSAPdataList2dhistPeak.append(pdcsapbinningData[SpTypefilter]["Peak"])
PDCSAPlabelList.append(f"{spTyp} Stars") PDCSAPlabelList.append(f"{spTyp} Stars")
PDCSAPcolorList.append(color) PDCSAPcolorList.append(color)
xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, PDCSAPdataList, SpTypefilter) xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningData, "PDCSAPNormPhase",
PDCSAPdataList, SpTypefilter)
plotdata = pdcsapbinningData plotdata = pdcsapbinningData
filters = SpTypefilter filters = SpTypefilter
generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {spTyp} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(spTyp)}-Flarecount-@bins_Bins.png", generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count in phase of {spTyp} type stars with @bins bins ({numStarsAccSpType} stars)", f"{locFolder}/{''.join(spTyp)}-Flarecount-@bins_Bins.png",
xData, yData, f"Flare peak per phase histogram of {spTyp} type stars with @bins bins ({numStars} stars)", f"{locFolder}/{''.join(spTyp)}-Flarepeaks-@bins_Bins_maxY-@maxY.png", xData, yData, f"Flare peak per phase histogram of {spTyp} type stars with @bins bins ({numStarsAccSpType} stars)", f"{locFolder}/{''.join(spTyp)}-Flarepeaks-@bins_Bins_maxY-@maxY.png",
plotdata, filters, PDCSAPlabelList[0], PDCSAPcolorList[0], f"Flare peaks per phase of {spTyp} type stars ({numStars} stars)", f"{locFolder}/{''.join(spTyp)}-Flarepeaks_maxY-@maxY.png") plotdata, filters, PDCSAPlabelList[0], PDCSAPcolorList[0], f"Flare peaks per phase of {spTyp} type stars ({numStarsAccSpType} stars)", f"{locFolder}/{''.join(spTyp)}-Flarepeaks_maxY-@maxY.png")
# per Period # per Period
for periodCut in periodsCutList: for periodCut in periodsCutList:
@@ -686,17 +690,19 @@ for comboLength in range(1, len(spType) + 1):
for td, peak, pv in zip(pdcsapVals["Phase"], pdcsapVals["Peak"], row["pdcsapPeaks"]): for td, peak, pv in zip(pdcsapVals["Phase"], pdcsapVals["Peak"], row["pdcsapPeaks"]):
normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase)) normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase))
if(row["MeanPeriod"] <= periodCut): if(row["MeanPeriod"] <= periodCut):
csvFileU.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{row["MeanPeriod"]},{normPhase},{peak['FlarePeak']}") csvFileU.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{row['MeanPeriod']},{normPhase},{peak['FlarePeak']}")
csvFileU.write("\n") csvFileU.write("\n")
pdcsapbinningDataU.append({"SpType": f'{row["SpType"][0]}', pdcsapbinningDataU.append({"SpType": f'{row["SpType"][0]}',
"PDCSAPNormPhase": normPhase, "PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]}) "Peak": peak["FlarePeak"],
"StarName": row['StarName']})
else: else:
csvFileO.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{row["MeanPeriod"]},{normPhase},{peak['FlarePeak']}") csvFileO.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{row['MeanPeriod']},{normPhase},{peak['FlarePeak']}")
csvFileO.write("\n") csvFileO.write("\n")
pdcsapbinningDataO.append({"SpType": f'{row["SpType"][0]}', pdcsapbinningDataO.append({"SpType": f'{row["SpType"][0]}',
"PDCSAPNormPhase": normPhase, "PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]}) "Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100): if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak") print(row["StarName"], "has over 100 peak")
csvFileU.close() csvFileU.close()
@@ -724,6 +730,8 @@ for comboLength in range(1, len(spType) + 1):
PDCSAPcolorList.append("greenyellow") PDCSAPcolorList.append("greenyellow")
if(len(pdcsapbinningDataU) > 0): if(len(pdcsapbinningDataU) > 0):
numStarsPeriodU = len(set(pdcsapbinningDataU["StarName"]))
pd.DataFrame(set(pdcsapbinningDataU["StarName"])).to_csv(f"{locFolder}/under_{periodCut}_starlist.csv")
if("M" in combo): if("M" in combo):
MfilterU = pdcsapbinningDataU["SpType"] == "M" MfilterU = pdcsapbinningDataU["SpType"] == "M"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[MfilterU]["PDCSAPNormPhase"]) PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[MfilterU]["PDCSAPNormPhase"])
@@ -750,6 +758,8 @@ for comboLength in range(1, len(spType) + 1):
plotFiltersU.append(FfilterU) plotFiltersU.append(FfilterU)
if(len(pdcsapbinningDataO) > 0): if(len(pdcsapbinningDataO) > 0):
numStarsPeriodO = len(set(pdcsapbinningDataO["StarName"]))
pd.DataFrame(set(pdcsapbinningDataO["StarName"])).to_csv(f"{locFolder}/over_{periodCut}_starlist.csv")
if("M" in combo): if("M" in combo):
MfilterO = pdcsapbinningDataO["SpType"] == "M" MfilterO = pdcsapbinningDataO["SpType"] == "M"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[MfilterO]["PDCSAPNormPhase"]) PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[MfilterO]["PDCSAPNormPhase"])
@@ -776,16 +786,94 @@ for comboLength in range(1, len(spType) + 1):
plotFiltersO.append(FfilterO) plotFiltersO.append(FfilterO)
if(len(PDCSAPdataList2dhistPhaseU) > 0 and len(PDCSAPdataList2dhistPeakU) > 0): if(len(PDCSAPdataList2dhistPhaseU) > 0 and len(PDCSAPdataList2dhistPeakU) > 0):
xDataU, yDataU, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU) xDataU, yDataU, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU,
pdcsapbinningDataU, "PDCSAPNormPhase",)
if(len(PDCSAPdataListU) > 0 and len(xDataU) > 0 and len(yDataU) > 0): if(len(PDCSAPdataListU) > 0 and len(xDataU) > 0 and len(yDataU) > 0):
generatePlots(PDCSAPdataListU, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins (Rot. Period under {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarecount-Period_u_{periodCut}-@bins_Bins.png", generatePlots(PDCSAPdataListU, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins (Rot. Period under {periodCut} days, {numStarsPeriodU} stars)", f"{locFolder}/{''.join(combo)}-Flarecount-Period_u_{periodCut}-@bins_Bins.png",
xDataU, yDataU, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins (Rot. Period under {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_u_{periodCut}-@bins_Bins_maxY-@maxY.png", xDataU, yDataU, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins (Rot. Period under {periodCut} days, {numStarsPeriodU} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_u_{periodCut}-@bins_Bins_maxY-@maxY.png",
pdcsapbinningDataU, plotFiltersU, PDCSAPlabelList, PDCSAPcolorList, f"Flare peaks per phase of {', '.join(combo)} type stars (Rot. Period under {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_u_{periodCut}-maxY_@maxY.png") pdcsapbinningDataU, plotFiltersU, PDCSAPlabelList, PDCSAPcolorList, f"Flare peaks per phase of {', '.join(combo)} type stars (Rot. Period under {periodCut} days, {numStarsPeriodU} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_u_{periodCut}-maxY_@maxY.png")
if(len(PDCSAPdataList2dhistPhaseO) > 0 and len(PDCSAPdataList2dhistPeakO) > 0): if(len(PDCSAPdataList2dhistPhaseO) > 0 and len(PDCSAPdataList2dhistPeakO) > 0):
xDataO, yDataO, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO) xDataO, yDataO, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO,
pdcsapbinningDataO, "PDCSAPNormPhase",)
if(len(PDCSAPdataListO) > 0 and len(xDataO) > 0 and len(yDataO) > 0): if(len(PDCSAPdataListO) > 0 and len(xDataO) > 0 and len(yDataO) > 0):
generatePlots(PDCSAPdataListO, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins (Rot. Period over {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarecount-Period_o_{periodCut}-@bins_Bins.png", generatePlots(PDCSAPdataListO, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins (Rot. Period over {periodCut} days, {numStarsPeriodO} stars)", f"{locFolder}/{''.join(combo)}-Flarecount-Period_o_{periodCut}-@bins_Bins.png",
xDataO, yDataO, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins (Rot. Period over {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_o_{periodCut}-@bins_Bins_maxY-@maxY.png", xDataO, yDataO, f"Flare peak per phase histogram of {', '.join(combo)} type stars with @bins bins (Rot. Period over {periodCut} days, {numStarsPeriodO} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_o_{periodCut}-@bins_Bins_maxY-@maxY.png",
pdcsapbinningDataO, plotFiltersO, PDCSAPlabelList, PDCSAPcolorList, f"Flare peaks per phase of {', '.join(combo)} type stars (Rot. Period over {periodCut} days)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_o_{periodCut}-maxY_@maxY.png") pdcsapbinningDataO, plotFiltersO, PDCSAPlabelList, PDCSAPcolorList, f"Flare peaks per phase of {', '.join(combo)} type stars (Rot. Period over {periodCut} days, {numStarsPeriodO} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_o_{periodCut}-maxY_@maxY.png")
binList = [10, 20, 30]
spType = ["M", "K", "G", "F"]
periodsCutList = [0.5, 1, 1.5, 2, 5, 10, 15, 20]
if __name__ == "__main__":
fileName = "datav5.1.cff"
fullData = pd.read_pickle(fileName)
starDB: StarDB = StarDB.getInstance("stars.db")
allStars = starDB.getAllStars()
useKepler = True
useK2 = True
useTESS = True
current = datetime.now()
date = f"{current.year}-{current.month}-{current.day}"
time = f"{current.hour}-{current.minute}-{current.second}"
cpuCount = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=cpuCount)
foldedFitTypes = ["sine", "poly"]
for foldedFitTypesLength in range(1, len(foldedFitTypes)+1):
for foldedFitTypeCombo in itertools.combinations(foldedFitTypes, foldedFitTypesLength):
folderPath = f"../{date}-{'-'.join(foldedFitTypeCombo)}/"
mkdir_p(folderPath)
foldedFitTypeComboFilter = np.full(len(fullData), False)
foldedFitTypeComboFilterPeriod = np.full(len(fullData), False)
if("sine" in foldedFitTypeCombo):
foldedFitTypeComboFilter |= fullData["FitType"] == "sine"
foldedFitTypeComboFilterPeriod |= fullData["periodFitType"] == "sine"
if("poly" in foldedFitTypeCombo):
foldedFitTypeComboFilter |= fullData["FitType"] == "poly"
foldedFitTypeComboFilterPeriod |= fullData["periodFitType"] == "poly"
data = fullData[(foldedFitTypeComboFilter) & (fullData["isValidFold"])]
dataPeriod = fullData[(foldedFitTypeComboFilterPeriod) & (fullData["isValidFold"])]
showSourceFilter = np.full(len(data), False)
if(useKepler):
showKepler = data["Source"] == "Kepler"
showSourceFilter |= showKepler
if(useK2):
showK2 = data["Source"] == "K2"
showSourceFilter |= showK2
if(useTESS):
showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS
validStarPeriodMap = []
starList = set(list(data["StarName"]))
for starName in starList:
periods = list(data[data["StarName"] == starName]["pdcsapPeriod"])
validStarPeriodMap.append({"StarName": starName,
"MeanPeriod": getMeanPeriod(periods),
"PeriodWithinStd": allValuesWithin3Std(periods)})
validStarPeriodMap = pd.DataFrame(validStarPeriodMap)
data = pd.merge(data, validStarPeriodMap, on="StarName")
#starPlotFunc = partial(plotStar, data, showSourceFilter, folderPath)
#list(pool.map(starPlotFunc, allStars)) # wrap in list, to force evaluation
#starPlotPeriodFunc = partial(plotStarPeriod, dataPeriod, showSourceFilter, folderPath)
#list(pool.map(starPlotPeriodFunc, allStars)) # wrap in list, to force evaluation
combos = []
for comboLength in range(1, len(spType) + 1):
for combo in itertools.combinations(spType, comboLength):
combos.append(combo)
plotComboFunc = partial(plotCombo, data, showSourceFilter, folderPath)
list(pool.map(plotComboFunc, combos)) # wrap in list, to force evaluation
+19 -7
View File
@@ -15,6 +15,18 @@ from errno import EEXIST
from os import makedirs, path from os import makedirs, path
from datetime import datetime from datetime import datetime
SMALL_SIZE = 16
MEDIUM_SIZE = 18
BIGGER_SIZE = 20
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=MEDIUM_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
def mkdir_p(mypath): def mkdir_p(mypath):
'''Creates a directory. equivalent to using mkdir -p on the command line''' '''Creates a directory. equivalent to using mkdir -p on the command line'''
@@ -48,13 +60,13 @@ def getFlareCount(filesDict):
lc.plot() lc.plot()
plt.title(f"{starName} - normalized lightcurve") plt.title(f"{starName} - normalized lightcurve")
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-lc.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-lc.png", bbox_inches="tight")
plt.close() plt.close()
flattenedLc = lc.flatten() flattenedLc = lc.flatten()
flattenedLc.plot() flattenedLc.plot()
plt.title(f"{starName} - flattened lightcurve") plt.title(f"{starName} - flattened lightcurve")
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-flattened_lc.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-flattened_lc.png", bbox_inches="tight")
plt.close() plt.close()
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(flattenedLc, normalizedLC=lc) pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(flattenedLc, normalizedLC=lc)
@@ -64,7 +76,7 @@ def getFlareCount(filesDict):
plt.plot(p["FlarePeakTime"].value, lc.flux[p["StandardIndex"]], "x", color="red") plt.plot(p["FlarePeakTime"].value, lc.flux[p["StandardIndex"]], "x", color="red")
plt.plot([], [], "x", color="red", label="Flare peaks") plt.plot([], [], "x", color="red", label="Flare peaks")
plt.legend() plt.legend()
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-lc-marked_flares.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-lc-marked_flares.png", bbox_inches="tight")
plt.close() plt.close()
flattenedLc.plot() flattenedLc.plot()
@@ -76,7 +88,7 @@ def getFlareCount(filesDict):
plt.plot(p["FlarePeakTime"].value, p["FlarePeak"], "x", color="red") plt.plot(p["FlarePeakTime"].value, p["FlarePeak"], "x", color="red")
plt.plot([], [], "x", color="red", label="Flare peaks") plt.plot([], [], "x", color="red", label="Flare peaks")
plt.legend() plt.legend()
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-flattened_lc-marked_flares.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-flattened_lc-marked_flares.png", bbox_inches="tight")
plt.close() plt.close()
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux") pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
@@ -86,7 +98,7 @@ def getFlareCount(filesDict):
pdcsapPeriodogram.plot(view="period") pdcsapPeriodogram.plot(view="period")
plt.plot(pdcsapPeakPeriod, pdcsapPeriodogram.power[maxPeriodIndex], "x", color="red") plt.plot(pdcsapPeakPeriod, pdcsapPeriodogram.power[maxPeriodIndex], "x", color="red")
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-periodogram-marked_max.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-periodogram-marked_max.png", bbox_inches="tight")
plt.close() plt.close()
#pdcsapEpochTime = getEpochTime(lc) #pdcsapEpochTime = getEpochTime(lc)
@@ -108,7 +120,7 @@ def getFlareCount(filesDict):
optimizedFit["foldedLC"].flux[optimizedFit["foldedLC"].cycle == cycle][foldedIndex], "x", color="red") optimizedFit["foldedLC"].flux[optimizedFit["foldedLC"].cycle == cycle][foldedIndex], "x", color="red")
plt.plot([], [], "x", color="red", label="Flare peaks") plt.plot([], [], "x", color="red", label="Flare peaks")
plt.legend() plt.legend()
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-foldedLC-marked_fit_flares.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-foldedLC-marked_fit_flares.png", bbox_inches="tight")
plt.close() plt.close()
if(optimizedFit["periodFoldedLC"] is not None): if(optimizedFit["periodFoldedLC"] is not None):
@@ -123,7 +135,7 @@ def getFlareCount(filesDict):
optimizedFit["periodFoldedLC"].flux[optimizedFit["periodFoldedLC"].cycle == cycle][foldedIndex], "x", color="red") optimizedFit["periodFoldedLC"].flux[optimizedFit["periodFoldedLC"].cycle == cycle][foldedIndex], "x", color="red")
plt.plot([], [], "x", color="red", label="Flare peaks") plt.plot([], [], "x", color="red", label="Flare peaks")
plt.legend() plt.legend()
plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-periodFoldedLC-marked_fit_flares.png") plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-periodFoldedLC-marked_fit_flares.png", bbox_inches="tight")
plt.close() plt.close()
filesDict["pdcsapPeaks"] = pdcsapPeaks filesDict["pdcsapPeaks"] = pdcsapPeaks
+66 -164
View File
@@ -120,7 +120,7 @@ class FlareSummaryPlotGUI(QWidget):
self.cbSpTypeUnknown.setChecked(False) self.cbSpTypeUnknown.setChecked(False)
self.cbShowSAP = QCheckBox("SAP") self.cbShowSAP = QCheckBox("SAP")
self.cbShowSAP.setChecked(True) self.cbShowSAP.setChecked(False)
self.cbShowPDCSAP = QCheckBox("PDCSAP") self.cbShowPDCSAP = QCheckBox("PDCSAP")
self.cbShowPDCSAP.setChecked(True) self.cbShowPDCSAP.setChecked(True)
@@ -129,12 +129,12 @@ class FlareSummaryPlotGUI(QWidget):
self.buttonGridLayout.addWidget(self.btShowFlaresPerStar, 0, 2) self.buttonGridLayout.addWidget(self.btShowFlaresPerStar, 0, 2)
self.buttonGridLayout.addWidget(self.btShowFlaresPerStarNormalized, 0, 3) self.buttonGridLayout.addWidget(self.btShowFlaresPerStarNormalized, 0, 3)
self.buttonGridLayout.addWidget(self.btShowPeriods, 0, 4) self.buttonGridLayout.addWidget(self.btShowPeriods, 0, 4)
self.buttonGridLayout.addWidget(self.btNumMinimaMaxima, 0, 5) #self.buttonGridLayout.addWidget(self.btNumMinimaMaxima, 0, 5)
self.buttonGridLayout.addWidget(self.btNumMinimaMaximaNorm, 0, 6) #self.buttonGridLayout.addWidget(self.btNumMinimaMaximaNorm, 0, 6)
self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaxima, 0, 7) #self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaxima, 0, 7)
self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaximaPerMinimaMaxima, 0, 8) #self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaximaPerMinimaMaxima, 0, 8)
self.buttonGridLayout.addWidget(self.btShowFlaresBinnedOnPhase, 0, 9) #self.buttonGridLayout.addWidget(self.btShowFlaresBinnedOnPhase, 0, 9)
self.buttonGridLayout.addWidget(self.textNumBins, 0, 10) #self.buttonGridLayout.addWidget(self.textNumBins, 0, 10)
self.buttonGridLayout.addWidget(QLabel("Sources: "), 1, 0) self.buttonGridLayout.addWidget(QLabel("Sources: "), 1, 0)
self.buttonGridLayout.addWidget(self.cbKepler, 1, 1) self.buttonGridLayout.addWidget(self.cbKepler, 1, 1)
@@ -149,7 +149,7 @@ class FlareSummaryPlotGUI(QWidget):
self.buttonGridLayout.addWidget(self.cbSpTypeF, 2, 4) self.buttonGridLayout.addWidget(self.cbSpTypeF, 2, 4)
#self.buttonGridLayout.addWidget(self.cbSpTypeUnknown, 2, 6) #self.buttonGridLayout.addWidget(self.cbSpTypeUnknown, 2, 6)
self.buttonGridLayout.addWidget(self.cbShowSAP, 3, 0) #self.buttonGridLayout.addWidget(self.cbShowSAP, 3, 0)
self.buttonGridLayout.addWidget(self.cbShowPDCSAP, 3, 1) self.buttonGridLayout.addWidget(self.cbShowPDCSAP, 3, 1)
self.mainLayout.addLayout(self.buttonGridLayout) self.mainLayout.addLayout(self.buttonGridLayout)
@@ -243,27 +243,7 @@ class FlareSummaryPlotGUI(QWidget):
self.figure.canvas.draw_idle() self.figure.canvas.draw_idle()
def btShowFlaresPerStarClicked(self): def btShowFlaresPerStarClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'pdcsapPeaks',
'sapFits',
'sapPeaks',
'sapPeriod',
'sapPeriodMinima',
'sapPeriodMinimaBoundaries',
'sapPeriodMaxima',
'sapPeriodMaximaBoundaries',
'pdcsapValidTimespans',
'pdcsapPeriod',
'pdcsapPeriodMinima',
'pdcsapPeriodMinimaBoundaries',
'pdcsapPeriodMaxima',
'pdcsapPeriodMaximaBoundaries'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -277,9 +257,14 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["sapPeaksCount"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["pdcsapPeaksCount"] = "sum"
data = data[showSourceFilter].groupby(["StarName", "SpType"], data = data[showSourceFilter].groupby(["StarName", "SpType"],
as_index=False).agg({"sapPeaksCount": "sum", as_index=False).agg(aggDic)
"pdcsapPeaksCount": "sum"})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
@@ -345,28 +330,7 @@ class FlareSummaryPlotGUI(QWidget):
self.figure.canvas.draw_idle() self.figure.canvas.draw_idle()
def btShowFlaresPerStarNormalizedClicked(self): def btShowFlaresPerStarNormalizedClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'pdcsapPeaks',
'sapFits',
'sapValidTimespans',
'sapPeaks',
'sapPeriod',
'sapPeriodMinima',
'sapPeriodMinimaBoundaries',
'sapPeriodMaxima',
'sapPeriodMaximaBoundaries',
'pdcsapValidTimespans',
'pdcsapPeriod',
'pdcsapPeriodMinima',
'pdcsapPeriodMinimaBoundaries',
'pdcsapPeriodMaxima',
'pdcsapPeriodMaximaBoundaries'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -380,11 +344,16 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["sapPeaksCount"] = "sum"
aggDic["sapValidSeconds"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["pdcsapPeaksCount"] = "sum"
aggDic["pdcsapValidSeconds"] = "sum"
data = data[showSourceFilter].groupby(["StarName", "SpType"], data = data[showSourceFilter].groupby(["StarName", "SpType"],
as_index=False).agg({"sapPeaksCount": "sum", as_index=False).agg(aggDic)
"pdcsapPeaksCount": "sum",
"sapValidSeconds": "sum",
"pdcsapValidSeconds": "sum"})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
@@ -462,30 +431,7 @@ class FlareSummaryPlotGUI(QWidget):
self.figure.canvas.draw_idle() self.figure.canvas.draw_idle()
def btShowPeriodsClicked(self): def btShowPeriodsClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'pdcsapPeaks',
'sapFits',
'sapValidTimespans',
'sapPeaks',
'sapPeriodMinima',
'sapPeriodMinimaBoundaries',
'sapPeriodMaxima',
'sapPeriodMaximaBoundaries',
'pdcsapValidTimespans',
'pdcsapPeriodMinima',
'pdcsapPeriodMinimaBoundaries',
'pdcsapPeriodMaxima',
'pdcsapPeriodMaximaBoundaries',
'sapPeaksCount',
'pdcsapPeaksCount',
'sapValidSeconds',
'pdcsapValidSeconds'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -499,11 +445,14 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
print(data["sapPeriod"]) aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["sapPeriod"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["pdcsapPeriod"] = "sum"
data = data[showSourceFilter].groupby(["StarName", "SpType"], data = data[showSourceFilter].groupby(["StarName", "SpType"],
as_index=False).agg({"sapPeriod": "mean", as_index=False).agg(aggDic)
"pdcsapPeriod": "mean"})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
@@ -582,20 +531,7 @@ class FlareSummaryPlotGUI(QWidget):
pass pass
def btShowNumMinimaMaximaClicked(self): def btShowNumMinimaMaximaClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'sapFits',
'sapValidTimespans',
'pdcsapValidTimespans',
'sapPeaksCount',
'pdcsapPeaksCount',
'sapValidSeconds',
'pdcsapValidSeconds'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -609,13 +545,15 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
print(data["sapPeriod"]) aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["sapPeriodMinima"] = "sum"
aggDic["sapPeriodMaxima"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["pdcsapPeriodMinima"] = "sum"
aggDic["pdcsapPeriodMaxima"] = "sum"
data = data[showSourceFilter].groupby(["StarName", "SpType"], data = data[showSourceFilter].groupby(["StarName", "SpType"],
as_index=False).agg({"sapPeriodMinima": sumArrayLengths, as_index=False).agg(aggDic)
"sapPeriodMaxima": sumArrayLengths,
"pdcsapPeriodMinima": sumArrayLengths,
"pdcsapPeriodMaxima": sumArrayLengths})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
@@ -718,20 +656,7 @@ class FlareSummaryPlotGUI(QWidget):
pass pass
def btShowNumMinimaMaximaNormalizedClicked(self): def btShowNumMinimaMaximaNormalizedClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'sapFits',
'sapValidTimespans',
'pdcsapValidTimespans',
'sapPeaksCount',
'pdcsapPeaksCount',
'sapValidSeconds',
'pdcsapValidSeconds'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -745,13 +670,15 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
print(data["sapPeriod"]) aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["sapPeriodMinima"] = "sum"
aggDic["sapPeriodMaxima"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["pdcsapPeriodMinima"] = "sum"
aggDic["pdcsapPeriodMaxima"] = "sum"
data = data[showSourceFilter].groupby(["StarName", "SpType"], data = data[showSourceFilter].groupby(["StarName", "SpType"],
as_index=False).agg({"sapPeriodMinima": sumArrayLengthsNorm, as_index=False).agg(aggDic)
"sapPeriodMaxima": sumArrayLengthsNorm,
"pdcsapPeriodMinima": sumArrayLengthsNorm,
"pdcsapPeriodMaxima": sumArrayLengthsNorm})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
@@ -854,20 +781,7 @@ class FlareSummaryPlotGUI(QWidget):
pass pass
def btShowFlaresInMinimaMaximaClicked(self): def btShowFlaresInMinimaMaximaClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'sapFits',
'sapValidTimespans',
'pdcsapValidTimespans',
'sapPeaksCount',
'pdcsapPeaksCount',
'sapValidSeconds',
'pdcsapValidSeconds'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -881,8 +795,6 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
print(data["sapPeriod"])
finalData = [] finalData = []
#data = data[showSourceFilter].groupby(["StarName", "SpType"], #data = data[showSourceFilter].groupby(["StarName", "SpType"],
# as_index=False).agg({"sapPeriod": "mean", # as_index=False).agg({"sapPeriod": "mean",
@@ -1011,20 +923,7 @@ class FlareSummaryPlotGUI(QWidget):
pass pass
def btShowFlaresInMinimaMaximaPerMinimaMaximaClicked(self): def btShowFlaresInMinimaMaximaPerMinimaMaximaClicked(self):
data = self.starFLareDictList.drop(columns=['Distance', data = self.starFLareDictList
'DistanceUnit',
'FilePath',
'RotVel',
'RotVelUnit',
'Sequence',
'pdcsapFits',
'sapFits',
'sapValidTimespans',
'pdcsapValidTimespans',
'sapPeaksCount',
'pdcsapPeaksCount',
'sapValidSeconds',
'pdcsapValidSeconds'])
showSourceFilter = np.full(len(data), False) showSourceFilter = np.full(len(data), False)
@@ -1038,8 +937,6 @@ class FlareSummaryPlotGUI(QWidget):
showTESS = data["Source"] == "TESS" showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS showSourceFilter |= showTESS
print(data["sapPeriod"])
finalData = [] finalData = []
for ind, row in data[showSourceFilter].reset_index().iterrows(): for ind, row in data[showSourceFilter].reset_index().iterrows():
minimaCountSAP = getNumFlaresInBounds(row["sapFoldedPeaksPhasePair"], minimaCountSAP = getNumFlaresInBounds(row["sapFoldedPeaksPhasePair"],
@@ -1056,15 +953,20 @@ class FlareSummaryPlotGUI(QWidget):
"minimaCountPDCSAP": minimaCountPDCSAP, "maximaCountPDCSAP": maximaCountPDCSAP, "minimaCountPDCSAP": minimaCountPDCSAP, "maximaCountPDCSAP": maximaCountPDCSAP,
"minimasPDCSAP": len(row["pdcsapPeriodMinima"]), "maximasPDCSAP": len(row["pdcsapPeriodMaxima"])}) "minimasPDCSAP": len(row["pdcsapPeriodMinima"]), "maximasPDCSAP": len(row["pdcsapPeriodMaxima"])})
aggDic = {}
if(self.cbShowSAP.isChecked()):
aggDic["minimaCountSAP"] = "sum"
aggDic["maximaCountSAP"] = "sum"
aggDic["minimasSAP"] = "sum"
aggDic["maximasSAP"] = "sum"
if(self.cbShowPDCSAP.isChecked()):
aggDic["minimaCountPDCSAP"] = "sum"
aggDic["maximaCountPDCSAP"] = "sum"
aggDic["minimasPDCSAP"] = "sum"
aggDic["maximasPDCSAP"] = "sum"
data = pd.DataFrame(finalData).groupby(["StarName", "SpType"], data = pd.DataFrame(finalData).groupby(["StarName", "SpType"],
as_index=False).agg({"minimaCountSAP": "sum", as_index=False).agg(aggDic)
"maximaCountSAP": "sum",
"minimasSAP": "sum",
"maximasSAP": "sum",
"minimaCountPDCSAP": "sum",
"maximaCountPDCSAP": "sum",
"minimasPDCSAP": "sum",
"maximasPDCSAP": "sum"})
x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int) x = np.arange(start=1, stop=len(data)+1, step=1, dtype=int)
if(self.cbSpTypeL.isChecked()): if(self.cbSpTypeL.isChecked()):
+3 -3
View File
@@ -265,7 +265,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.periodsCalculated.emit([optimizedFold["SpotModulation"]]) self.periodsCalculated.emit([optimizedFold["SpotModulation"]])
foldOptimizePhase = optimizedFold["phase"] foldOptimizePhase = optimizedFold["phase"]
foldOptimizeFit = optimizedFold["fit"] foldOptimizeFit = optimizedFold["fit"]
print(self.FoldState["SpotModulation"]) print("SpotModulation", self.FoldState["SpotModulation"])
self.epochCalculated.emit(optimizedFold["epoch"]) self.epochCalculated.emit(optimizedFold["epoch"])
else: else:
lc = lc.fold(period=self.FoldState["Period"], lc = lc.fold(period=self.FoldState["Period"],
@@ -301,8 +301,8 @@ class FlaredetectorWidget(QtWidgets.QWidget):
phase, sineFit, _ = getFoldedBestFit(lc, fitType=self.foldedFitType) phase, sineFit, _ = getFoldedBestFit(lc, fitType=self.foldedFitType)
self.figureAxis.plot(phase, sineFit, color="red") self.figureAxis.plot(phase, sineFit, color="red")
print(phase, sineFit) print(phase, sineFit)
minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase) #minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase)
plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis) #plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis)
except Exception as e: except Exception as e:
print("Failed to get fit") print("Failed to get fit")
print(e) print(e)