Compare commits
5 Commits
9afe0993f6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d0401d31d | |||
| 95ce7917d9 | |||
| ecf480c2de | |||
| 6514a6d125 | |||
| b6c194cb6e |
+63
-10
@@ -1,9 +1,19 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from main.astrodatagui.db.StarsDB import StarDB
|
||||
|
||||
db: StarDB = StarDB.getInstance("stars.db")
|
||||
starMainIDs = db.getAllStars()
|
||||
res = []
|
||||
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)
|
||||
@@ -16,16 +26,59 @@ for mainID in starMainIDs:
|
||||
if name[0].startswith("KIC"):
|
||||
kicName = name[0]
|
||||
spType = infos["SpType"]
|
||||
res.append({"MainID": mainID,
|
||||
"Spectral Type": spType,
|
||||
"TIC": ticName,
|
||||
"KIC": kicName})
|
||||
|
||||
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)
|
||||
|
||||
resDF = pd.DataFrame(res)
|
||||
resDF.sort_values(by=["Spectral Type", "MainID"]) #.to_latex(index=False)
|
||||
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}.tex", "w")
|
||||
tex = resDF[resDF["Spectral Type"].str.startswith(sptype)].sort_values(by=["Spectral Type", "MainID"]).to_latex(index=False)
|
||||
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.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()
|
||||
+117
-105
@@ -85,7 +85,7 @@ def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, ti
|
||||
axHisto.set_title(title, wrap=True)
|
||||
axHisto.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
|
||||
axHisto.xaxis.set_major_locator(MaxNLocator(5))
|
||||
axHisto.legend()
|
||||
axHisto.legend(loc="lower right")
|
||||
|
||||
axHistoPhase = axHisto.twinx()
|
||||
if(foldedFits is None):
|
||||
@@ -149,7 +149,7 @@ def plotFlarePeaks(plotdata, filters, labels, colors, maxY, title, filename):
|
||||
axFlarePeaks.set_title(title, wrap=True)
|
||||
axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
|
||||
axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5))
|
||||
axFlarePeaks.legend()
|
||||
axFlarePeaks.legend(loc="lower right")
|
||||
plt.savefig(filename, bbox_inches="tight")
|
||||
plt.close()
|
||||
|
||||
@@ -322,6 +322,101 @@ def plotStarPeriod(data, showSourceFilter, folderPath, starName):
|
||||
|
||||
|
||||
def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
# 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]:
|
||||
# max Flare Peak cut
|
||||
finalDataMaxFlarePeak = pd.DataFrame()
|
||||
@@ -366,7 +461,8 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
csvFileU.write("\n")
|
||||
pdcsapbinningDataU.append({"SpType": row["SpType"][0],
|
||||
"PDCSAPNormPhase": normPhase,
|
||||
"Peak": peak["FlarePeak"]})
|
||||
"Peak": peak["FlarePeak"],
|
||||
"StarName": row['StarName']})
|
||||
if(peak["FlarePeak"] > 100):
|
||||
print(row["StarName"], "has over 100 peak")
|
||||
else:
|
||||
@@ -375,7 +471,8 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
csvFileO.write("\n")
|
||||
pdcsapbinningDataO.append({"SpType": row["SpType"][0],
|
||||
"PDCSAPNormPhase": normPhase,
|
||||
"Peak": peak["FlarePeak"]})
|
||||
"Peak": peak["FlarePeak"],
|
||||
"StarName": row['StarName']})
|
||||
if(peak["FlarePeak"] > 100):
|
||||
print(row["StarName"], "has over 100 peak")
|
||||
|
||||
@@ -384,6 +481,7 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
if(len(pdcsapbinningDataU) > 0):
|
||||
pdcsapbinningDataU = pd.DataFrame(pdcsapbinningDataU)
|
||||
numStarsFlarePeakU = len(set(pdcsapbinningDataU["StarName"]))
|
||||
pd.DataFrame(set(pdcsapbinningDataU["StarName"])).to_csv(f"{locFolderU}/{''.join(combo)}_starlist.csv")
|
||||
PDCSAPdataListU = []
|
||||
PDCSAPlabelListU = []
|
||||
PDCSAPcolorListU = []
|
||||
@@ -432,6 +530,7 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
if(len(pdcsapbinningDataO) > 0):
|
||||
pdcsapbinningDataO = pd.DataFrame(pdcsapbinningDataO)
|
||||
numStarsFlarePeakO = len(set(pdcsapbinningDataO["StarName"]))
|
||||
pd.DataFrame(set(pdcsapbinningDataO["StarName"])).to_csv(f"{locFolderO}/{''.join(combo)}_starlist.csv")
|
||||
PDCSAPdataListO = []
|
||||
PDCSAPlabelListO = []
|
||||
PDCSAPcolorListO = []
|
||||
@@ -476,99 +575,7 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
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",
|
||||
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",
|
||||
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")
|
||||
# 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)
|
||||
|
||||
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)
|
||||
numStarsAllFLarePeaks = len(set(pdcsapbinningData["StarName"]))
|
||||
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,
|
||||
pdcsapbinningData, "PDCSAPNormPhase",)
|
||||
plotdata = pdcsapbinningData
|
||||
filters = plotFilters
|
||||
generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, f"Flare count per phase of {', '.join(combo)} type stars with @bins bins ({numStarsAllFLarePeaks} 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 ({numStarsAllFLarePeaks} 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 ({numStarsAllFLarePeaks} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks_maxY-@maxY.png")
|
||||
|
||||
|
||||
if(len(combo) == 1):
|
||||
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"]
|
||||
@@ -606,13 +613,15 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
csvFile.write("\n")
|
||||
pdcsapbinningData.append({"SpType": f'{row["SpType"][0]}{row["SpType"][1]}',
|
||||
"PDCSAPNormPhase": normPhase,
|
||||
"Peak": peak["FlarePeak"]})
|
||||
"Peak": peak["FlarePeak"],
|
||||
"StarName": row['StarName']})
|
||||
if(peak["FlarePeak"] > 100):
|
||||
print(row["StarName"], "has over 100 peak")
|
||||
csvFile.close()
|
||||
if(len(pdcsapbinningData) > 0):
|
||||
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
|
||||
numStarsAccSpType = len(set(pdcsapbinningData[typeFilter]["StarName"]))
|
||||
numStarsAccSpType = len(set(pdcsapbinningData["StarName"]))
|
||||
pd.DataFrame(set(pdcsapbinningData["StarName"])).to_csv(f"{locFolder}/{spTyp}_starlist.csv")
|
||||
PDCSAPdataList = []
|
||||
PDCSAPlabelList = []
|
||||
PDCSAPcolorList = []
|
||||
@@ -685,13 +694,15 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
csvFileU.write("\n")
|
||||
pdcsapbinningDataU.append({"SpType": f'{row["SpType"][0]}',
|
||||
"PDCSAPNormPhase": normPhase,
|
||||
"Peak": peak["FlarePeak"]})
|
||||
"Peak": peak["FlarePeak"],
|
||||
"StarName": row['StarName']})
|
||||
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("\n")
|
||||
pdcsapbinningDataO.append({"SpType": f'{row["SpType"][0]}',
|
||||
"PDCSAPNormPhase": normPhase,
|
||||
"Peak": peak["FlarePeak"]})
|
||||
"Peak": peak["FlarePeak"],
|
||||
"StarName": row['StarName']})
|
||||
if(peak["FlarePeak"] > 100):
|
||||
print(row["StarName"], "has over 100 peak")
|
||||
csvFileU.close()
|
||||
@@ -705,9 +716,6 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
PDCSAPdataList2dhistPhaseO = []; PDCSAPdataList2dhistPeakO = []
|
||||
plotFiltersU = []; plotFiltersO = [];
|
||||
|
||||
numStarsPeriodU = len(set(pdcsapbinningDataU[typeFilter]["StarName"]))
|
||||
numStarsPeriodO = len(set(pdcsapbinningDataO[typeFilter]["StarName"]))
|
||||
|
||||
if("M" in combo):
|
||||
PDCSAPlabelList.append("M Stars")
|
||||
PDCSAPcolorList.append("red")
|
||||
@@ -722,6 +730,8 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
PDCSAPcolorList.append("greenyellow")
|
||||
|
||||
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):
|
||||
MfilterU = pdcsapbinningDataU["SpType"] == "M"
|
||||
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[MfilterU]["PDCSAPNormPhase"])
|
||||
@@ -748,6 +758,8 @@ def plotCombo(data, showSourceFilter, folderPath, combo):
|
||||
plotFiltersU.append(FfilterU)
|
||||
|
||||
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):
|
||||
MfilterO = pdcsapbinningDataO["SpType"] == "M"
|
||||
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[MfilterO]["PDCSAPNormPhase"])
|
||||
@@ -851,7 +863,7 @@ if __name__ == "__main__":
|
||||
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
|
||||
|
||||
|
||||
@@ -15,6 +15,18 @@ from errno import EEXIST
|
||||
from os import makedirs, path
|
||||
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):
|
||||
'''Creates a directory. equivalent to using mkdir -p on the command line'''
|
||||
|
||||
@@ -48,13 +60,13 @@ def getFlareCount(filesDict):
|
||||
|
||||
lc.plot()
|
||||
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()
|
||||
|
||||
flattenedLc = lc.flatten()
|
||||
flattenedLc.plot()
|
||||
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()
|
||||
|
||||
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([], [], "x", color="red", label="Flare peaks")
|
||||
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()
|
||||
|
||||
flattenedLc.plot()
|
||||
@@ -76,7 +88,7 @@ def getFlareCount(filesDict):
|
||||
plt.plot(p["FlarePeakTime"].value, p["FlarePeak"], "x", color="red")
|
||||
plt.plot([], [], "x", color="red", label="Flare peaks")
|
||||
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()
|
||||
|
||||
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
|
||||
@@ -86,7 +98,7 @@ def getFlareCount(filesDict):
|
||||
|
||||
pdcsapPeriodogram.plot(view="period")
|
||||
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()
|
||||
|
||||
#pdcsapEpochTime = getEpochTime(lc)
|
||||
@@ -108,7 +120,7 @@ def getFlareCount(filesDict):
|
||||
optimizedFit["foldedLC"].flux[optimizedFit["foldedLC"].cycle == cycle][foldedIndex], "x", color="red")
|
||||
plt.plot([], [], "x", color="red", label="Flare peaks")
|
||||
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()
|
||||
|
||||
if(optimizedFit["periodFoldedLC"] is not None):
|
||||
@@ -123,7 +135,7 @@ def getFlareCount(filesDict):
|
||||
optimizedFit["periodFoldedLC"].flux[optimizedFit["periodFoldedLC"].cycle == cycle][foldedIndex], "x", color="red")
|
||||
plt.plot([], [], "x", color="red", label="Flare peaks")
|
||||
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()
|
||||
|
||||
filesDict["pdcsapPeaks"] = pdcsapPeaks
|
||||
|
||||
@@ -301,8 +301,8 @@ class FlaredetectorWidget(QtWidgets.QWidget):
|
||||
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)
|
||||
#minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase)
|
||||
#plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis)
|
||||
except Exception as e:
|
||||
print("Failed to get fit")
|
||||
print(e)
|
||||
|
||||
Reference in New Issue
Block a user