Compare commits

..

6 Commits

Author SHA1 Message Date
SGCMarkus 447c353844 generate_plots: use newest dataset 2024-11-14 13:40:55 +01:00
SGCMarkus b0d6991f4a generate_plots: make some plots nicer 2024-11-14 13:39:49 +01:00
SGCMarkus 55dfe55702 CalcAllFlaresThread: generate plots when calculating data 2024-11-14 13:37:23 +01:00
SGCMarkus 09902a70e8 flaredetector: make sure to only use valid flares
flattening can sometimes invert tips in the lightcurve to cause
a false detection of a flare
2024-11-14 13:35:16 +01:00
SGCMarkus d005102a09 flaredetector: add file to show starts with unknown spectral type 2024-11-13 13:07:30 +01:00
SGCMarkus 1df661815a flaredetector: bring it up to date 2024-11-13 13:03:04 +01:00
13 changed files with 961 additions and 30 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+373
View File
@@ -0,0 +1,373 @@
import numpy as np
import pandas as pd
import itertools
from main.astrodatagui.db.StarsDB import StarDB
import matplotlib.ticker as tck
from matplotlib.pyplot import MaxNLocator
import matplotlib.pyplot as plt
from datetime import datetime
from errno import EEXIST
from os import makedirs, path
import shutil
def normalizePhase(phase, phaseMin = None, phaseMax = None):
if(phaseMin is None):
phaseMin = np.abs(np.min(phase))
if(phaseMax is None):
phaseMax = np.abs(np.max(phase))
return (phase + phaseMin) / (phaseMin + phaseMax) * (2)
def mkdir_p(mypath):
'''Creates a directory. equivalent to using mkdir -p on the command line'''
try:
makedirs(mypath)
except OSError as exc: # Python >2.5
if exc.errno == EEXIST and path.isdir(mypath):
pass
else: raise
fileName = "datav3.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}/"
#folderPath = f"G:/Meine Ablage/Masterthesis/{date}/"
mkdir_p(folderPath)
for comboLength in range(1, len(spType) + 1):
for combo in itertools.combinations(spType, comboLength):
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)}.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"]):
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()
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)
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)}-Flarecount-{bins}_Bins.png")
plt.close()
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
figFlarepeakHist, ((axFlarepeakHist)) = plt.subplots(nrows=1, ncols=1)
axFlarepeakHist.set_ylabel("Flare peak")
axFlarepeakHist.set_xlabel("Phase")
axFlarepeakHist.set_title(f"Flare peak per phase histogram of {', '.join(combo)} type stars with {bins} bins ({numStars} stars)")
H, xedges, yedges = np.histogram2d(xData, yData, bins=bins, range=[[0, 2], [0.99, maxY]])
cmax = 11
H_clipped = np.clip(H, None, cmax)
im = axFlarepeakHist.imshow(H_clipped.T, origin='lower', interpolation='nearest',
extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],
aspect='auto', cmap='viridis')
figFlarepeakHist.colorbar(im, label='Counts', ax=axFlarepeakHist)
axFlarepeakHist.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarepeakHist.xaxis.set_major_locator(MaxNLocator(5))
plt.savefig(f"{locFolder}/{''.join(combo)}-Flarepeaks-{bins}_Bins_maxY-{maxY}.png")
plt.close()
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
figFlarePeaks, ((axFlarePeaks)) = plt.subplots(nrows=1, ncols=1)
axFlarePeaks.set_title(f"Flare peaks per phase of {', '.join(combo)} type stars ({numStars} stars)")
if("M" in combo):
axFlarePeaks.scatter(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"],
pdcsapbinningData[Mfilter]["Peak"],
label="M Stars", color="red")
if("K" in combo):
axFlarePeaks.scatter(pdcsapbinningData[Kfilter]["PDCSAPNormPhase"],
pdcsapbinningData[Kfilter]["Peak"],
label="K Stars", color="orange")
if("G" in combo):
axFlarePeaks.scatter(pdcsapbinningData[Gfilter]["PDCSAPNormPhase"],
pdcsapbinningData[Gfilter]["Peak"],
label="G Stars", color="yellow")
if("F" in combo):
axFlarePeaks.scatter(pdcsapbinningData[Ffilter]["PDCSAPNormPhase"],
pdcsapbinningData[Ffilter]["Peak"],
label="F Stars", color="greenyellow")
axFlarePeaks.set_xlim(0, 2)
axFlarePeaks.set_ylim(0.99, maxY)
axFlarePeaks.set_ylabel("Flare peak")
axFlarePeaks.set_xlabel("Phase")
axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5))
axFlarePeaks.legend()
plt.savefig(f"{locFolder}/{''.join(combo)}-Flarepeaks_maxY-{maxY}.png")
plt.close()
for sT, color in zip(["M", "K", "G", "F"], ["red", "orange", "yellow", "greenyellow"]):
spTypes = [f"{sT}0", f"{sT}1", f"{sT}2", f"{sT}3", f"{sT}4", f"{sT}5", f"{sT}6", f"{sT}7", f"{sT}8", f"{sT}9"]
for spTyp in spTypes:
finalData = pd.DataFrame()
Mfilter = data["SpType"].str.startswith(spTyp)
numStars = len(set(data[Mfilter]["StarName"]))
Mfilter &= showSourceFilter
finalData = pd.concat([finalData, data[Mfilter]], ignore_index=True)
pdcsapbinningData = []
locFolder = f"{folderPath}/{spTyp}/"
mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{spTyp}.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"]):
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": f'{row["SpType"][0]}{row["SpType"][1]}',
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
csvFile.close()
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
PDCSAPdataList = []
PDCSAPlabelList = []
PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = []
PDCSAPlabelList2dhist = []
PDCSAPcolorList2dhist = []
try:
SpTypefilter = pdcsapbinningData["SpType"] == spTyp
except:
shutil.rmtree(locFolder)
continue
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[SpTypefilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[SpTypefilter]["Peak"])
PDCSAPlabelList2dhist.append(f"{spTyp} Stars")
PDCSAPcolorList2dhist.append(color)
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]
PDCSAPdataList.append(pdcsapbinningData[SpTypefilter]["PDCSAPNormPhase"])
PDCSAPlabelList.append(f"{spTyp} Stars")
PDCSAPcolorList.append(color)
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)
axHisto.bar(bincenters[y > 0], y[y > 0], width=0, color='r', yerr=stdDev)
if(~np.isnan(stdDev) & ~np.isinf(stdDev)):
axHisto.set_ylim(0, max(y[y > 0 & ~np.isnan(y) & ~np.isinf(y)] + stdDev))
axHisto.set_ylabel("Num. flares")
axHisto.set_xlabel("Phase")
axHisto.set_title(f"Flare count in phase of {spTyp} 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(spTyp)}-Flarecount-{bins}_Bins.png")
plt.close()
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
figFlarepeakHist, ((axFlarepeakHist)) = plt.subplots(nrows=1, ncols=1)
axFlarepeakHist.set_ylabel("Flare peak")
axFlarepeakHist.set_xlabel("Phase")
H, xedges, yedges = np.histogram2d(xData, yData, bins=bins, range=[[0, 2], [min(yData), maxY]])
cmax = 11
H_clipped = np.clip(H, None, cmax)
im = axFlarepeakHist.imshow(H_clipped.T, origin='lower', interpolation='nearest',
extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],
aspect='auto', cmap='viridis')
figFlarepeakHist.colorbar(im, label='Counts', ax=axFlarepeakHist)
axFlarepeakHist.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarepeakHist.xaxis.set_major_locator(MaxNLocator(5))
axFlarepeakHist.set_title(f"Flare peak per phase histogram of {spTyp} type stars with {bins} bins ({numStars} stars)")
plt.savefig(f"{locFolder}/{''.join(spTyp)}-Flarepeaks-{bins}_Bins_maxY-{maxY}.png")
plt.close()
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
figFlarePeaks, ((axFlarePeaks)) = plt.subplots(nrows=1, ncols=1)
axFlarePeaks.scatter(pdcsapbinningData[SpTypefilter]["PDCSAPNormPhase"],
pdcsapbinningData[SpTypefilter]["Peak"],
label=f"{spTyp} Stars", color=color)
axFlarePeaks.set_xlim(0, 2)
axFlarePeaks.set_ylim(0.99, maxY)
axFlarePeaks.set_ylabel("Flare peak")
axFlarePeaks.set_xlabel("Phase")
axFlarePeaks.set_title(f"Flare peaks per phase of {spTyp} type stars ({numStars} stars)")
axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5))
axFlarePeaks.legend()
plt.savefig(f"{locFolder}/{''.join(spTyp)}-Flarepeaks_maxY-{maxY}.png")
plt.close()
+91 -5
View File
@@ -1,7 +1,9 @@
from PyQt5.QtCore import pyqtSignal, QThread
import multiprocessing
import concurrent.futures
from ..util.MinimalLightCurve import read
#from ..util.MinimalLightCurve import read
import lightkurve as lk
import matplotlib.pyplot as plt
import pandas as pd
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
from ..flaredetector.util import *
@@ -9,12 +11,39 @@ from ..flaredetector.util import *
import warnings
warnings.filterwarnings("ignore")
from errno import EEXIST
from os import makedirs, path
from datetime import datetime
def mkdir_p(mypath):
'''Creates a directory. equivalent to using mkdir -p on the command line'''
try:
makedirs(mypath)
except OSError as exc: # Python >2.5
if exc.errno == EEXIST and path.isdir(mypath):
pass
else: raise
current = datetime.now()
date = f"{current.year}-{current.month}-{current.day}"
time = f"{current.hour}-{current.minute}-{current.second}"
folderPath = f"../{date}/"
mkdir_p(folderPath)
def getFlareCount(filesDict):
try:
print(f"Starting {filesDict['StarName']}, {filesDict['Sequence']}")
lc = read(filesDict["FilePath"])
starName = filesDict['StarName']
starNameR = filesDict['StarName'].replace("*", "_star_")
sequence = filesDict['Sequence']
starFolder = f"{folderPath}/stars/{starNameR}/"
mkdir_p(starFolder)
lc = lk.read(filesDict["FilePath"])
lc.flux = lc["sap_flux"]
lc.flux_err = lc["sap_flux_err"]
lc = lc.normalize()
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten())
sapValSec, sapTds = getTotalValidDataInSeconds(lc, "sap_flux")
sapPeriodogram = lc.to_periodogram()
@@ -33,10 +62,51 @@ def getFlareCount(filesDict):
lc.flux = lc["pdcsap_flux"]
lc.flux_err = lc["pdcsap_flux_err"]
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(lc.flatten())
lc = lc.normalize()
lc.plot()
plt.title(f"{starName} - normalized lightcurve")
plt.savefig(f"{starFolder}/{starNameR}_{sequence}-lc.png")
plt.close()
flattenedLc = lc.flatten()
flattenedLc.plot()
plt.title(f"{starName} - flattened lightcurve")
plt.savefig(f"{starFolder}/{starNameR}_{sequence}-flattened_lc.png")
plt.close()
pdcsapPeaks, pdcsapFits = calculateFlareFitsForLightcurve(flattenedLc, normalizedLC=lc)
lc.plot()
plt.title(f"{starName} - normalized lightcurve")
for p in pdcsapPeaks:
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}_{sequence}-lc-marked_flares.png")
plt.close()
flattenedLc.plot()
plt.title(f"{starName} - flattened lightcurve")
for f in pdcsapFits:
plt.plot(f["FlareFitTime"].value, f["FlareFit"], "g--")
plt.plot([], [], "g--", label="Flare fits")
for p in pdcsapPeaks:
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}_{sequence}-flattened_lc-marked_flares.png")
plt.close()
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
pdcsapPeriodogram = lc.to_periodogram()
pdcsapPeakPeriod = pdcsapPeriodogram.period[findMaxIndices(pdcsapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
maxPeriodIndex = findMaxIndices(pdcsapPeriodogram, num=4, distance=100, sortByHighest=True)[0]
pdcsapPeakPeriod = pdcsapPeriodogram.period[maxPeriodIndex]
pdcsapPeriodogram.plot(view="period")
plt.plot(pdcsapPeakPeriod, pdcsapPeriodogram.power[maxPeriodIndex], "x", color="red")
plt.savefig(f"{starFolder}/{starNameR}_{sequence}-periodogram-marked_max.png")
plt.close()
pdcsapEpochTime = getEpochTime(lc)
pdcsapFoldedLC = lc.fold(period=pdcsapPeakPeriod, epoch_time=pdcsapEpochTime)
pdcsapPhase, pdcsapSineFit, pdcsapFitType = getFoldedBestFit(pdcsapFoldedLC, fitType=filesDict["FitType"])
@@ -44,10 +114,21 @@ def getFlareCount(filesDict):
pdcsapminPhasesBounds, pdcsapmaxPhasesBounds = getPhaseRangesNearPeak((pdcsapMinima, pdcsapMaxima), pdcsapPhase, returnPhaseValue=True)
pdcsapFoldedPeaks = []
pdcsapFoldedPeaksPhasePair = []
for peak in sapPeaks:
pdcsapFoldedLC.scatter()
plt.title(f"{starName} - folded lightcurve")
plt.plot(pdcsapPhase, pdcsapSineFit, color="blue", label=f"{pdcsapFitType}-fit")
for peak in pdcsapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(pdcsapFoldedLC, peak["StandardIndex"])
pdcsapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapFoldedPeaksPhasePair.append({"Phase": pdcsapFoldedLC.phase[pdcsapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
plt.plot(pdcsapFoldedLC.phase[pdcsapFoldedLC.cycle == cycle][foldedIndex].value,
pdcsapFoldedLC.flux[pdcsapFoldedLC.cycle == cycle][foldedIndex], "x", color="red")
plt.plot([], [], "x", color="red", label="Flare peaks")
plt.legend()
plt.savefig(f"{starFolder}/{starNameR}_{sequence}-foldedLC-marked_fit_flares.png")
plt.close()
filesDict["sapPeaks"] = sapPeaks
filesDict["sapPeaksCount"] = len(sapPeaks)
@@ -79,6 +160,11 @@ def getFlareCount(filesDict):
filesDict["pdcsapPeriodMinimaBoundaries"] = pdcsapminPhasesBounds
filesDict["pdcsapPeriodMaxima"] = pdcsapMaxima
filesDict["pdcsapPeriodMaximaBoundaries"] = pdcsapmaxPhasesBounds
csvFile = open(f"{starFolder}/{starNameR}_{sequence}.csv", "a")
csvFile.write("StarName,Spectral Type,Rotational Velocity,Rotenional Velocity Unit,Distance,Distance Unit,Source,Sequence,File Path,Initial folded Fit Type,Used folded Fit Type")
csvFile.write(f"{filesDict['StarName']},{filesDict['SpType']},{filesDict['RotVel']},{filesDict['RotVelUnit']},{filesDict['Distance']},{filesDict['DistanceUnit']},{filesDict['Source']},{filesDict['Sequence']},{filesDict['FilePath']},{filesDict['FitType']},{pdcsapFitType}")
csvFile.close()
del lc
print(f"Finished {filesDict['StarName']}, {filesDict['Sequence']}")
return filesDict
+288 -9
View File
@@ -1,6 +1,6 @@
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QGridLayout,
QPushButton, QCheckBox, QLabel)
QPushButton, QCheckBox, QLabel, QLineEdit)
from matplotlib.figure import Figure
from matplotlib.backends.backend_qtagg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
@@ -41,6 +41,13 @@ def sumArrayLengthsNorm(series):
sumRes += len(s)
return sumRes / len(series)
def normalizePhase(phase, phaseMin = None, phaseMax = None):
if(phaseMin is None):
phaseMin = np.abs(np.min(phase))
if(phaseMax is None):
phaseMax = np.abs(np.max(phase))
return (phase + phaseMin) / (phaseMin + phaseMax) * (2)
class FlareSummaryPlotGUI(QWidget):
def __init__(self, starFLareDictList):
@@ -87,6 +94,11 @@ class FlareSummaryPlotGUI(QWidget):
self.btShowFlaresInMinimaMaximaPerMinimaMaxima = QPushButton("Show num Flares Minima/Maxima normalized")
self.btShowFlaresInMinimaMaximaPerMinimaMaxima.clicked.connect(self.btShowFlaresInMinimaMaximaPerMinimaMaximaClicked)
self.btShowFlaresBinnedOnPhase = QPushButton("Show flares binned")
self.btShowFlaresBinnedOnPhase.clicked.connect(self.btShowFlaresBinnedOnPhaseClicked)
self.textNumBins = QLineEdit()
self.textNumBins.setText("10")
self.cbKepler = QCheckBox("Kepler")
self.cbKepler.setChecked(True)
self.cbK2 = QCheckBox("K2")
@@ -95,7 +107,7 @@ class FlareSummaryPlotGUI(QWidget):
self.cbTESS.setChecked(True)
self.cbSpTypeL = QCheckBox("L")
self.cbSpTypeL.setChecked(True)
self.cbSpTypeL.setChecked(False)
self.cbSpTypeM = QCheckBox("M")
self.cbSpTypeM.setChecked(True)
self.cbSpTypeK = QCheckBox("K")
@@ -105,7 +117,7 @@ class FlareSummaryPlotGUI(QWidget):
self.cbSpTypeF = QCheckBox("F")
self.cbSpTypeF.setChecked(True)
self.cbSpTypeUnknown = QCheckBox("Unknown")
self.cbSpTypeUnknown.setChecked(True)
self.cbSpTypeUnknown.setChecked(False)
self.cbShowSAP = QCheckBox("SAP")
self.cbShowSAP.setChecked(True)
@@ -121,6 +133,8 @@ class FlareSummaryPlotGUI(QWidget):
self.buttonGridLayout.addWidget(self.btNumMinimaMaximaNorm, 0, 6)
self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaxima, 0, 7)
self.buttonGridLayout.addWidget(self.btShowFlaresInMinimaMaximaPerMinimaMaxima, 0, 8)
self.buttonGridLayout.addWidget(self.btShowFlaresBinnedOnPhase, 0, 9)
self.buttonGridLayout.addWidget(self.textNumBins, 0, 10)
self.buttonGridLayout.addWidget(QLabel("Sources: "), 1, 0)
self.buttonGridLayout.addWidget(self.cbKepler, 1, 1)
@@ -128,12 +142,12 @@ class FlareSummaryPlotGUI(QWidget):
self.buttonGridLayout.addWidget(self.cbTESS, 1, 3)
self.buttonGridLayout.addWidget(QLabel("Sp Types: "), 2, 0)
self.buttonGridLayout.addWidget(self.cbSpTypeL, 2, 1)
self.buttonGridLayout.addWidget(self.cbSpTypeM, 2, 2)
self.buttonGridLayout.addWidget(self.cbSpTypeK, 2, 3)
self.buttonGridLayout.addWidget(self.cbSpTypeG, 2, 4)
self.buttonGridLayout.addWidget(self.cbSpTypeF, 2, 5)
self.buttonGridLayout.addWidget(self.cbSpTypeUnknown, 2, 6)
#self.buttonGridLayout.addWidget(self.cbSpTypeL, 2, 1)
self.buttonGridLayout.addWidget(self.cbSpTypeM, 2, 1)
self.buttonGridLayout.addWidget(self.cbSpTypeK, 2, 2)
self.buttonGridLayout.addWidget(self.cbSpTypeG, 2, 3)
self.buttonGridLayout.addWidget(self.cbSpTypeF, 2, 4)
#self.buttonGridLayout.addWidget(self.cbSpTypeUnknown, 2, 6)
self.buttonGridLayout.addWidget(self.cbShowSAP, 3, 0)
self.buttonGridLayout.addWidget(self.cbShowPDCSAP, 3, 1)
@@ -1295,3 +1309,268 @@ class FlareSummaryPlotGUI(QWidget):
print("Total Minima: ", PDCSAPtotalMin)
print("Total Maxima: ", PDCSAPtotalMax)
def btShowFlaresBinnedOnPhaseClicked(self):
data = self.starFLareDictList
showSourceFilter = np.full(len(data), False)
try:
nBins = int(self.textNumBins.text())
except Exception as e:
print("Falling back to 10 Bins")
print(e)
nBins = 10
if(self.cbKepler.isChecked()):
showKepler = data["Source"] == "Kepler"
showSourceFilter |= showKepler
if(self.cbK2.isChecked()):
showK2 = data["Source"] == "K2"
showSourceFilter |= showK2
if(self.cbTESS.isChecked()):
showTESS = data["Source"] == "TESS"
showSourceFilter |= showTESS
finalData = pd.DataFrame()
#if(self.cbSpTypeL.isChecked()):
# Lfilter = data["SpType"].str.startswith("L")
# Lfilter &= showSourceFilter
# finalData = pd.concat([finalData, data[Lfilter]], ignore_index=True)
if(self.cbSpTypeM.isChecked()):
Mfilter = data["SpType"].str.startswith("M")
Mfilter &= showSourceFilter
finalData = pd.concat([finalData, data[Mfilter]], ignore_index=True)
if(self.cbSpTypeK.isChecked()):
Kfilter = data["SpType"].str.startswith("K")
Kfilter &= showSourceFilter
finalData = pd.concat([finalData, data[Kfilter]], ignore_index=True)
if(self.cbSpTypeG.isChecked()):
Gfilter = data["SpType"].str.startswith("G")
Gfilter &= showSourceFilter
finalData = pd.concat([finalData, data[Gfilter]], ignore_index=True)
if(self.cbSpTypeF.isChecked()):
Ffilter = data["SpType"].str.startswith("F")
Ffilter &= showSourceFilter
finalData = pd.concat([finalData, data[Ffilter]], ignore_index=True)
#if(self.cbSpTypeUnknown.isChecked()):
# Unknownfilter = data["SpType"].str.startswith("-")
# Unknownfilter &= showSourceFilter
# finalData = pd.concat([finalData, data[Unknownfilter]], ignore_index=True)
sapbinningData = []
pdcsapbinningData = []
for ind, row in finalData.reset_index().iterrows():
SAPminOrigPhase = row["sapFoldedFitPhaseStarEnd"][0]
SAPmaxOrigPhase = row["sapFoldedFitPhaseStarEnd"][1]
PDCSAPminOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][0]
PDCSAPmaxOrigPhase = row["pdcsapFoldedFitPhaseStarEnd"][1]
sapValsList = []
pdcsapValsList = []
if(len(row["sapFoldedPeaksPhasePair"]) > 0):
sapVals = pd.DataFrame(row["sapFoldedPeaksPhasePair"])
for td, peak in zip(sapVals["Phase"], sapVals["Peak"]):
sapbinningData.append({"SpType": row["SpType"][0],
"SAPNormPhase": normalizePhase(td.value, np.abs(SAPminOrigPhase), np.abs(SAPmaxOrigPhase)),
"Peak": peak["FlarePeak"]})
if(len(row["pdcsapFoldedPeaksPhasePair"]) > 0):
pdcsapVals = pd.DataFrame(row["pdcsapFoldedPeaksPhasePair"])
for td, peak in zip(pdcsapVals["Phase"], pdcsapVals["Peak"]):
pdcsapbinningData.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase)),
"Peak": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
sapbinningData = pd.DataFrame(sapbinningData)
SAPdataList = []
SAPlabelList = []
SAPcolorList = []
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
PDCSAPdataList = []
PDCSAPlabelList = []
PDCSAPcolorList = []
#if(self.cbSpTypeL.isChecked()):
# SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "L"]["SAPNormPhase"])
# SAPlabelList.append("L Stars")
# SAPcolorList.append("brown")
# PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "L"]["PDCSAPNormPhase"])
# PDCSAPlabelList.append("L Stars")
# PDCSAPcolorList.append("brown")
if(self.cbSpTypeM.isChecked()):
SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "M"]["SAPNormPhase"])
SAPlabelList.append("M Stars")
SAPcolorList.append("red")
PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "M"]["PDCSAPNormPhase"])
PDCSAPlabelList.append("M Stars")
PDCSAPcolorList.append("red")
if(self.cbSpTypeK.isChecked()):
SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "K"]["SAPNormPhase"])
SAPlabelList.append("K Stars")
SAPcolorList.append("orange")
PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "K"]["PDCSAPNormPhase"])
PDCSAPlabelList.append("K Stars")
PDCSAPcolorList.append("orange")
if(self.cbSpTypeG.isChecked()):
SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "G"]["SAPNormPhase"])
SAPlabelList.append("G Stars")
SAPcolorList.append("yellow")
PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "G"]["PDCSAPNormPhase"])
PDCSAPlabelList.append("G Stars")
PDCSAPcolorList.append("yellow")
if(self.cbSpTypeF.isChecked()):
SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "F"]["SAPNormPhase"])
SAPlabelList.append("F Stars")
SAPcolorList.append("greenyellow")
PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "F"]["PDCSAPNormPhase"])
PDCSAPlabelList.append("F Stars")
PDCSAPcolorList.append("greenyellow")
#if(self.cbSpTypeUnknown.isChecked()):
# SAPdataList.append(sapbinningData[sapbinningData["SpType"] == "-"]["SAPNormPhase"])
# SAPlabelList.append("Unknown Stars")
# SAPcolorList.append("gray")
# PDCSAPdataList.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "-"]["PDCSAPNormPhase"])
# PDCSAPlabelList.append("Unknown Stars")
# PDCSAPcolorList.append("gray")
self.figureAxis.clear()
import matplotlib.ticker as tck
from matplotlib.pyplot import MaxNLocator
import matplotlib.pyplot as plt
#fig, ((ax1, ax3), (ax5, ax7)) = plt.subplots(nrows=2, ncols=2)
fig1, ((ax1)) = plt.subplots(nrows=1, ncols=1)
ax1.clear()
ax1.set_title("PDCSAP Flarerate in phase")
y, binEdges, _ = ax1.hist(PDCSAPdataList, nBins, label=PDCSAPlabelList, color=PDCSAPcolorList, stacked=True)
bincenters = 0.5*(binEdges[1:]+binEdges[:-1])
if(isinstance(y[0], np.ndarray)):
y = y[-1]
print("n_i")
n_i = y
print(n_i)
print("----------------------")
print("m_i")
m_i = bincenters * np.pi
print(m_i)
print("----------------------")
print("N")
N = np.sum(n_i)
print(N)
print("----------------------")
mean = np.sum(n_i * m_i)/N
print(np.sum(n_i * m_i))
print("----------------------")
print(mean)
print("----------------------")
stdDev = np.sqrt(np.sum(((n_i - mean)**2)) / (N-1))
print(stdDev)
menStd = np.sqrt(y)
#width = 0.05
print(bincenters)
print(type(y))
ax1.bar(bincenters, y, width=0, color='r', yerr=stdDev)
ax1.set_ylabel("Num. flares")
ax1.set_xlabel("Phase")
ax1.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
ax1.xaxis.set_major_locator(MaxNLocator(5))
ax1.legend()
ax2 = ax1.twinx()
secAxisXdata = np.linspace(0, 2, num=10000)
secAxisYdata = np.cos(secAxisXdata*np.pi) + 1
ax2.plot(secAxisXdata, secAxisYdata)
ax2.set_ylim(0, 5)
fig3, ((ax3)) = plt.subplots(nrows=1, ncols=1)
ax3.clear()
ax3.set_title("PDCSAP Flare peak in phase")
if(self.cbSpTypeM.isChecked()):
Mfilter = pdcsapbinningData["SpType"] == "M"
ax3.scatter(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"],
pdcsapbinningData[Mfilter]["Peak"],
label="M Stars", color="red")
if(self.cbSpTypeK.isChecked()):
ax3.scatter(pdcsapbinningData[pdcsapbinningData["SpType"] == "K"]["PDCSAPNormPhase"],
pdcsapbinningData[pdcsapbinningData["SpType"] == "K"]["Peak"],
label="K Stars", color="orange")
if(self.cbSpTypeG.isChecked()):
ax3.scatter(pdcsapbinningData[pdcsapbinningData["SpType"] == "G"]["PDCSAPNormPhase"],
pdcsapbinningData[pdcsapbinningData["SpType"] == "G"]["Peak"],
label="G Stars", color="yellow")
if(self.cbSpTypeF.isChecked()):
ax3.scatter(pdcsapbinningData[pdcsapbinningData["SpType"] == "F"]["PDCSAPNormPhase"],
pdcsapbinningData[pdcsapbinningData["SpType"] == "F"]["Peak"],
label="F Stars", color="greenyellow")
#if(self.cbSpTypeUnknown.isChecked()):
# ax3.scatter(pdcsapbinningData[pdcsapbinningData["SpType"] == "-"]["PDCSAPNormPhase"],
# pdcsapbinningData[pdcsapbinningData["SpType"] == "-"]["Peak"],
# label="Unknown Stars", color="gray")
ax3.set_ylabel("Flare peak")
ax3.set_xlabel("Phase")
ax3.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
ax3.xaxis.set_major_locator(MaxNLocator(5))
ax3.legend()
fig5, ((ax5)) = plt.subplots(nrows=1, ncols=1)
ax5.clear()
ax5.set_title("PDCSAP Flare peak in phase")
PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = []
PDCSAPlabelList2dhist = []
PDCSAPcolorList2dhist = []
if(self.cbSpTypeM.isChecked()):
Mfilter = pdcsapbinningData["SpType"] == "M"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[Mfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[Mfilter]["Peak"])
PDCSAPlabelList2dhist.append("M Stars")
PDCSAPcolorList2dhist.append("red")
if(self.cbSpTypeK.isChecked()):
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "K"]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "K"]["Peak"])
PDCSAPlabelList2dhist.append("K Stars")
PDCSAPcolorList2dhist.append("orange")
if(self.cbSpTypeG.isChecked()):
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "G"]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "G"]["Peak"])
PDCSAPlabelList2dhist.append("G Stars")
PDCSAPcolorList2dhist.append("yellow")
if(self.cbSpTypeF.isChecked()):
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "F"]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "F"]["Peak"])
PDCSAPlabelList2dhist.append("F Stars")
PDCSAPcolorList2dhist.append("greenyellow")
#if(self.cbSpTypeUnknown.isChecked()):
# PDCSAPdataList2dhistPhase.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "-"]["PDCSAPNormPhase"])
# PDCSAPdataList2dhistPeak.append(pdcsapbinningData[pdcsapbinningData["SpType"] == "-"]["Peak"])
# PDCSAPlabelList2dhist.append("Unknown Stars")
# PDCSAPcolorList2dhist.append("gray")
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)
print(np.shape(np.asarray(xData.values)[:,0]))
xData = np.asarray(xData.values)[:,0]
yData = np.asarray(yData.values)[:,0]
ax5.set_ylabel("Flare peak")
ax5.set_xlabel("Phase")
#h = ax5.hist2d(x=xData, y=yData, bins=[nBins, nBins], cmin=0, cmax=10)#, range=[[0, 2], [1, 4.5]])
#fig5.colorbar(h[3], ax=ax5)
H, xedges, yedges = np.histogram2d(xData, yData, bins=nBins)
cmax = 11
H_clipped = np.clip(H, None, cmax)
im = ax5.imshow(H_clipped.T, origin='lower', interpolation='nearest',
extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],
aspect='auto', cmap='viridis')
fig5.colorbar(im, label='Counts', ax=ax5)
ax5.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
ax5.xaxis.set_major_locator(MaxNLocator(5))
#ax5.legend()
#fig.tight_layout()
plt.show()
+18
View File
@@ -163,12 +163,30 @@ class StarDB():
else:
raise Exception(f"Fit type {fitType} not supported, must be one of {supportedFitTypes}")
def updateStarInfoSpType(self, mainName, spType):
self.dbCursor.execute(f"""UPDATE starInfo
SET spType = '{spType}'
WHERE mainName = '{mainName}'""")
self.connection.commit()
def getAllStars(self):
res = self.dbCursor.execute("""SELECT DISTINCT mainName FROM stars
ORDER BY mainName""")
resList = []
for s in res.fetchall():
resList.append(s[0])
print(f"Loading {len(resList)} stars")
return resList
def getAllStarsWithSpType(self, spType: str):
res = self.dbCursor.execute(f"""SELECT DISTINCT mainName
FROM stars INNER JOIN starInfo USING(mainName)
WHERE spType LIKE '{spType}%'
ORDER BY mainName""")
resList = []
for s in res.fetchall():
resList.append(s[0])
print(f"Loading {len(resList)} stars")
return resList
def getStarSequences(self, mainName):
+1 -1
View File
@@ -210,7 +210,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.currentFlattenLC = lc.flatten(window_length=self.FlattenState["WindowLength"],
polyorder=self.FlattenState["PolynomialOrder"])
self.foldedLC = lc.to_periodogram(method=self.PeriodogramState["Method"])
self.peaks, self.fits = calculateFlareFitsForLightcurve(self.currentFlattenLC, num=100)
self.peaks, self.fits = calculateFlareFitsForLightcurve(self.currentFlattenLC, num=100, normalizedLC=self.currentLC.normalize())
self.periods = [self.foldedLC.period[i] for i in findMaxIndices(self.foldedLC, num=4, distance=100, sortByHighest=True)]
self.epoch_time = getEpochTime(lc)
self.periodsCalculated.emit(self.periods)
+92 -13
View File
@@ -1,3 +1,4 @@
from types import NoneType
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QListWidgetItem
from PyQt5 import uic
@@ -8,6 +9,62 @@ from astropy.table import vstack
from ...astrodatadownloader.astrodatadownloader import (ObservationSource,
getStarObservations, downloadStarProducts)
from astroquery.simbad import Simbad
import multiprocessing
import concurrent.futures
from astropy.table import Table
def createEmptyObsTable():
table = Table()
table['obsID'] = []
table['obs_collection'] = []
table['dataproduct_type'] = []
table['obs_id'] = []
table['description'] = []
table['type'] = []
table['dataURI'] = []
table['productType'] = []
table['productGroupDescription'] = []
table['productSubGroupDescription'] = []
table['productDocumentationURL'] = []
table['project'] = []
table['prvversion'] = []
table['proposal_id'] = []
table['productFilename'] = []
table['size'] = []
table['parent_obsid'] = []
table['dataRights'] = []
table['calib_level'] = []
table['filters'] = []
table['sequence_number'] = []
table['starName'] = []
return table
def getStarObsParallel(starName, keplerKadences, k2Kadences, sources):
simbad = Simbad()
s = starName.strip()
altNames = simbad.query_objectids(s)
if(type(altNames) == NoneType):
altNames = [s]
else:
altNames = list(altNames["ID"])
print("Trying for " + ", ".join(altNames))
obs = createEmptyObsTable()
for name in altNames:
try:
obs = getStarObservations(name, keplerKadences, k2Kadences, sources)
if(len(obs) == 0):
continue;
obs['starName'] = name
break
except:
print(f"Could not find data for {name}")
return obs
def getStarObsParallelWrapper(args):
return getStarObsParallel(*args)
class NewStarDialog(QDialog):
def __init__(self):
super().__init__()
@@ -27,6 +84,8 @@ class NewStarDialog(QDialog):
QtWidgets.QMessageBox.Ok)
def btFetchData_clicked(self):
from astroquery.simbad import Simbad
simbad = Simbad()
star = self.leStarIdentifier.text()
if not star:
self.showErrorMessage("No star identifier",
@@ -51,23 +110,43 @@ class NewStarDialog(QDialog):
k2Kadences = [self.cbK2ShortCadence.isChecked(),
self.cbK2LongCadence.isChecked()]
allObs = []
#allObs = []
stars = star.split(";")
starsRet = []
self.listPreview.clear()
for s in stars:
s = s.strip()
obs = getStarObservations(s, keplerKadences, k2Kadences, sources)
if(len(obs) == 0):
self.showErrorMessage("No observations found",
"No observationnal data has been found with the current filters")
return
allObs.append(obs)
for o in obs:
self.listPreview.addItem(QListWidgetItem(f"{s} - {o['obs_collection']} - {o['sequence_number']}"))
#for s in stars:
# s = s.strip()
# altNames = simbad.query_objectids(s)
# if(type(altNames) == NoneType):
# altNames = [s]
# else:
# altNames = list(altNames["ID"])
# print("Trying for " + ", ".join(altNames))
# for name in altNames:
# try:
# obs = getStarObservations(name, keplerKadences, k2Kadences, sources)
# if(len(obs) == 0):
# self.showErrorMessage("No observations found",
# "No observationnal data has been found with the current filters")
# return
# allObs.append(obs)
#
# for o in obs:
# self.listPreview.addItem(QListWidgetItem(f"{name} - {o['obs_collection']} - {o['sequence_number']}"))
# starsRet.append(name)
# break
# except:
# print(f"Could not find data for {name}")
cpuCount = multiprocessing.cpu_count()
executor = concurrent.futures.ThreadPoolExecutor(500)
args = ((starName, keplerKadences, k2Kadences, sources) for starName in stars)
allObs = list(executor.map(getStarObsParallelWrapper, args))
obs = vstack(allObs)
for o in obs:
self.listPreview.addItem(QListWidgetItem(f"{o['starName']} - {o['obs_collection']} - {o['sequence_number']}"))
self.currentObservations = obs
self.starIdentifier = star
self.starIdentifier = ";".join(starsRet)
self.leStarIdentifier.setText(self.starIdentifier)
def btOk_clicked(self):
if self.currentObservations:
+3
View File
@@ -78,6 +78,9 @@
<height>16777215</height>
</size>
</property>
<property name="maxLength">
<number>999999</number>
</property>
</widget>
</item>
<item>
+4 -1
View File
@@ -47,7 +47,7 @@ def calculateFitForFlare(lightcurve, peakIndex):
flareFitDataPoints = flareFitDataPoints + peakIndex
return np.array(Peak+1), flareFitDataPoints, np.array(fit+1)
def calculateFlareFitsForLightcurve(lightcurve, num=100, distance=1, height=0.05):
def calculateFlareFitsForLightcurve(lightcurve, num=100, distance=1, height=0.05, normalizedLC=None):
maxIndices = findMaxIndices(lightcurve, num, distance=distance, height=height,
sortByHighest=True)
peaks = []
@@ -55,6 +55,9 @@ def calculateFlareFitsForLightcurve(lightcurve, num=100, distance=1, height=0.05
for index in maxIndices:
try:
Peak, flareFitDataPoints, fit = calculateFitForFlare(lightcurve, index)
if(normalizedLC is not None and
(normalizedLC.flux[index] < 0.95 or Peak > 1.5 * normalizedLC.flux[index])):
continue
peaks.append({"FlarePeak": Peak,
"FlarePeakTime": lightcurve.time[index],
"StandardIndex": index,
+90
View File
@@ -0,0 +1,90 @@
from main.astrodatadownloader.astrodatadownloader import *
from main.astrodatagui.db.StarsDB import StarDB
from astroquery.simbad import Simbad
import concurrent.futures
import pandas as pd
DEFAULT_DB = "stars.db"
starDB: StarDB = StarDB.getInstance(DEFAULT_DB)
simbad = Simbad()
simbad.add_votable_fields("sptype")
simbad.add_votable_fields("velocity")
simbad.add_votable_fields("diameter")
simbad.add_votable_fields("distance")
allUnknownStars = starDB.getAllStarsWithSpType("-")
print(allUnknownStars)
gaiaNames = []
for star in allUnknownStars:
altNames = starDB.getStarAltNames(star)
for altName in altNames[:-1]:
if(altName[0].startswith("Gaia DR3")):
gaiaNames.append({"mainName": star,
"gaiaName": altName[0]})
break
gaiaNames = pd.DataFrame(gaiaNames)
kicNames = []
for star in allUnknownStars:
altNames = starDB.getStarAltNames(star)
for altName in altNames[:-1]:
if(altName[0].startswith("KIC")):
kicNames.append({"mainName": star,
"kicName": altName[0]})
break
kicNames = pd.DataFrame(kicNames)
nonGaiaStars = []
for star in allUnknownStars:
if(star not in gaiaNames["mainName"].values):
nonGaiaStars.append({"mainName": star})
nonGaiaStars = pd.DataFrame(nonGaiaStars)
nonKicStars = []
for star in allUnknownStars:
if(star not in gaiaNames["mainName"].values):
nonKicStars.append({"mainName": star})
nonKicStars = pd.DataFrame(nonKicStars)
#print(gaiaNames)
#print(nonGaiaStars)
print(kicNames)
#print(nonKicStars)
KeplerM = pd.read_csv("D:/Masterthesis/ressources/akthukair_AFD/Results/M-type-superflares.csv")
KeplerK = pd.read_csv("D:/Masterthesis/ressources/akthukair_AFD/Results/K-type-superflares.csv")
KeplerG = pd.read_csv("D:/Masterthesis/ressources/akthukair_AFD/Results/G-type-superflares.csv")
KeplerF = pd.read_csv("D:/Masterthesis/ressources/akthukair_AFD/Results/F-type-superflares.csv")
KeplerA = pd.read_csv("D:/Masterthesis/ressources/akthukair_AFD/Results/A-type-superflares.csv")
#kicBasedSP = []
#for fullKIC in kicNames["kicName"].values:
# kic = int(fullKIC[4:])
# if(kic in KeplerM["kepler_id"].values):
# kicBasedSP.append("M")
# elif(kic in KeplerK["kepler_id"].values):
# kicBasedSP.append("K")
# elif(kic in KeplerG["kepler_id"].values):
# kicBasedSP.append("G")
# elif(kic in KeplerF["kepler_id"].values):
# kicBasedSP.append("F")
# elif(kic in KeplerA["kepler_id"].values):
# kicBasedSP.append("A")
# else:
# print("No Match")
# kicBasedSP.append("-")
#kicNames["spType"] = kicBasedSP
#print(kicNames)
#for ind, row in kicNames.reset_index().iterrows():
# mainName = row["mainName"]
# spType = row["spType"]
# starDB.updateStarInfoSpType(mainName, spType)
BIN
View File
Binary file not shown.