generate_plots_MKGF: generate histograms with lower peaks only too
This commit is contained in:
@@ -55,6 +55,148 @@ folderPath = f"../{date}/"
|
|||||||
#folderPath = f"G:/Meine Ablage/Masterthesis/{date}/"
|
#folderPath = f"G:/Meine Ablage/Masterthesis/{date}/"
|
||||||
mkdir_p(folderPath)
|
mkdir_p(folderPath)
|
||||||
|
|
||||||
|
for comboLength in range(1, len(spType) + 1):
|
||||||
|
for combo in itertools.combinations(spType, comboLength):
|
||||||
|
for maxFlarePeak in [1.01, 1.05, 1.1, 1.25, 1.5]:
|
||||||
|
finalData = pd.DataFrame()
|
||||||
|
if("M" in combo):
|
||||||
|
Mfilter = data["SpType"].str.startswith("M")
|
||||||
|
Mfilter &= showSourceFilter
|
||||||
|
finalData = pd.concat([finalData, data[Mfilter]], ignore_index=True)
|
||||||
|
if("K" in combo):
|
||||||
|
Kfilter = data["SpType"].str.startswith("K")
|
||||||
|
Kfilter &= showSourceFilter
|
||||||
|
finalData = pd.concat([finalData, data[Kfilter]], ignore_index=True)
|
||||||
|
if("G" in combo):
|
||||||
|
Gfilter = data["SpType"].str.startswith("G")
|
||||||
|
Gfilter &= showSourceFilter
|
||||||
|
finalData = pd.concat([finalData, data[Gfilter]], ignore_index=True)
|
||||||
|
if("F" in combo):
|
||||||
|
Ffilter = data["SpType"].str.startswith("F")
|
||||||
|
Ffilter &= showSourceFilter
|
||||||
|
finalData = pd.concat([finalData, data[Ffilter]], ignore_index=True)
|
||||||
|
|
||||||
|
numStars = len(set(finalData["StarName"]))
|
||||||
|
|
||||||
|
pdcsapbinningData = []
|
||||||
|
locFolder = f"{folderPath}/{''.join(combo)}/"
|
||||||
|
mkdir_p(f"{locFolder}/")
|
||||||
|
csvFile = open(f"{locFolder}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}.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 finalData.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"]):
|
||||||
|
if(peak["FlarePeak"] <= maxFlarePeak):
|
||||||
|
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) < 1):
|
||||||
|
continue
|
||||||
|
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
|
||||||
|
PDCSAPdataList = []
|
||||||
|
PDCSAPlabelList = []
|
||||||
|
PDCSAPcolorList = []
|
||||||
|
PDCSAPdataList2dhistPhase = []
|
||||||
|
PDCSAPdataList2dhistPeak = []
|
||||||
|
PDCSAPlabelList2dhist = []
|
||||||
|
PDCSAPcolorList2dhist = []
|
||||||
|
if("M" in combo):
|
||||||
|
Mfilter = pdcsapbinningData["SpType"] == "M"
|
||||||
|
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Mfilter]["Peak"])
|
||||||
|
PDCSAPlabelList2dhist.append("M Stars")
|
||||||
|
PDCSAPcolorList2dhist.append("red")
|
||||||
|
|
||||||
|
PDCSAPdataList.append(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPlabelList.append("M Stars")
|
||||||
|
PDCSAPcolorList.append("red")
|
||||||
|
if("K" in combo):
|
||||||
|
Kfilter = pdcsapbinningData["SpType"] == "K"
|
||||||
|
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Kfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Kfilter]["Peak"])
|
||||||
|
PDCSAPlabelList2dhist.append("K Stars")
|
||||||
|
PDCSAPcolorList2dhist.append("orange")
|
||||||
|
|
||||||
|
PDCSAPdataList.append(pdcsapbinningData[Kfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPlabelList.append("K Stars")
|
||||||
|
PDCSAPcolorList.append("orange")
|
||||||
|
if("G" in combo):
|
||||||
|
Gfilter = pdcsapbinningData["SpType"] == "G"
|
||||||
|
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Gfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Gfilter]["Peak"])
|
||||||
|
PDCSAPlabelList2dhist.append("G Stars")
|
||||||
|
PDCSAPcolorList2dhist.append("yellow")
|
||||||
|
|
||||||
|
PDCSAPdataList.append(pdcsapbinningData[Gfilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPlabelList.append("G Stars")
|
||||||
|
PDCSAPcolorList.append("yellow")
|
||||||
|
if("F" in combo):
|
||||||
|
Ffilter = pdcsapbinningData["SpType"] == "F"
|
||||||
|
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Ffilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Ffilter]["Peak"])
|
||||||
|
PDCSAPlabelList2dhist.append("F Stars")
|
||||||
|
PDCSAPcolorList2dhist.append("greenyellow")
|
||||||
|
|
||||||
|
PDCSAPdataList.append(pdcsapbinningData[Ffilter]["PDCSAPNormPhase"])
|
||||||
|
PDCSAPlabelList.append("F Stars")
|
||||||
|
PDCSAPcolorList.append("greenyellow")
|
||||||
|
|
||||||
|
xData = pd.DataFrame()
|
||||||
|
yData = pd.DataFrame()
|
||||||
|
for aX, aY in zip(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak):
|
||||||
|
xData = pd.concat([xData, aX], ignore_index=True)
|
||||||
|
yData = pd.concat([yData, aY], ignore_index=True)
|
||||||
|
|
||||||
|
xData = np.asarray(xData.values)[:,0]
|
||||||
|
yData = np.asarray(yData.values)[:,0]
|
||||||
|
|
||||||
|
for bins in binList:
|
||||||
|
figHisto, ((axHisto)) = plt.subplots(nrows=1, ncols=1)
|
||||||
|
y, binEdges, _ = axHisto.hist(PDCSAPdataList, bins,
|
||||||
|
label=PDCSAPlabelList,
|
||||||
|
color=PDCSAPcolorList,
|
||||||
|
stacked=True,
|
||||||
|
range=[0, 2])
|
||||||
|
bincenters = 0.5*(binEdges[1:]+binEdges[:-1])
|
||||||
|
if(isinstance(y[0], np.ndarray)):
|
||||||
|
y = y[-1]
|
||||||
|
n_i = y
|
||||||
|
m_i = bincenters * np.pi
|
||||||
|
N = np.sum(n_i)
|
||||||
|
mean = np.sum(n_i * m_i)/N
|
||||||
|
stdDev = np.sqrt(np.sum(((n_i - mean)**2)) / (N-1))
|
||||||
|
menStd = np.sqrt(y)
|
||||||
|
if(np.isinf(stdDev)):
|
||||||
|
stdDev = np.mean(menStd)
|
||||||
|
axHisto.bar(bincenters[y > 0], y[y > 0], width=0, color='r', yerr=stdDev)
|
||||||
|
axHisto.set_ylim(0, max(y) + stdDev)
|
||||||
|
axHisto.set_ylabel("Num. flares")
|
||||||
|
axHisto.set_xlabel("Phase")
|
||||||
|
axHisto.set_title(f"Flare count per phase of {', '.join(combo)} type stars with {bins} bins ({numStars} stars)")
|
||||||
|
axHisto.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
|
||||||
|
axHisto.xaxis.set_major_locator(MaxNLocator(5))
|
||||||
|
axHisto.legend()
|
||||||
|
|
||||||
|
axHistoPhase = axHisto.twinx()
|
||||||
|
secAxisXdata = np.linspace(0, 2, num=10000)
|
||||||
|
secAxisYdata = np.cos(secAxisXdata*np.pi) + 1
|
||||||
|
axHistoPhase.plot(secAxisXdata, secAxisYdata)
|
||||||
|
axHistoPhase.set_ylim(0, 7)
|
||||||
|
|
||||||
|
plt.savefig(f"{locFolder}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}-Flarecount-{bins}_Bins.png")
|
||||||
|
plt.close()
|
||||||
|
|
||||||
for comboLength in range(1, len(spType) + 1):
|
for comboLength in range(1, len(spType) + 1):
|
||||||
for combo in itertools.combinations(spType, comboLength):
|
for combo in itertools.combinations(spType, comboLength):
|
||||||
finalData = pd.DataFrame()
|
finalData = pd.DataFrame()
|
||||||
|
|||||||
Reference in New Issue
Block a user