Compare commits

47 Commits

Author SHA1 Message Date
SGCMarkus 7d0401d31d generate_plots: fix formatting and star count 2025-06-08 15:39:30 +02:00
SGCMarkus 95ce7917d9 Merge branch 'main' of https://gitea.markus.stammgruppe.eu/SGCMarkus/flaredetector 2025-06-08 15:38:40 +02:00
SGCMarkus ecf480c2de generate_latex_table: update printed tables 2025-06-08 15:37:40 +02:00
SGCMarkus 6514a6d125 Merge branch 'main' of https://gitea.markus.stammgruppe.eu/SGCMarkus/flaredetector 2025-05-31 16:54:33 +02:00
SGCMarkus b6c194cb6e CalcAllFlaresThread: set proper plot description sizes 2025-05-31 16:54:26 +02:00
SGCMarkus 9afe0993f6 generate_plots: fix flare number 2025-05-31 16:53:17 +02:00
SGCMarkus c1c58746e9 FlareSummaryPlotGUI: bring up to date 2025-05-31 16:52:41 +02:00
SGCMarkus c36c227e11 generate_plots: add option to adjust plot text sizes 2025-05-25 18:22:32 +02:00
SGCMarkus cd04b272ca fix period plot generation after rework 2025-05-25 14:24:42 +02:00
SGCMarkus a41edfcaa7 add latex table generation file 2025-05-21 17:59:23 +02:00
SGCMarkus 44d5da5975 generate_plots: fix multithreaded plot generation 2025-05-08 14:55:21 +02:00
SGCMarkus 7d574febcf generate_plots: use multiprocessing 2025-05-06 11:48:01 +02:00
SGCMarkus 43eb79bcc6 FlaredetectorWidget: properly label print 2025-05-06 11:46:45 +02:00
SGCMarkus 1fc9b82a1a generate plots: fix using wrong dataset for full period histogram 2025-04-27 21:22:04 +02:00
SGCMarkus 060cae2264 generate_plots: bring uptodate for changes, add max flare peak plots 2025-04-27 20:32:44 +02:00
SGCMarkus 54bd2e4bff add updated data package 2025-04-27 20:31:50 +02:00
SGCMarkus a7a816a892 CalcAllFlaresThread: add isValid flag to final output 2025-04-27 20:30:50 +02:00
SGCMarkus 4ad7974bb1 flaredetector: util: optimize: improve minima detection 2025-04-27 20:29:46 +02:00
SGCMarkus d930d7896b update code for optimized fold 2025-04-25 08:11:55 +02:00
SGCMarkus a13e32f35e astrodatagui: change default to pdcsap flux 2025-04-21 11:29:23 +02:00
SGCMarkus 10d1699d71 CalcAllFlaresThread: remove sap calculations, we dont use those 2025-04-11 13:48:21 +02:00
SGCMarkus c4a0dc766b Add UI option to optimize the lightcurve fold 2025-04-11 13:41:08 +02:00
SGCMarkus bb54965b54 generate_plots: fix generation of more detailed spectral types plots 2025-03-11 12:08:18 +01:00
SGCMarkus 01ae4f9084 rework generate_plot script 2025-03-10 08:26:16 +01:00
SGCMarkus df79c8bdcc add newest dataset 2025-01-27 08:40:16 +01:00
SGCMarkus 68dcc66071 generate_plots_MKGF: pre filter data to exclude data without periods 2025-01-14 13:21:32 +01:00
SGCMarkus fa7a2a3f75 generate_plots_MKGF: generate histograms with lower peaks only too 2024-12-16 10:38:06 +01:00
SGCMarkus a901ba9c45 generate_plots_MKGF: generate plots individually per star too 2024-12-04 14:05:26 +01:00
SGCMarkus 989a3d82ec stars.db: update from running e145014 2024-12-04 12:42:42 +01:00
SGCMarkus e1450141b0 identify_unknown_sptypes: update sptypes in database
also update SpType per Teff from
https://lweb.cfa.harvard.edu/~pberlind/atlas/htmls/note.html
2024-12-04 12:41:33 +01:00
SGCMarkus bef934176d identify_unknown_sptypes: use vizier tic catalogue and print best match 2024-12-04 11:54:06 +01:00
SGCMarkus db3c8be556 identify_unknown_sptypes: add colorcoding to the output 2024-12-02 10:01:05 +01:00
SGCMarkus 34261b9581 Revert "identify unknown sptypes: only check U-B and B-V"
This reverts commit 87f71c386e.
2024-12-02 09:50:30 +01:00
SGCMarkus 3d92dcb1bb identify_unknown_sptypes: print UBV only match 2024-12-02 09:49:57 +01:00
SGCMarkus 87f71c386e identify unknown sptypes: only check U-B and B-V 2024-12-02 08:23:57 +01:00
SGCMarkus 6480c9fbee add file to estimate spectral type by B-V 2024-12-02 08:22:33 +01:00
SGCMarkus f150c02dfd cousins.cols: rework to csv format 2024-11-29 13:57:02 +01:00
SGCMarkus 8bfb34a3d0 Add cousins B-V conversion table
from:
https://www.stsci.edu/~inr/intrins.html
2024-11-29 13:32:43 +01:00
SGCMarkus 557ae476e5 add newest dataset 2024-11-28 10:04:39 +01:00
SGCMarkus 208e619ce7 FlaredetectorWidget: handle K2 no QUARTER in header 2024-11-28 10:03:39 +01:00
SGCMarkus 53fcdc541e CalcAllFlaresThread: add source to filename 2024-11-28 10:00:56 +01:00
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
23 changed files with 2330 additions and 341 deletions
+51
View File
@@ -0,0 +1,51 @@
SpType,U-B,B-V,V-R,V-I,V-J,V-H,V-K,V-L,V-M,V-N
B0.0,-1.08,-0.30,-0.19,-0.31,-0.80,-0.92,-0.97,-1.13,-1.00,-9.99
B0.5,-1.00,-0.28,-0.18,-0.31,-0.77,-0.89,-0.95,-1.11,-0.99,-9.99
B1.0,-0.95,-0.26,-0.16,-0.30,-0.73,-0.85,-0.93,-1.08,-0.96,-9.99
B1.5,-0.88,-0.25,-0.15,-0.29,-0.70,-0.82,-0.91,-1.05,-0.94,-9.99
B2.0,-0.81,-0.24,-0.14,-0.29,-0.67,-0.79,-0.89,-1.02,-0.92,-9.99
B2.5,-0.72,-0.22,-0.13,-0.28,-0.64,-0.76,-0.86,-0.97,-0.88,-0.96
B3.0,-0.68,-0.20,-0.12,-0.27,-0.60,-0.72,-0.82,-0.92,-0.84,-0.91
B3.5,-0.65,-0.19,-0.12,-0.26,-0.58,-0.70,-0.80,-0.90,-0.82,-0.87
B4.0,-0.63,-0.18,-0.11,-0.25,-0.56,-0.68,-0.77,-0.86,-0.79,-0.84
B4.5,-0.61,-0.17,-0.11,-0.24,-0.54,-0.65,-0.74,-0.83,-0.76,-0.80
B5.0,-0.58,-0.16,-0.10,-0.24,-0.51,-0.62,-0.71,-0.78,-0.73,-0.75
B6.0,-0.49,-0.14,-0.10,-0.21,-0.46,-0.57,-0.64,-0.70,-0.65,-0.66
B7.0,-0.43,-0.13,-0.09,-0.19,-0.41,-0.51,-0.57,-0.61,-0.58,-0.58
B7.5,-0.40,-0.12,-0.09,-0.17,-0.39,-0.48,-0.54,-0.57,-0.54,-0.53
B8.0,-0.36,-0.11,-0.08,-0.16,-0.36,-0.45,-0.49,-0.52,-0.49,-0.48
B8.5,-0.27,-0.09,-0.08,-0.13,-0.31,-0.40,-0.43,-0.43,-0.42,-0.39
B9.0,-0.18,-0.07,-0.07,-0.10,-0.26,-0.34,-0.33,-0.34,-0.34,-0.30
B9.5,-0.10,-0.04,-0.05,-0.08,-0.22,-0.29,-0.26,-0.27,-0.26,-0.22
A0.0,-0.02,-0.01,-0.04,-0.04,-0.16,-0.19,-0.17,-0.18,-0.18,-0.14
A1.0,0.01,0.02,-0.02,-0.02,-0.11,-0.12,-0.11,-0.12,-0.13,-0.08
A2.0,0.05,0.05,-0.01,0.00,-0.07,-0.04,-0.05,-0.07,-0.08,-0.02
A3.0,0.08,0.08,0.01,0.02,-0.02,0.03,0.01,-0.01,-0.02,0.03
A4.0,0.09,0.12,0.02,0.05,0.03,0.11,0.08,0.05,-0.04,0.09
A5.0,0.09,0.15,0.04,0.09,0.09,0.19,0.15,0.12,0.10,0.16
A6.0,0.10,0.17,0.05,0.12,0.13,0.30,0.21,0.17,0.15,0.21
A7.0,0.10,0.20,0.06,0.15,0.18,0.32,0.27,0.23,0.20,0.26
A8.0,0.09,0.27,0.09,0.20,0.25,0.42,0.36,0.33,0.29,0.34
A9.0,0.08,0.30,0.10,0.24,0.31,0.49,0.44,0.41,0.36,0.41
F0.0,0.03,0.32,0.12,0.28,0.37,0.57,0.52,0.49,0.43,0.48
F1.0,0.00,0.34,0.14,0.31,0.43,0.64,0.58,0.57,0.49,0.54
F2.0,0.00,0.35,0.15,0.35,0.48,0.71,0.66,0.66,0.56,0.60
F5.0,-0.02,0.45,0.21,0.44,0.67,0.93,0.89,0.90,0.77,0.80
F8.0,0.02,0.53,0.24,0.50,0.79,1.06,1.03,1.06,0.91,0.91
G0.0,0.06,0.60,0.27,0.54,0.87,1.15,1.14,1.18,1.01,1.01
G2.0,0.09,0.63,0.30,0.58,0.97,1.25,1.26,1.31,1.12,1.11
G3.0,0.12,0.65,0.30,0.59,0.98,1.27,1.28,1.33,1.14,1.13
G5.0,0.20,0.68,0.31,0.61,1.02,1.31,1.32,1.38,1.18,1.17
G8.0,0.30,0.74,0.35,0.66,1.14,1.44,1.47,1.55,1.34,1.30
K0.0,0.44,0.81,0.42,0.75,1.34,1.67,1.74,1.85,1.61,1.54
K1.0,0.48,0.86,0.46,0.82,1.46,1.80,1.89,2.02,1.78,1.68
K2.0,0.67,0.92,0.50,0.89,1.60,1.94,2.06,2.21,1.97,1.84
K3.0,0.73,0.95,0.55,0.97,1.73,2.09,2.23,2.40,2.17,2.01
K4.0,1.00,1.00,0.60,1.04,1.84,2.22,2.38,2.57,2.36,2.15
K5.0,1.06,1.15,0.68,1.20,2.04,2.46,2.66,2.87,2.71,2.44
K7.0,1.21,1.33,0.62,1.45,2.30,2.78,3.01,3.25,3.21,2.83
M0.0,1.23,1.37,0.70,1.67,2.49,3.04,3.29,3.54,3.65,3.16
M1.0,1.18,1.47,0.76,1.84,2.61,3.22,3.47,3.72,3.95,3.39
M2.0,1.15,1.47,0.83,2.06,2.74,3.42,3.67,3.92,4.31,3.66
M3.0,1.17,1.50,0.89,2.24,2.84,3.58,3.83,4.08,4.62,3.89
M4.0,1.07,1.52,0.94,2.43,2.93,3.74,3.98,4.22,4.93,4.11
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+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()
+879
View File
@@ -0,0 +1,879 @@
from math import comb
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
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):
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
def allValuesWithin3Std(values: list):
if(not values or len(values) == 1):
return True
return max(values) - min(values) <= 3*np.std(values)
def getMeanPeriod(values: list):
return np.mean(values)
def plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, title, filename, foldedFits):
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) or np.isnan(stdDev)):
stdDev = np.mean(menStd)
if(np.isinf(stdDev) or np.isnan(stdDev)):
stdDev = 0
axHisto.bar(bincenters[y > 0], y[y > 0], width=0, color='r', yerr=stdDev)
try:
axHisto.set_ylim(0, max(y) + stdDev)
except Exception as e:
print(e)
print(max(y), stdDev)
quit()
axHisto.set_ylabel("Num. flares")
axHisto.set_xlabel("Phase")
axHisto.set_title(title, wrap=True)
axHisto.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axHisto.xaxis.set_major_locator(MaxNLocator(5))
axHisto.legend(loc="lower right")
axHistoPhase = axHisto.twinx()
if(foldedFits is None):
secAxisXdata = np.linspace(0, 2, num=10000)
secAxisYdata = np.cos(secAxisXdata*np.pi) + 1
axHistoPhase.plot(secAxisXdata, secAxisYdata, color="blue")
axHistoPhase.set_ylim(0, 7)
else:
for fit in foldedFits:
axHistoPhase.plot(fit[0], fit[1], color="blue")
fitCol = [fit[1] for fit in foldedFits]
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)
plt.savefig(filename, bbox_inches="tight")
plt.close()
def plotFlarePhasePeakHistogram(xData, yData, bins, maxY, title, filename):
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], [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))
axFlarepeakHist.set_title(title, wrap=True)
plt.savefig(filename, bbox_inches="tight")
plt.close()
def plotFlarePeaks(plotdata, filters, labels, colors, maxY, title, filename):
if(isinstance(labels, list) and isinstance(colors, list)):
_, ((axFlarePeaks)) = plt.subplots(nrows=1, ncols=1)
for f, l, c in zip(filters, labels, colors):
axFlarePeaks.scatter(plotdata[f]["PDCSAPNormPhase"] if "PDCSAPNormPhase" in plotdata[f].columns else plotdata[f]["PDCSAPNormPhasePeriod"],
plotdata[f]["Peak"] if "Peak" in plotdata[f].columns else plotdata[f]["PeakPeriod"],
label=l, color=c)
elif(isinstance(labels, str) and isinstance(colors, str)):
_, ((axFlarePeaks)) = plt.subplots(nrows=1, ncols=1)
if(filters is None):
axFlarePeaks.scatter(plotdata[:]["PDCSAPNormPhase"] if "PDCSAPNormPhase" in plotdata[:].columns else plotdata[:]["PDCSAPNormPhasePeriod"],
plotdata[:]["Peak"] if "Peak" in plotdata[:].columns else plotdata[:]["PeakPeriod"],
label=labels, color=colors)
else:
axFlarePeaks.scatter(plotdata[filters]["PDCSAPNormPhase"] if "PDCSAPNormPhase" in plotdata[filters].columns else plotdata[filters]["PDCSAPNormPhasePeriod"],
plotdata[filters]["Peak"] if "Peak" in plotdata[filters].columns else plotdata[filters]["PeakPeriod"],
label=labels, color=colors)
else:
return
axFlarePeaks.set_xlim(0, 2)
axFlarePeaks.set_ylim(0.99, maxY)
axFlarePeaks.set_ylabel("Flare peak")
axFlarePeaks.set_xlabel("Phase")
axFlarePeaks.set_title(title, wrap=True)
axFlarePeaks.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$'))
axFlarePeaks.xaxis.set_major_locator(MaxNLocator(5))
axFlarePeaks.legend(loc="lower right")
plt.savefig(filename, bbox_inches="tight")
plt.close()
def setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak, pdcsapbinningData,
pdcsapbinningDataColumn, PDCSAPdataList=None, dataFilter=None):
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]
if(PDCSAPdataList is not None):
if(dataFilter is not None):
PDCSAPdataList.append(pdcsapbinningData[dataFilter][pdcsapbinningDataColumn])
else:
PDCSAPdataList.append(pdcsapbinningData[:][pdcsapbinningDataColumn])
return xData, yData, PDCSAPdataList
def generatePlots(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, histogramTitleArg, histogramFilenameArg,
xData, yData, peak2DHistogramTitleArg, peak2DfilenameArg,
plotdata, filters, flarePlotLabels, flarePlotColors, flarePlotTitleArg, flarePlotFilenameArg,
foldedFits=None):
for bins in binList:
histogramTitle = histogramTitleArg.replace("@bins", str(bins))
histogramFilename = histogramFilenameArg.replace("@bins", str(bins))
plotBinsHistogram(PDCSAPdataList, PDCSAPlabelList, PDCSAPcolorList, bins, histogramTitle, histogramFilename, foldedFits)
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
peak2DHistogramTitle = peak2DHistogramTitleArg.replace("@bins", str(bins))
peak2Dfilename = peak2DfilenameArg.replace("@bins", str(bins)).replace("@maxY", str(maxY))
plotFlarePhasePeakHistogram(xData, yData, bins, maxY, peak2DHistogramTitle, peak2Dfilename)
for maxY in [1.05, 1.1, 1.2, 1.5, 2, 2.5, 3, 5, max(yData)]:
flarePlotTitle = flarePlotTitleArg
flarePlotFilename = flarePlotFilenameArg.replace("@maxY", str(maxY))
plotFlarePeaks(plotdata, filters, flarePlotLabels, flarePlotColors, maxY, flarePlotTitle, flarePlotFilename)
def plotStar(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)
pdcsapbinningData = []
foldedFits = []
locFolder = f"{folderPath}/stars/{starNameR}/"
mkdir_p(f"{locFolder}/")
csvFile = open(f"{locFolder}/{starNameR}.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["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']},{row['pdcsapSpotModulation']},{normPhase},{peak['FlarePeak']}")
csvFile.write("\n")
pdcsapbinningData.append({"SpType": f'{row["SpType"][0:2] if len(row["SpType"]) > 1 else row["SpType"][0]}',
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"]})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
foldedFits.append([normalizePhase(row["pdcsapFoldedFitPhase"]), row["pdcsapFoldedFit"]])
csvFile.close()
pdcsapbinningData = pd.DataFrame(pdcsapbinningData)
PDCSAPdataList = []
PDCSAPlabelList = []
PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = []
if(len(pdcsapbinningData) > 0):
if(pdcsapbinningData["SpType"][0][0] == "M"):
color = "red"
elif(pdcsapbinningData["SpType"][0][0] == "K"):
color = "orange"
elif(pdcsapbinningData["SpType"][0][0] == "G"):
color = "yellow"
elif(pdcsapbinningData["SpType"][0][0] == "F"):
color = "greenyellow"
else:
color = "gray"
PDCSAPdataList2dhistPhase.append(pdcsapbinningData[:]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningData[:]["Peak"])
xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningData, "PDCSAPNormPhase",
PDCSAPdataList)
PDCSAPcolorList.append(color)
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",
pdcsapbinningData, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY.png",
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):
PDCSAPdataListPeriod = []
PDCSAPlabelList = []
PDCSAPcolorList = []
PDCSAPdataList2dhistPhase = []
PDCSAPdataList2dhistPeak = []
if(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "M"):
color = "red"
elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "K"):
color = "orange"
elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "G"):
color = "yellow"
elif(pdcsapbinningDataSpotModDiffPeriod["SpType"][0][0] == "F"):
color = "greenyellow"
else:
color = "gray"
PDCSAPdataList2dhistPhase.append(pdcsapbinningDataSpotModDiffPeriod[:]["PDCSAPNormPhasePeriod"])
PDCSAPdataList2dhistPeak.append(pdcsapbinningDataSpotModDiffPeriod[:]["PeakPeriod"])
xData, yData, PDCSAPdataListPeriod = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningDataSpotModDiffPeriod, "PDCSAPNormPhasePeriod",
PDCSAPdataListPeriod)
PDCSAPlabelList.append(f"{starName}")
PDCSAPcolorList.append(color)
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",
pdcsapbinningDataSpotModDiffPeriod, None, f"{starName}", color, f"Flare peaks per phase of {starName}", f"{locFolder}/{starNameR}-Flarepeaks_maxY-@maxY_Period.png",
foldedPeriodFits)
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()
if("M" in combo):
Mfilter = data["SpType"].str.startswith("M")
Mfilter &= showSourceFilter
finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Mfilter]], ignore_index=True)
if("K" in combo):
Kfilter = data["SpType"].str.startswith("K")
Kfilter &= showSourceFilter
finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Kfilter]], ignore_index=True)
if("G" in combo):
Gfilter = data["SpType"].str.startswith("G")
Gfilter &= showSourceFilter
finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Gfilter]], ignore_index=True)
if("F" in combo):
Ffilter = data["SpType"].str.startswith("F")
Ffilter &= showSourceFilter
finalDataMaxFlarePeak = pd.concat([finalDataMaxFlarePeak, data[Ffilter]], ignore_index=True)
pdcsapbinningDataU = []
pdcsapbinningDataO = []
locFolderU = f"{folderPath}/{''.join(combo)}/maxFlarePeaks/{maxFlarePeak}/"
locFolderO = f"{folderPath}/{''.join(combo)}/minFlarePeaks/{maxFlarePeak}/"
mkdir_p(f"{locFolderU}/")
mkdir_p(f"{locFolderO}/")
csvFileU = open(f"{locFolderU}/{''.join(combo)}_maxFlarePeak_{maxFlarePeak}.csv", "a")
csvFileU.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Normalized Phase of Peak,Peak in Period")
csvFileU.write("\n")
csvFileO = open(f"{locFolderO}/{''.join(combo)}_minFlarePeak_{maxFlarePeak}.csv", "a")
csvFileO.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Normalized Phase of Peak,Peak in Period")
csvFileO.write("\n")
for ind, row in finalDataMaxFlarePeak.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))
csvFileU.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{normPhase},{peak['FlarePeak']}")
csvFileU.write("\n")
pdcsapbinningDataU.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
else:
normPhase = normalizePhase(td.value, np.abs(PDCSAPminOrigPhase), np.abs(PDCSAPmaxOrigPhase))
csvFileO.write(f"{row['StarName']},{row['SpType']},{row['Source']},{row['FilePath']},{pv['FlarePeakTime']},{pv['FlarePeak']},{row['pdcsapPeriod']},{normPhase},{peak['FlarePeak']}")
csvFileO.write("\n")
pdcsapbinningDataO.append({"SpType": row["SpType"][0],
"PDCSAPNormPhase": normPhase,
"Peak": peak["FlarePeak"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
csvFileU.close()
csvFileO.close()
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 = []
PDCSAPdataList2dhistPhaseU = []
PDCSAPdataList2dhistPeakU = []
plotFiltersU = []
if("M" in combo):
Mfilter = pdcsapbinningDataU["SpType"] == "M"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[Mfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[Mfilter]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[Mfilter]["PDCSAPNormPhase"])
PDCSAPlabelListU.append("M Stars")
PDCSAPcolorListU.append("red")
plotFiltersU.append(Mfilter)
if("K" in combo):
Kfilter = pdcsapbinningDataU["SpType"] == "K"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[Kfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[Kfilter]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[Kfilter]["PDCSAPNormPhase"])
PDCSAPlabelListU.append("K Stars")
PDCSAPcolorListU.append("orange")
plotFiltersU.append(Kfilter)
if("G" in combo):
Gfilter = pdcsapbinningDataU["SpType"] == "G"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[Gfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[Gfilter]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[Gfilter]["PDCSAPNormPhase"])
PDCSAPlabelListU.append("G Stars")
PDCSAPcolorListU.append("yellow")
plotFiltersU.append(Gfilter)
if("F" in combo):
Ffilter = pdcsapbinningDataU["SpType"] == "F"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[Ffilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[Ffilter]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[Ffilter]["PDCSAPNormPhase"])
PDCSAPlabelListU.append("F Stars")
PDCSAPcolorListU.append("greenyellow")
plotFiltersU.append(Ffilter)
xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU,
pdcsapbinningDataU, "PDCSAPNormPhase")
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",
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):
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 = []
PDCSAPdataList2dhistPhaseO = []
PDCSAPdataList2dhistPeakO = []
plotFiltersO = []
if("M" in combo):
Mfilter = pdcsapbinningDataO["SpType"] == "M"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[Mfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[Mfilter]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[Mfilter]["PDCSAPNormPhase"])
PDCSAPlabelListO.append("M Stars")
PDCSAPcolorListO.append("red")
plotFiltersO.append(Mfilter)
if("K" in combo):
Kfilter = pdcsapbinningDataO["SpType"] == "K"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[Kfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[Kfilter]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[Kfilter]["PDCSAPNormPhase"])
PDCSAPlabelListO.append("K Stars")
PDCSAPcolorListO.append("orange")
plotFiltersO.append(Kfilter)
if("G" in combo):
Gfilter = pdcsapbinningDataO["SpType"] == "G"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[Gfilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[Gfilter]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[Gfilter]["PDCSAPNormPhase"])
PDCSAPlabelListO.append("G Stars")
PDCSAPcolorListO.append("yellow")
plotFiltersO.append(Gfilter)
if("F" in combo):
Ffilter = pdcsapbinningDataO["SpType"] == "F"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[Ffilter]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[Ffilter]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[Ffilter]["PDCSAPNormPhase"])
PDCSAPlabelListO.append("F Stars")
PDCSAPcolorListO.append("greenyellow")
plotFiltersO.append(Ffilter)
xData, yData, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO,
pdcsapbinningDataO, "PDCSAPNormPhase")
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")
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"]
match mainSpType:
case "M":
color = "red"
case "K":
color = "orange"
case "G":
color = "yellow"
case "F":
color = "greenyellow"
for spTyp in spTypes:
finalDataAccSpTypes = pd.DataFrame()
typeFilter = data["SpType"].str.startswith(spTyp)
typeFilter &= showSourceFilter
finalDataAccSpTypes = pd.concat([finalDataAccSpTypes, data[typeFilter]], 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 finalDataAccSpTypes.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"],
"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["StarName"]))
pd.DataFrame(set(pdcsapbinningData["StarName"])).to_csv(f"{locFolder}/{spTyp}_starlist.csv")
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"])
PDCSAPlabelList.append(f"{spTyp} Stars")
PDCSAPcolorList.append(color)
xData, yData, PDCSAPdataList = setupxyDataAndDataList(PDCSAPdataList2dhistPhase, PDCSAPdataList2dhistPeak,
pdcsapbinningData, "PDCSAPNormPhase",
PDCSAPdataList, SpTypefilter)
plotdata = pdcsapbinningData
filters = SpTypefilter
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 ({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 ({numStarsAccSpType} stars)", f"{locFolder}/{''.join(spTyp)}-Flarepeaks_maxY-@maxY.png")
# per Period
for periodCut in periodsCutList:
finalDataPeriod = pd.DataFrame()
if("M" in combo):
Mfilter = data["SpType"].str.startswith("M")
Mfilter &= showSourceFilter
Mfilter &= data["PeriodWithinStd"] == True
finalDataPeriod = pd.concat([finalDataPeriod, data[Mfilter]], ignore_index=True)
if("K" in combo):
Kfilter = data["SpType"].str.startswith("K")
Kfilter &= showSourceFilter
Kfilter &= data["PeriodWithinStd"] == True
finalDataPeriod = pd.concat([finalDataPeriod, data[Kfilter]], ignore_index=True)
if("G" in combo):
Gfilter = data["SpType"].str.startswith("G")
Gfilter &= showSourceFilter
Gfilter &= data["PeriodWithinStd"] == True
finalDataPeriod = pd.concat([finalDataPeriod, data[Gfilter]], ignore_index=True)
if("F" in combo):
Ffilter = data["SpType"].str.startswith("F")
Ffilter &= showSourceFilter
Ffilter &= data["PeriodWithinStd"] == True
finalDataPeriod = pd.concat([finalDataPeriod, data[Ffilter]], ignore_index=True)
pdcsapbinningDataU = []
pdcsapbinningDataO = []
locFolder = f"{folderPath}/{''.join(combo)}/periodCuts/{periodCut}/"
mkdir_p(f"{locFolder}/")
csvFileU = open(f"{locFolder}/under_{periodCut}.csv", "a")
csvFileO = open(f"{locFolder}/over_{periodCut}.csv", "a")
csvFileU.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Mean Period,Normalized Phase of Peak,Peak in Period")
csvFileU.write("\n")
csvFileO.write("Star Name,Spectral Type,Source,File,Flare Time,Flare Peak,Period,Mean Period,Normalized Phase of Peak,Peak in Period")
csvFileO.write("\n")
for ind, row in finalDataPeriod.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))
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("\n")
pdcsapbinningDataU.append({"SpType": f'{row["SpType"][0]}',
"PDCSAPNormPhase": normPhase,
"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"],
"StarName": row['StarName']})
if(peak["FlarePeak"] > 100):
print(row["StarName"], "has over 100 peak")
csvFileU.close()
csvFileO.close()
pdcsapbinningDataU = pd.DataFrame(pdcsapbinningDataU)
pdcsapbinningDataO = pd.DataFrame(pdcsapbinningDataO)
PDCSAPdataListU = []; PDCSAPdataListO = []
PDCSAPlabelList = []
PDCSAPcolorList = []
PDCSAPdataList2dhistPhaseU = []; PDCSAPdataList2dhistPeakU = []
PDCSAPdataList2dhistPhaseO = []; PDCSAPdataList2dhistPeakO = []
plotFiltersU = []; plotFiltersO = [];
if("M" in combo):
PDCSAPlabelList.append("M Stars")
PDCSAPcolorList.append("red")
if("K" in combo):
PDCSAPlabelList.append("K Stars")
PDCSAPcolorList.append("orange")
if("G" in combo):
PDCSAPlabelList.append("G Stars")
PDCSAPcolorList.append("yellow")
if("F" in combo):
PDCSAPlabelList.append("F Stars")
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"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[MfilterU]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[MfilterU]["PDCSAPNormPhase"])
plotFiltersU.append(MfilterU)
if("K" in combo):
KfilterU = pdcsapbinningDataU["SpType"] == "K"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[KfilterU]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[KfilterU]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[KfilterU]["PDCSAPNormPhase"])
plotFiltersU.append(KfilterU)
if("G" in combo):
GfilterU = pdcsapbinningDataU["SpType"] == "G"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[GfilterU]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[GfilterU]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[GfilterU]["PDCSAPNormPhase"])
plotFiltersU.append(GfilterU)
if("F" in combo):
FfilterU = pdcsapbinningDataU["SpType"] == "F"
PDCSAPdataList2dhistPhaseU.append(pdcsapbinningDataU[FfilterU]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakU.append(pdcsapbinningDataU[FfilterU]["Peak"])
PDCSAPdataListU.append(pdcsapbinningDataU[FfilterU]["PDCSAPNormPhase"])
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"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[MfilterO]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[MfilterO]["PDCSAPNormPhase"])
plotFiltersO.append(MfilterO)
if("K" in combo):
KfilterO = pdcsapbinningDataO["SpType"] == "K"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[KfilterO]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[KfilterO]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[KfilterO]["PDCSAPNormPhase"])
plotFiltersO.append(KfilterO)
if("G" in combo):
GfilterO = pdcsapbinningDataO["SpType"] == "G"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[GfilterO]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[GfilterO]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[GfilterO]["PDCSAPNormPhase"])
plotFiltersO.append(GfilterO)
if("F" in combo):
FfilterO = pdcsapbinningDataO["SpType"] == "F"
PDCSAPdataList2dhistPhaseO.append(pdcsapbinningDataO[FfilterO]["PDCSAPNormPhase"])
PDCSAPdataList2dhistPeakO.append(pdcsapbinningDataO[FfilterO]["Peak"])
PDCSAPdataListO.append(pdcsapbinningDataO[FfilterO]["PDCSAPNormPhase"])
plotFiltersO.append(FfilterO)
if(len(PDCSAPdataList2dhistPhaseU) > 0 and len(PDCSAPdataList2dhistPeakU) > 0):
xDataU, yDataU, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseU, PDCSAPdataList2dhistPeakU,
pdcsapbinningDataU, "PDCSAPNormPhase",)
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, {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, {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, {numStarsPeriodU} stars)", f"{locFolder}/{''.join(combo)}-Flarepeaks-Period_u_{periodCut}-maxY_@maxY.png")
if(len(PDCSAPdataList2dhistPhaseO) > 0 and len(PDCSAPdataList2dhistPeakO) > 0):
xDataO, yDataO, _ = setupxyDataAndDataList(PDCSAPdataList2dhistPhaseO, PDCSAPdataList2dhistPeakO,
pdcsapbinningDataO, "PDCSAPNormPhase",)
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, {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, {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, {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
+182
View File
@@ -0,0 +1,182 @@
from astroquery.simbad import Simbad
from astroquery.vizier import Vizier
from astropy.coordinates import Angle
import pandas as pd
import numpy as np
from main.astrodatagui.db.StarsDB import StarDB
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
simbad = Simbad()
starDB: StarDB = StarDB.getInstance("stars.db")
bvStars = ["1RXS J064643.6-770027", "BD-08 995", "CPD-19 878", "PM J07058-5848", "TYC 1360-957-1", "TYC 4595-107-1"]
jhcStars = ["2MASS J18524052+4156057", "2MASS J18534407+4208274", "2MASS J18535462+4135227", "2MASS J19335656+4010546"]
filters = ["U", "B", "V", "R", "I", "J", "H", "K", "u", "g", "r", "i", "z", "G", "F150W", "F200W", "F444W"]
for f in filters:
simbad.add_votable_fields(f"flux({f})")
vizierTIC = Vizier(catalog="IV/38/tic",
columns=["TIC", "HIP", "TYC", "UCAC4", "2MASS", "GAIA", "KIC", "S/G", "Teff", "Rad", "Mass", "LClass", "Dist"])
spTypeTable = pd.read_csv("cousins.cols")
weights = {"SpType": 0.0,
"U-B": 2.0,
"B-V": 2.0,
"V-R": 0.8,
"V-I": 0.7,
"V-J": 0.6,
"V-H": 0.5,
"V-K": 0.4,
"V-L": 0.0,
"V-M": 0.0,
"V-N": 0.0}
spTypeTeffMinTable = {2700: "M",
4000: "K",
5440: "G",
6300: "F",
7920: "A"}
def getSpTypeFromTeff(Teff):
if(Teff >= 25000):
return "O"
elif(Teff >= 10000):
return "B"
elif(Teff >= 7500):
return "A"
elif(Teff >= 6000):
return "F"
elif(Teff >= 5000):
return "G"
elif(Teff >= 3500):
return "K"
#elif(Teff >= 2700):
# return "M"
else:
return "M"
resTable = {"StarID": [],
"simbad B-V": [],
"simbad SpType": [],
"vizier Teff": [],
"vizier Mass": [],
"vizier Radius": [],
"vizier SpType": [],
"vizier Lum. Class": [],
"Final SpType": []}
resTable = pd.DataFrame(resTable)
allStars = []
allStars.extend(bvStars)
allStars.extend(jhcStars)
for star in allStars:
star = simbad.query_object(star)
U_B = star["FLUX_U"] - star["FLUX_B"]
B_V = star["FLUX_B"] - star["FLUX_V"]
V_R = star["FLUX_V"] - star["FLUX_R"]
V_I = star["FLUX_V"] - star["FLUX_I"]
V_J = star["FLUX_V"] - star["FLUX_J"]
V_H = star["FLUX_V"] - star["FLUX_H"]
V_K = star["FLUX_V"] - star["FLUX_K"]
fluxDiff = {"U-B": U_B,
"B-V": B_V,
"V-R": V_R,
"V-I": V_I,
"V-J": V_J,
"V-H": V_H,
"V-K": V_K}
fluxDiff = pd.DataFrame(fluxDiff)
fluxDiffValColumns = fluxDiff.columns[fluxDiff.notna().iloc[0]]
matchingColumnsUBVIJHK = spTypeTable.columns.intersection(fluxDiffValColumns)
distancesUBV = spTypeTable[matchingColumnsUBVIJHK].sub(fluxDiff.iloc[0]).pow(2).sum(axis=1)
bestMatchIndexUBVIJHK = distancesUBV.idxmin()
bestMatchNameUBV = spTypeTable.iloc[bestMatchIndexUBVIJHK, 0]
distancesUBVIJHKweighted = (
spTypeTable[matchingColumnsUBVIJHK]
.sub(fluxDiff.iloc[0][matchingColumnsUBVIJHK])
.pow(2)
.multiply([weights[col] for col in matchingColumnsUBVIJHK], axis=1)
.sum(axis=1)
)
bestMatchIndexUBVIJHKweighted = distancesUBVIJHKweighted.idxmin()
bestMatchNameUBVweighted = spTypeTable.iloc[bestMatchIndexUBVIJHKweighted, 0]
distancesUBVonlyWeighted = (
spTypeTable[matchingColumnsUBVIJHK]
.sub(fluxDiff.iloc[0][matchingColumnsUBVIJHK])
.pow(2)
.multiply([1.0 if(col == "U-B" or col == "B-V") else 0.0 for col in matchingColumnsUBVIJHK], axis=1)
.sum(axis=1)
)
bestMatchIndexUBVonlyWeighted = distancesUBVonlyWeighted.idxmin()
bestMatchNameUBVonlyWeighted = spTypeTable.iloc[bestMatchIndexUBVonlyWeighted, 0] if (not np.isnan(U_B) or not np.isnan(B_V)) else ""
starName = star['MAIN_ID'].value[0]
regionResults = vizierTIC.query_region(starName,
radius=Angle(5, "arcsec"))
altNames = [an[0] for an in starDB.getStarAltNames(starName)[:-1]]
vizierTable = None
for reg in regionResults:
for row in reg:
for aN in altNames:
if((str(row["TIC"]) in aN or
str(row["GAIA"]) in aN or
str(row["_2MASS"]) in aN) and
row["LClass"] == "DWARF"):
vizierTable = row
break
else:
continue
break
else:
continue
break
Teff = vizierTable["Teff"]
vizierSpType = getSpTypeFromTeff(Teff)
finalSpType = ""
if(bestMatchNameUBVonlyWeighted == "" or
bestMatchNameUBVonlyWeighted[0] == vizierSpType):
finalSpType = vizierSpType
else:
if(bestMatchNameUBVonlyWeighted[1] == "0"):
finalSpType = vizierSpType
else:
finalSpType = bestMatchNameUBVonlyWeighted[0]
if(vizierTable is None):
resTable = pd.concat([resTable,
pd.DataFrame([[starName, B_V[0], bestMatchNameUBVonlyWeighted,
"", "", "", "", "",
finalSpType]],
columns=resTable.columns)],
ignore_index=True)
else:
resTable = pd.concat([resTable,
pd.DataFrame([[starName, B_V[0], bestMatchNameUBVonlyWeighted,
vizierTable["Teff"], vizierTable["Mass"], vizierTable["Rad"], vizierSpType, vizierTable["LClass"],
finalSpType]],
columns=resTable.columns)],
ignore_index=True)
print(resTable.to_string())
for index, row in resTable.iterrows():
starDB.updateStarInfoSpType(row["StarID"], row["Final SpType"])
+16 -2
View File
@@ -42,6 +42,9 @@ class AstrodataGUI(QtWidgets.QMainWindow):
self.cbPlotFlattenPlotEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked) self.cbPlotFlattenPlotEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked)
self.cbPlotFoldEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked) self.cbPlotFoldEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked)
self.cbPlotPeriodogramEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked) self.cbPlotPeriodogramEnable.stateChanged.connect(self.plotOptionsExclusiveCBChecked)
self.cbPlotFoldShowSpotModulation.stateChanged.connect(self.plotOptionsCBChecked)
self.gbPlotFoldOptimize.toggled.connect(self.plotOptionsCBChecked)
self.comboPlotFluxType.currentTextChanged.connect(self.plotOptionsComboBoxTextChanged) self.comboPlotFluxType.currentTextChanged.connect(self.plotOptionsComboBoxTextChanged)
self.comboPlotNormalizeUnit.currentTextChanged.connect(self.plotOptionsComboBoxTextChanged) self.comboPlotNormalizeUnit.currentTextChanged.connect(self.plotOptionsComboBoxTextChanged)
@@ -251,7 +254,10 @@ class AstrodataGUI(QtWidgets.QMainWindow):
self.flaredetectorPreview.setFoldedFitType(self.foldedFitType) self.flaredetectorPreview.setFoldedFitType(self.foldedFitType)
def updatePeriods(self, periods: list): def updatePeriods(self, periods: list):
self.edPlotFoldPeriod.setText(str(periods[0].value)) try:
self.edPlotFoldPeriod.setText(str(periods[0].value))
except:
self.edPlotFoldPeriod.setText(str(periods[0]))
def updateEpochPeriod(self, epoch: float): def updateEpochPeriod(self, epoch: float):
self.edPlotFoldEpochTime.setText(str(epoch)) self.edPlotFoldEpochTime.setText(str(epoch))
@@ -281,6 +287,11 @@ class AstrodataGUI(QtWidgets.QMainWindow):
case self.cbPlotBinEnable: case self.cbPlotBinEnable:
self.updateFlaredetectionWidgetBin() self.updateFlaredetectionWidgetBin()
case self.gbPlotFoldOptimize:
self.updateFlaredetectionWidgetFold()
case self.cbPlotFoldShowSpotModulation:
self.updateFlaredetectionWidgetFold()
def plotOptionsExclusiveCBChecked(self, state): def plotOptionsExclusiveCBChecked(self, state):
print(f"{self.sender().objectName()} is set to {state}") print(f"{self.sender().objectName()} is set to {state}")
if(state == QtCore.Qt.Checked): if(state == QtCore.Qt.Checked):
@@ -395,13 +406,16 @@ class AstrodataGUI(QtWidgets.QMainWindow):
def updateFlaredetectionWidgetFold(self): def updateFlaredetectionWidgetFold(self):
foldEnabled = self.cbPlotFoldEnable.isChecked() foldEnabled = self.cbPlotFoldEnable.isChecked()
optimizeEnabled = self.gbPlotFoldOptimize.isChecked()
showSpotModulationEnabled = self.cbPlotFoldShowSpotModulation.isChecked()
try: try:
period = float(self.edPlotFoldPeriod.text()) period = float(self.edPlotFoldPeriod.text())
epoch = float(self.edPlotFoldEpochTime.text()) epoch = float(self.edPlotFoldEpochTime.text())
except: except:
print(f"Invalid period/epoch detected, aborting") print(f"Invalid period/epoch detected, aborting")
return return
self.flaredetectorPreview.setFoldState(foldEnabled, period, epoch) self.flaredetectorPreview.setFoldState(foldEnabled, period, epoch, optimizeEnabled, showSpotModulationEnabled)
def updateFlaredetectionWidgetPeriodogram(self): def updateFlaredetectionWidgetPeriodogram(self):
periodogramEnabled = self.cbPlotPeriodogramEnable.isChecked() periodogramEnabled = self.cbPlotPeriodogramEnable.isChecked()
+145 -56
View File
@@ -1,7 +1,9 @@
from PyQt5.QtCore import pyqtSignal, QThread from PyQt5.QtCore import pyqtSignal, QThread
import multiprocessing import multiprocessing
import concurrent.futures 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 import pandas as pd
from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
from ..flaredetector.util import * from ..flaredetector.util import *
@@ -9,76 +11,163 @@ from ..flaredetector.util import *
import warnings import warnings
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
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'''
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): def getFlareCount(filesDict):
try: try:
print(f"Starting {filesDict['StarName']}, {filesDict['Sequence']}") print(f"Starting {filesDict['StarName']}, {filesDict['Sequence']}")
lc = read(filesDict["FilePath"]) starName = filesDict['StarName']
lc.flux = lc["sap_flux"] starNameR = filesDict['StarName'].replace("*", "_star_")
lc.flux_err = lc["sap_flux_err"] source = filesDict['Source']
sapPeaks, sapFits = calculateFlareFitsForLightcurve(lc.flatten()) sequence = filesDict['Sequence']
sapValSec, sapTds = getTotalValidDataInSeconds(lc, "sap_flux") starFolder = f"{folderPath}/stars/{starNameR}/"
sapPeriodogram = lc.to_periodogram() mkdir_p(starFolder)
sapPeakPeriod = sapPeriodogram.period[findMaxIndices(sapPeriodogram, num=4, distance=100, sortByHighest=True)[0]]
sapEpochTime = getEpochTime(lc)
sapFoldedLC = lc.fold(period=sapPeakPeriod, epoch_time=sapEpochTime)
sapPhase, sapSineFit, sapFitType = getFoldedBestFit(sapFoldedLC, fitType=filesDict["FitType"])
sapMinima, sapMaxima = getFoldedFitPeakValley(sapSineFit)
sapminPhasesBounds, sapmaxPhasesBounds = getPhaseRangesNearPeak((sapMinima, sapMaxima), sapPhase, returnPhaseValue=True)
sapFoldedPeaks = []
sapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(sapFoldedLC, peak["StandardIndex"])
sapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
sapFoldedPeaksPhasePair.append({"Phase": sapFoldedLC.phase[sapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
lc = lk.read(filesDict["FilePath"])
lc.flux = lc["pdcsap_flux"] lc.flux = lc["pdcsap_flux"]
lc.flux_err = lc["pdcsap_flux_err"] 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}_{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", bbox_inches="tight")
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}_{source}-{sequence}-lc-marked_flares.png", bbox_inches="tight")
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}_{source}-{sequence}-flattened_lc-marked_flares.png", bbox_inches="tight")
plt.close()
pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux") pdcsapValSec, pdcsapTds = getTotalValidDataInSeconds(lc, "pdcsap_flux")
pdcsapPeriodogram = lc.to_periodogram() 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]
pdcsapEpochTime = getEpochTime(lc) pdcsapPeakPeriod = pdcsapPeriodogram.period[maxPeriodIndex]
pdcsapFoldedLC = lc.fold(period=pdcsapPeakPeriod, epoch_time=pdcsapEpochTime)
pdcsapPhase, pdcsapSineFit, pdcsapFitType = getFoldedBestFit(pdcsapFoldedLC, fitType=filesDict["FitType"])
pdcsapMinima, pdcsapMaxima = getFoldedFitPeakValley(pdcsapSineFit)
pdcsapminPhasesBounds, pdcsapmaxPhasesBounds = getPhaseRangesNearPeak((pdcsapMinima, pdcsapMaxima), pdcsapPhase, returnPhaseValue=True)
pdcsapFoldedPeaks = []
pdcsapFoldedPeaksPhasePair = []
for peak in sapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(pdcsapFoldedLC, peak["StandardIndex"])
pdcsapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapFoldedPeaksPhasePair.append({"Phase": pdcsapFoldedLC.phase[pdcsapFoldedLC.cycle == cycle][foldedIndex], "Peak": peak})
filesDict["sapPeaks"] = sapPeaks pdcsapPeriodogram.plot(view="period")
filesDict["sapPeaksCount"] = len(sapPeaks) plt.plot(pdcsapPeakPeriod, pdcsapPeriodogram.power[maxPeriodIndex], "x", color="red")
filesDict["sapFits"] = sapFits plt.savefig(f"{starFolder}/{starNameR}_{source}-{sequence}-periodogram-marked_max.png", bbox_inches="tight")
filesDict["sapValidTimespans"] = sapTds plt.close()
filesDict["sapValidSeconds"] = sapValSec
filesDict["sapFoldedCycle"] = sapFoldedLC.cycle #pdcsapEpochTime = getEpochTime(lc)
#filesDict["sapFoldedPhase"] = sapFoldedLC.phase.value #pdcsapFoldedLC = lc.fold(period=pdcsapPeakPeriod, epoch_time=pdcsapEpochTime)
#filesDict["sapFoldedFitPhase"] = sapPhase #pdcsapPhase, pdcsapSineFit, pdcsapFitType = getFoldedBestFit(pdcsapFoldedLC, fitType=filesDict["FitType"])
filesDict["sapFoldedFitPhaseStarEnd"] = (sapFoldedLC.phase.value[0], sapFoldedLC.phase.value[-1]) optimizedFit = getOptimizedFold(lc.normalize(), filesDict["FitType"])
filesDict["sapFoldedPeaksPhasePair"] = sapFoldedPeaksPhasePair #pdcsapMinima, pdcsapMaxima = getFoldedFitPeakValley(pdcsapSineFit)
filesDict["sapPeriod"] = sapPeakPeriod.value #pdcsapminPhasesBounds, pdcsapmaxPhasesBounds = getPhaseRangesNearPeak((pdcsapMinima, pdcsapMaxima), pdcsapPhase, returnPhaseValue=True)
filesDict["sapPeriodMinima"] = sapMinima pdcsapFoldedPeaks = []; pdcsapPeriodFoldedPeaks = []
filesDict["sapPeriodMinimaBoundaries"] = sapminPhasesBounds pdcsapFoldedPeaksPhasePair = []; pdcsapPeriodFoldedPeaksPhasePair = []
filesDict["sapPeriodMaxima"] = sapMaxima optimizedFit["foldedLC"].scatter()
filesDict["sapPeriodMaximaBoundaries"] = sapmaxPhasesBounds plt.title(f"{starName} - folded lightcurve")
plt.plot(optimizedFit["phase"], optimizedFit["fit"], color="blue", label=f"{optimizedFit['fitType']}-fit")
for peak in pdcsapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(optimizedFit["foldedLC"], peak["StandardIndex"])
pdcsapFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapFoldedPeaksPhasePair.append({"Phase": optimizedFit["foldedLC"].phase[optimizedFit["foldedLC"].cycle == cycle][foldedIndex], "Peak": peak})
plt.plot(optimizedFit["foldedLC"].phase[optimizedFit["foldedLC"].cycle == cycle][foldedIndex].value,
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", bbox_inches="tight")
plt.close()
if(optimizedFit["periodFoldedLC"] is not None):
optimizedFit["periodFoldedLC"].scatter()
plt.title(f"{starName} - folded lightcurve")
plt.plot(optimizedFit["periodFoldedPhase"], optimizedFit["periodFoldedFit"], color="blue", label=f"{optimizedFit['fitType']}-fit")
for peak in pdcsapPeaks:
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(optimizedFit["periodFoldedLC"], peak["StandardIndex"])
pdcsapPeriodFoldedPeaks.append({"Cycle: ": cycle, "Index": foldedIndex})
pdcsapPeriodFoldedPeaksPhasePair.append({"Phase": optimizedFit["periodFoldedLC"].phase[optimizedFit["periodFoldedLC"].cycle == cycle][foldedIndex], "Peak": peak})
plt.plot(optimizedFit["periodFoldedLC"].phase[optimizedFit["periodFoldedLC"].cycle == cycle][foldedIndex].value,
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", bbox_inches="tight")
plt.close()
filesDict["pdcsapPeaks"] = pdcsapPeaks filesDict["pdcsapPeaks"] = pdcsapPeaks
filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks) filesDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
filesDict["pdcsapFits"] = pdcsapFits filesDict["pdcsapFits"] = pdcsapFits
filesDict["pdcsapValidTimespans"] = pdcsapTds filesDict["pdcsapValidTimespans"] = pdcsapTds
filesDict["pdcsapValidSeconds"] = pdcsapValSec filesDict["pdcsapValidSeconds"] = pdcsapValSec
filesDict["pdcsapFoldedCycle"] = sapFoldedLC.cycle filesDict["pdcsapFoldedEpoch"] = optimizedFit["epoch"]
#filesDict["pdcsapFoldedPhase"] = sapFoldedLC.phase.value filesDict["pdcsapFoldedCycle"] = optimizedFit["foldedLC"].cycle
#filesDict["pdcsapFoldedFitPhase"] = pdcsapPhase filesDict["pdcsapFoldedPhase"] = optimizedFit["foldedLC"].phase.value
filesDict["pdcsapFoldedFitPhaseStarEnd"] = (pdcsapFoldedLC.phase.value[0], pdcsapFoldedLC.phase.value[-1]) filesDict["pdcsapFoldedFitPhase"] = optimizedFit["phase"]
filesDict["pdcsapFoldedFit"] = optimizedFit["fit"]
filesDict["pdcsapFoldedFitPhaseStarEnd"] = (optimizedFit["foldedLC"].phase.value[0], optimizedFit["foldedLC"].phase.value[-1])
filesDict["pdcsapFoldedPeaksPhasePair"] = pdcsapFoldedPeaksPhasePair filesDict["pdcsapFoldedPeaksPhasePair"] = pdcsapFoldedPeaksPhasePair
filesDict["pdcsapPeriod"] = pdcsapPeakPeriod.value filesDict["pdcsapPeriod"] = optimizedFit["Period"]
filesDict["pdcsapPeriodMinima"] = pdcsapMinima filesDict["pdcsapSpotModulation"] = optimizedFit["SpotModulation"]
filesDict["pdcsapPeriodMinimaBoundaries"] = pdcsapminPhasesBounds filesDict['FitType'] = optimizedFit["fitType"]
filesDict["pdcsapPeriodMaxima"] = pdcsapMaxima
filesDict["pdcsapPeriodMaximaBoundaries"] = pdcsapmaxPhasesBounds filesDict["pdcsapPeriodFoldedCycle"] = optimizedFit["periodFoldedLC"].cycle if optimizedFit["periodFoldedLC"] is not None else None
filesDict["pdcsapPeriodFoldedPhase"] = optimizedFit["periodFoldedLC"].phase.value if optimizedFit["periodFoldedLC"] is not None else None
filesDict["pdcsapPeriodFoldedFitPhase"] = optimizedFit["periodFoldedPhase"]
filesDict["pdcsapPeriodFoldedFit"] = optimizedFit["periodFoldedFit"]
filesDict["pdcsapPeriodFoldedFitPhaseStarEnd"] = (optimizedFit["periodFoldedLC"].phase.value[0], optimizedFit["periodFoldedLC"].phase.value[-1]) if optimizedFit["periodFoldedLC"] is not None else (None, None)
filesDict["pdcsapPeriodFoldedPeaksPhasePair"] = pdcsapPeriodFoldedPeaksPhasePair
filesDict['periodFitType'] = optimizedFit["periodFitType"]
filesDict["isValidFold"] = optimizedFit["isValid"]
csvFile = open(f"{starFolder}/{starNameR}_{source}-{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']},{optimizedFit['fitType']}")
csvFile.close()
del lc del lc
print(f"Finished {filesDict['StarName']}, {filesDict['Sequence']}") print(f"Finished {filesDict['StarName']}, {filesDict['Sequence']}")
return filesDict return filesDict
+352 -171
View File
@@ -1,6 +1,6 @@
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QGridLayout, from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QGridLayout,
QPushButton, QCheckBox, QLabel) QPushButton, QCheckBox, QLabel, QLineEdit)
from matplotlib.figure import Figure from matplotlib.figure import Figure
from matplotlib.backends.backend_qtagg import ( from matplotlib.backends.backend_qtagg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar) FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
@@ -41,6 +41,13 @@ def sumArrayLengthsNorm(series):
sumRes += len(s) sumRes += len(s)
return sumRes / len(series) 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): class FlareSummaryPlotGUI(QWidget):
def __init__(self, starFLareDictList): def __init__(self, starFLareDictList):
@@ -87,6 +94,11 @@ class FlareSummaryPlotGUI(QWidget):
self.btShowFlaresInMinimaMaximaPerMinimaMaxima = QPushButton("Show num Flares Minima/Maxima normalized") self.btShowFlaresInMinimaMaximaPerMinimaMaxima = QPushButton("Show num Flares Minima/Maxima normalized")
self.btShowFlaresInMinimaMaximaPerMinimaMaxima.clicked.connect(self.btShowFlaresInMinimaMaximaPerMinimaMaximaClicked) 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 = QCheckBox("Kepler")
self.cbKepler.setChecked(True) self.cbKepler.setChecked(True)
self.cbK2 = QCheckBox("K2") self.cbK2 = QCheckBox("K2")
@@ -95,7 +107,7 @@ class FlareSummaryPlotGUI(QWidget):
self.cbTESS.setChecked(True) self.cbTESS.setChecked(True)
self.cbSpTypeL = QCheckBox("L") self.cbSpTypeL = QCheckBox("L")
self.cbSpTypeL.setChecked(True) self.cbSpTypeL.setChecked(False)
self.cbSpTypeM = QCheckBox("M") self.cbSpTypeM = QCheckBox("M")
self.cbSpTypeM.setChecked(True) self.cbSpTypeM.setChecked(True)
self.cbSpTypeK = QCheckBox("K") self.cbSpTypeK = QCheckBox("K")
@@ -105,10 +117,10 @@ class FlareSummaryPlotGUI(QWidget):
self.cbSpTypeF = QCheckBox("F") self.cbSpTypeF = QCheckBox("F")
self.cbSpTypeF.setChecked(True) self.cbSpTypeF.setChecked(True)
self.cbSpTypeUnknown = QCheckBox("Unknown") self.cbSpTypeUnknown = QCheckBox("Unknown")
self.cbSpTypeUnknown.setChecked(True) 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)
@@ -117,10 +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.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)
@@ -128,14 +142,14 @@ class FlareSummaryPlotGUI(QWidget):
self.buttonGridLayout.addWidget(self.cbTESS, 1, 3) self.buttonGridLayout.addWidget(self.cbTESS, 1, 3)
self.buttonGridLayout.addWidget(QLabel("Sp Types: "), 2, 0) self.buttonGridLayout.addWidget(QLabel("Sp Types: "), 2, 0)
self.buttonGridLayout.addWidget(self.cbSpTypeL, 2, 1) #self.buttonGridLayout.addWidget(self.cbSpTypeL, 2, 1)
self.buttonGridLayout.addWidget(self.cbSpTypeM, 2, 2) self.buttonGridLayout.addWidget(self.cbSpTypeM, 2, 1)
self.buttonGridLayout.addWidget(self.cbSpTypeK, 2, 3) self.buttonGridLayout.addWidget(self.cbSpTypeK, 2, 2)
self.buttonGridLayout.addWidget(self.cbSpTypeG, 2, 4) self.buttonGridLayout.addWidget(self.cbSpTypeG, 2, 3)
self.buttonGridLayout.addWidget(self.cbSpTypeF, 2, 5) 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)
@@ -229,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)
@@ -263,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()):
@@ -331,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)
@@ -366,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()):
@@ -448,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)
@@ -485,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()):
@@ -568,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)
@@ -595,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()):
@@ -704,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)
@@ -731,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()):
@@ -840,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)
@@ -867,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",
@@ -997,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)
@@ -1024,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"],
@@ -1042,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()):
@@ -1295,3 +1211,268 @@ class FlareSummaryPlotGUI(QWidget):
print("Total Minima: ", PDCSAPtotalMin) print("Total Minima: ", PDCSAPtotalMin)
print("Total Maxima: ", PDCSAPtotalMax) 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()
+262 -78
View File
@@ -174,6 +174,21 @@
<string>Sequences/Target Table ID</string> <string>Sequences/Target Table ID</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
@@ -255,12 +270,39 @@
<string>Plot options</string> <string>Plot options</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
<item> <item>
<layout class="QGridLayout" name="gridLayout_11"> <layout class="QGridLayout" name="gridLayout_11">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="label_19">
<property name="sizePolicy"> <property name="sizePolicy">
@@ -284,12 +326,12 @@
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>sap_flux</string> <string>pdcsap_flux</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>pdcsap_flux</string> <string>sap_flux</string>
</property> </property>
</item> </item>
</widget> </widget>
@@ -346,6 +388,21 @@
<string>Normalize</string> <string>Normalize</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_12"> <widget class="QLabel" name="label_12">
<property name="text"> <property name="text">
@@ -412,6 +469,21 @@
<string>Remove Outliers</string> <string>Remove Outliers</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="cbPlotRemoveOutliersEnable"> <widget class="QCheckBox" name="cbPlotRemoveOutliersEnable">
<property name="text"> <property name="text">
@@ -464,6 +536,21 @@
<string>Remove nans/infs</string> <string>Remove nans/infs</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_10"> <layout class="QGridLayout" name="gridLayout_10">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="cbPlotRemoveNansEnable"> <widget class="QCheckBox" name="cbPlotRemoveNansEnable">
<property name="sizePolicy"> <property name="sizePolicy">
@@ -522,6 +609,21 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="label_11">
<property name="text"> <property name="text">
@@ -625,6 +727,21 @@
<string>Flatten</string> <string>Flatten</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="label_14">
<property name="text"> <property name="text">
@@ -706,84 +823,31 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0"> <item row="0" column="1">
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>Epoch Time: </string> <string>Enable</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="4" column="1">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Period: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="edPlotFoldPeriod">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="edPlotFoldEpochTime"> <widget class="QLineEdit" name="edPlotFoldEpochTime">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -808,6 +872,31 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Period: </string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="cbPlotFoldEnable"> <widget class="QCheckBox" name="cbPlotFoldEnable">
<property name="text"> <property name="text">
@@ -815,11 +904,76 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="3" column="1">
<widget class="QLabel" name="label_10"> <widget class="QLineEdit" name="edPlotFoldPeriod">
<property name="text"> <property name="sizePolicy">
<string>Enable</string> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Epoch Time: </string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QGroupBox" name="gbPlotFoldOptimize">
<property name="title">
<string>Optimize</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="cbPlotFoldShowSpotModulation">
<property name="text">
<string>Show Spot Modulation</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -856,6 +1010,21 @@
<string>Periodogram</string> <string>Periodogram</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_9"> <layout class="QGridLayout" name="gridLayout_9">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_20"> <widget class="QLabel" name="label_20">
<property name="text"> <property name="text">
@@ -966,6 +1135,21 @@
<string>Star infos</string> <string>Star infos</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0"> <item row="1" column="0">
+19 -1
View File
@@ -163,14 +163,32 @@ class StarDB():
else: else:
raise Exception(f"Fit type {fitType} not supported, must be one of {supportedFitTypes}") 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): def getAllStars(self):
res = self.dbCursor.execute("""SELECT DISTINCT mainName FROM stars res = self.dbCursor.execute("""SELECT DISTINCT mainName FROM stars
ORDER BY mainName""") ORDER BY mainName""")
resList = [] resList = []
for s in res.fetchall(): for s in res.fetchall():
resList.append(s[0]) resList.append(s[0])
print(f"Loading {len(resList)} stars")
return resList 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): def getStarSequences(self, mainName):
res = self.dbCursor.execute(f"""SELECT sourceName, sequence FROM stars res = self.dbCursor.execute(f"""SELECT sourceName, sequence FROM stars
WHERE mainName = \"{mainName}\" WHERE mainName = \"{mainName}\"
+46 -17
View File
@@ -51,14 +51,14 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.periodogramInfoGroupBox.setSizePolicy(sp) self.periodogramInfoGroupBox.setSizePolicy(sp)
self.mainLayout.addWidget(self.periodogramInfoGroupBox) self.mainLayout.addWidget(self.periodogramInfoGroupBox)
self.fluxType = "sap_flux" self.fluxType = "pdcsap_flux"
self.fluxErrType = "sap_flux_err" self.fluxErrType = "pdcsap_flux_err"
self.NormalizeState = {"Enabled": False, "Scale": "unscaled"} self.NormalizeState = {"Enabled": False, "Scale": "unscaled"}
self.RemoveOutliersState = {"Enabled": False, "Sigma": 5.0} self.RemoveOutliersState = {"Enabled": False, "Sigma": 5.0}
self.RemoveNansState = {"Enabled": False} self.RemoveNansState = {"Enabled": False}
self.BinState = {"Enabled": False, "Size": None} self.BinState = {"Enabled": False, "Size": None}
self.FlattenState = {"Enabled": False, "WindowLength": 101, "PolynomialOrder": 2} self.FlattenState = {"Enabled": False, "WindowLength": 101, "PolynomialOrder": 2}
self.FoldState = {"Enabled": False, "Period": 1, "EpochTime": 0} self.FoldState = {"Enabled": False, "Period": 1, "EpochTime": 0, "Optimize": False, "spotModulation": False}
self.PeriodogramState = {"Enabled": False, "Method": "lombscargle", "View": "frequency"} self.PeriodogramState = {"Enabled": False, "Method": "lombscargle", "View": "frequency"}
self.ShowQualityState = {"Enabled": False} self.ShowQualityState = {"Enabled": False}
@@ -66,7 +66,10 @@ class FlaredetectorWidget(QtWidgets.QWidget):
print(f"Plotting: {fitsFilePath}") print(f"Plotting: {fitsFilePath}")
self.currentLC = lk.read(fitsFilePath) self.currentLC = lk.read(fitsFilePath)
if(isinstance(self.currentLC, lk.lightcurve.KeplerLightCurve)): if(isinstance(self.currentLC, lk.lightcurve.KeplerLightCurve)):
print(f"Kepler Quarter: {self.currentLC.hdu[0].header['QUARTER']}") try:
print(f"Kepler Quarter: {self.currentLC.hdu[0].header['QUARTER']}")
except:
print("K2 Data, no QUARTER in header")
self.currentLCCollection = None self.currentLCCollection = None
self.currentMainName = mainName self.currentMainName = mainName
self.updateFit() self.updateFit()
@@ -153,8 +156,10 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.updateFit() self.updateFit()
self.updatePlot() self.updatePlot()
def setFoldState(self, enabled: bool, period: float, epoch: float): def setFoldState(self, enabled: bool, period: float, epoch: float, optimize: bool, spotModulation: bool):
self.FoldState["Enabled"] = enabled self.FoldState["Enabled"] = enabled
self.FoldState["Optimize"] = optimize
self.FoldState["SpotModulation"] = spotModulation
if(period < 0): if(period < 0):
print(f"Negative period detected, setting default 1") print(f"Negative period detected, setting default 1")
period = 1 period = 1
@@ -210,7 +215,7 @@ class FlaredetectorWidget(QtWidgets.QWidget):
self.currentFlattenLC = lc.flatten(window_length=self.FlattenState["WindowLength"], self.currentFlattenLC = lc.flatten(window_length=self.FlattenState["WindowLength"],
polyorder=self.FlattenState["PolynomialOrder"]) polyorder=self.FlattenState["PolynomialOrder"])
self.foldedLC = lc.to_periodogram(method=self.PeriodogramState["Method"]) 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.periods = [self.foldedLC.period[i] for i in findMaxIndices(self.foldedLC, num=4, distance=100, sortByHighest=True)]
self.epoch_time = getEpochTime(lc) self.epoch_time = getEpochTime(lc)
self.periodsCalculated.emit(self.periods) self.periodsCalculated.emit(self.periods)
@@ -243,8 +248,28 @@ class FlaredetectorWidget(QtWidgets.QWidget):
lc = self.currentFlattenLC lc = self.currentFlattenLC
label += " - flattened" label += " - flattened"
if(self.FoldState["Enabled"]): if(self.FoldState["Enabled"]):
lc = lc.fold(period=self.FoldState["Period"], if(self.FoldState["Optimize"]):
epoch_time=self.FoldState["EpochTime"]) optimizedFold = getOptimizedFold(lc.normalize(), self.foldedFitType)
if(self.FoldState["SpotModulation"]):
lc = optimizedFold["foldedLC"]
self.periodsCalculated.emit([optimizedFold["SpotModulation"]])
foldOptimizePhase = optimizedFold["phase"]
foldOptimizeFit = optimizedFold["fit"]
elif(not self.FoldState["SpotModulation"] and optimizedFold["periodFoldedLC"] is not None):
lc = optimizedFold["periodFoldedLC"]
self.periodsCalculated.emit([optimizedFold["Period"]])
foldOptimizePhase = optimizedFold["periodFoldedPhase"]
foldOptimizeFit = optimizedFold["periodFoldedFit"]
else:
lc = optimizedFold["foldedLC"]
self.periodsCalculated.emit([optimizedFold["SpotModulation"]])
foldOptimizePhase = optimizedFold["phase"]
foldOptimizeFit = optimizedFold["fit"]
print("SpotModulation", self.FoldState["SpotModulation"])
self.epochCalculated.emit(optimizedFold["epoch"])
else:
lc = lc.fold(period=self.FoldState["Period"],
epoch_time=self.FoldState["EpochTime"])
label += " - folded" label += " - folded"
if(self.PeriodogramState["Enabled"]): if(self.PeriodogramState["Enabled"]):
lc = lc.to_periodogram(method=self.PeriodogramState["Method"]) lc = lc.to_periodogram(method=self.PeriodogramState["Method"])
@@ -268,15 +293,19 @@ class FlaredetectorWidget(QtWidgets.QWidget):
cycle, foldedIndex = convertStarndardIndexToFoldedIndex(lc, peak["StandardIndex"]) cycle, foldedIndex = convertStarndardIndexToFoldedIndex(lc, peak["StandardIndex"])
self.figureAxis.plot(lc.phase[lc.cycle == cycle][foldedIndex].value, self.figureAxis.plot(lc.phase[lc.cycle == cycle][foldedIndex].value,
lc.flux[lc.cycle == cycle][foldedIndex], "x", color="red") lc.flux[lc.cycle == cycle][foldedIndex], "x", color="red")
try: if(self.FoldState["Optimize"]):
phase, sineFit, _ = getFoldedBestFit(lc, fitType=self.foldedFitType) self.figureAxis.plot(foldOptimizePhase, foldOptimizeFit, color="red")
self.figureAxis.plot(phase, sineFit, color="red")
print(phase, sineFit) else:
minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase) try:
plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis) phase, sineFit, _ = getFoldedBestFit(lc, fitType=self.foldedFitType)
except Exception as e: self.figureAxis.plot(phase, sineFit, color="red")
print("Failed to get fit") print(phase, sineFit)
print(e) #minPhasesBoundsIndices, maxPhasesBoundsIndices = getPhaseRangesNearPeak(getFoldedFitPeakValley(sineFit), phase)
#plotPhaseRangesNearPeak((minPhasesBoundsIndices, maxPhasesBoundsIndices), phase, ax=self.figureAxis)
except Exception as e:
print("Failed to get fit")
print(e)
elif(self.PeriodogramState["Enabled"]): elif(self.PeriodogramState["Enabled"]):
lc.plot(label=label, ax=self.figureAxis, view=self.PeriodogramState["View"]) lc.plot(label=label, ax=self.figureAxis, view=self.PeriodogramState["View"])
if(self.PeriodogramState["View"] == "period"): if(self.PeriodogramState["View"] == "period"):
+92 -13
View File
@@ -1,3 +1,4 @@
from types import NoneType
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QListWidgetItem from PyQt5.QtWidgets import QDialog, QListWidgetItem
from PyQt5 import uic from PyQt5 import uic
@@ -8,6 +9,62 @@ from astropy.table import vstack
from ...astrodatadownloader.astrodatadownloader import (ObservationSource, from ...astrodatadownloader.astrodatadownloader import (ObservationSource,
getStarObservations, downloadStarProducts) 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): class NewStarDialog(QDialog):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@@ -27,6 +84,8 @@ class NewStarDialog(QDialog):
QtWidgets.QMessageBox.Ok) QtWidgets.QMessageBox.Ok)
def btFetchData_clicked(self): def btFetchData_clicked(self):
from astroquery.simbad import Simbad
simbad = Simbad()
star = self.leStarIdentifier.text() star = self.leStarIdentifier.text()
if not star: if not star:
self.showErrorMessage("No star identifier", self.showErrorMessage("No star identifier",
@@ -51,23 +110,43 @@ class NewStarDialog(QDialog):
k2Kadences = [self.cbK2ShortCadence.isChecked(), k2Kadences = [self.cbK2ShortCadence.isChecked(),
self.cbK2LongCadence.isChecked()] self.cbK2LongCadence.isChecked()]
allObs = [] #allObs = []
stars = star.split(";") stars = star.split(";")
starsRet = []
self.listPreview.clear() self.listPreview.clear()
for s in stars: #for s in stars:
s = s.strip() # s = s.strip()
obs = getStarObservations(s, keplerKadences, k2Kadences, sources) # altNames = simbad.query_objectids(s)
if(len(obs) == 0): # if(type(altNames) == NoneType):
self.showErrorMessage("No observations found", # altNames = [s]
"No observationnal data has been found with the current filters") # else:
return # altNames = list(altNames["ID"])
allObs.append(obs) # print("Trying for " + ", ".join(altNames))
for o in obs: # for name in altNames:
self.listPreview.addItem(QListWidgetItem(f"{s} - {o['obs_collection']} - {o['sequence_number']}")) # 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) obs = vstack(allObs)
for o in obs:
self.listPreview.addItem(QListWidgetItem(f"{o['starName']} - {o['obs_collection']} - {o['sequence_number']}"))
self.currentObservations = obs self.currentObservations = obs
self.starIdentifier = star self.starIdentifier = ";".join(starsRet)
self.leStarIdentifier.setText(self.starIdentifier)
def btOk_clicked(self): def btOk_clicked(self):
if self.currentObservations: if self.currentObservations:
+3
View File
@@ -78,6 +78,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="maxLength">
<number>999999</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>
+4 -1
View File
@@ -47,7 +47,7 @@ def calculateFitForFlare(lightcurve, peakIndex):
flareFitDataPoints = flareFitDataPoints + peakIndex flareFitDataPoints = flareFitDataPoints + peakIndex
return np.array(Peak+1), flareFitDataPoints, np.array(fit+1) 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, maxIndices = findMaxIndices(lightcurve, num, distance=distance, height=height,
sortByHighest=True) sortByHighest=True)
peaks = [] peaks = []
@@ -55,6 +55,9 @@ def calculateFlareFitsForLightcurve(lightcurve, num=100, distance=1, height=0.05
for index in maxIndices: for index in maxIndices:
try: try:
Peak, flareFitDataPoints, fit = calculateFitForFlare(lightcurve, index) 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, peaks.append({"FlarePeak": Peak,
"FlarePeakTime": lightcurve.time[index], "FlarePeakTime": lightcurve.time[index],
"StandardIndex": index, "StandardIndex": index,
+105 -2
View File
@@ -1,7 +1,8 @@
import numpy as np import numpy as np
from numpy.polynomial.polynomial import Polynomial from numpy.polynomial.polynomial import Polynomial
from scipy.signal import find_peaks, argrelextrema from scipy.signal import find_peaks, argrelextrema, periodogram
from scipy.optimize import curve_fit from scipy.optimize import curve_fit
import itertools
def findMaxIndices(lc, num=3, distance=100, height=(None, None), sortByHighest=False): def findMaxIndices(lc, num=3, distance=100, height=(None, None), sortByHighest=False):
if(hasattr(lc, "power")): if(hasattr(lc, "power")):
@@ -390,4 +391,106 @@ def plotPhaseRangesNearPeak(indices, phase, ax=None):
ax.axvline(phase[l], color="orange") ax.axvline(phase[l], color="orange")
def getEpochTime(lc): def getEpochTime(lc):
return lc.time.value[argrelextrema(np.asarray(lc.flux.value), np.less, order=500)[0]][0] return lc.time.value[argrelextrema(np.asarray(lc.flux.value), np.less, order=500)[0]][0]
def getOptimizedFold(normalizedLC, preferedFoldedFitType):
isValid = False
periodogramLS = normalizedLC.to_periodogram(method="lombscargle")
periodogramBLS = normalizedLC.to_periodogram(method="boxleastsquares")
lsPeriods = periodogramLS.period[findMaxIndices(periodogramLS, num=4, distance=100, sortByHighest=True)]
blsPeriods = periodogramBLS.period[findMaxIndices(periodogramBLS, num=4, distance=100, sortByHighest=True)]
period = -100
spotModulation = -100
for lsP, blsP in itertools.product(lsPeriods, blsPeriods):
if(abs(lsP.value - blsP.value) < max(lsP.value, blsP.value)*0.05):
period = np.average([lsP.value, blsP.value])
print("Period found: ", period)
break
else:
print("No matching LS/BLS peak -> use highest LS")
period = lsPeriods[0].value
spotModulation = period
epoch = getEpochTime(normalizedLC)
tries = 0
periodFoldedLC = None
periodFoldedPhase = None
periodFoldedFit = None
periodFitType = None
while(tries < 30):
tries += 1
foldedLC = normalizedLC.fold(period=spotModulation, epoch_time=epoch)
phase, fit, fitType = getFoldedBestFit(foldedLC, fitType=preferedFoldedFitType)
phaseLength = abs(phase[0]) + abs(phase[-1])
fitMaximaArgs = argrelextrema(np.asarray(fit), np.greater)[0]
spotModulationBefore = spotModulation
if(len(fitMaximaArgs) > 1):
print("fitMaximaArgs > 1: ", fitMaximaArgs)
print(fitMaximaArgs[0], len(phase)*0.1, fitMaximaArgs[1], len(phase)*0.9)
print(fitMaximaArgs[0] > len(phase)*0.1, fitMaximaArgs[1] < len(phase)*0.9)
if(len(fitMaximaArgs) == 2 and fitMaximaArgs[0] > len(phase)*0.1 and fitMaximaArgs[1] < len(phase)*0.9):
halfPeriod = period/2
for lsP, blsP in zip(lsPeriods, blsPeriods):
if(abs(lsP.value - halfPeriod) < period*0.05):
spotModulation = lsP.value
print("lsP.value", lsP.value)
break
elif(abs(blsP.value - halfPeriod) < period*0.05):
spotModulation = blsP.value
print("blsP.value", blsP.value)
break
else:
print("2 fit peaks, but no spot modulation")
if(spotModulationBefore != spotModulation):
periodFoldedLC = foldedLC
periodFoldedPhase = phase
periodFoldedFit = fit
periodFitType = fitType
foldedLC = normalizedLC.fold(period=spotModulation, epoch_time=epoch)
phase, fit, fitType = getFoldedBestFit(foldedLC, fitType=preferedFoldedFitType)
phaseLength = abs(phase[0]) + abs(phase[-1])
fitMinimaArgs = argrelextrema(np.asarray(fit), np.less)[0]
fitMinima = phase[0]
fitMinimaArg = 0
newFitMinimaArgs = []
for args in fitMinimaArgs:
print("Phases: ", fit[0], fit[len(phase)-1], fit[args])
if(fit[0] < fit[args] and fit[len(fit)-1] < fit[args]):
print("Found new minima")
newFitMinimaArgs.append(0)
newFitMinimaArgs.append(args)
newFitMinimaArgs = set(newFitMinimaArgs)
print(newFitMinimaArgs)
for args in newFitMinimaArgs:
if(abs(phase[args]) < abs(fitMinima) and fit[args] < fit[fitMinimaArg]):
fitMinima = phase[args]
fitMinimaArg = args
if(abs(fitMinima) < phaseLength*0.01):
isValid = True
break;
else:
epoch += fitMinima
return {"Period": period,
"SpotModulation": spotModulation,
"lsPeriods": lsPeriods,
"blsPeriods": blsPeriods,
"foldedLC": foldedLC,
"phase": phase,
"fit": fit,
"periodFoldedLC": periodFoldedLC,
"periodFoldedPhase": periodFoldedPhase,
"periodFoldedFit": periodFoldedFit,
"periodFitType": periodFitType,
"fitType": fitType,
"epoch": epoch,
"isValid": isValid}
+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.