\chapter{Discussion \label{sec:discussion}}

The investigation of a flare to spot relation in this study is based on a large sample of known active stars, which were observed by the Kepler/K2 and TESS missions. To also catch shorter events, short-cadence data was used for Kepler/K2. Not all stars analysed which have been analysed were used though to generate the plots in the results section (see table \ref{apA:list_of_unused_stars}). This list contains stars that either did not match the spectral types which were analysed in this study (e.g. some A type stars from the list of stars by \cite{althukair_starlist}), could not produce valid fits (reached 30 iterations during the fit optimization for folded lightcurves) or no consistent period was found. The full list of stars analyzed can be found in table \ref{apA:list_of_all_stars}.\\

\section{Analysis}

The analysis was done with a self written python program (discussed in chapter \ref{sec:gui}). The reason for developing a GUI was to ease the management of the data (e.g. easily looking up parameters of a star), as well as checking individual results in a fast and easy way during the development stage. This also allowed to quickly compare the outputs of the algorithms between different fits files of the same star as well as between different stars. The algorithms are based on the approaches of \cite{kepler_411_study}, \cite{au_mic_flaring_spi} and \cite{doyle_2018}. The thresholds described in section \ref{sec:data:data_reduction:flare_detection} for the flare detection algorithm have been set by trial and visual inspection of the lightcurves of multiple stars/fits files. The last step of the flare detection algorithm, as discussed in section \ref{sec:data:data_reduction:flare_detection}, was implemented to prevent failures due to the flattening algorithm massively inverting dips in the lightcurves. This happened for the lightcurves of 2MASS J19033576+3941263 (TESS sectors 40, 41 and 53), 2MASS J19370439+4626209 (TESS sector 54) and V* V452 Lyr (Kepler target table ID 55). 2MASS J19033576+3941263, also known by KOI-6423 or KIC 4544623 shows regular dips in its lightcurve, which could indicate one or multiple transiting planets. It has currently been marked as a false positive candidate in the NASA Exoplanet Archive (\cite{koidr25}, \href{https://exoplanetarchive.ipac.caltech.edu/overview/KOI-6423}{https://exoplanetarchive.ipac.caltech.edu/overview/KOI-6423}). The TESS lightcurves for KOI-6423 can be found in appendix \ref{apC} in figures \ref{apC:fig:KOI-6423-TESS_lightcurves1} and \ref{apC:fig:KOI-6423-TESS_lightcurves2}. While there are no noteworthy dips upon manual inspection in the lightcurve for 2MASS J19370439+4626209, flattening still generates peaks with values of over 800 on a normalized lightcurve. V* V452 Lyr was observed in multiple Kepler target table IDs, with the only detected flares (4 total) in target table ID 55. The lightcurve itself is very flat (see figure \ref{apC:fig:V452Lyr-Kepler_lightcurves} in appendix \ref{apC}). Further to notice, the flare detection can only distinguish between high and low flare peaks, but it does not calculate the flare energy. But we can say that all flares detected on G type stars  in broad-band photometry such as Kepler/K2 and TESS are superflares, as the lowest detectable flare peak by this algorithm is 1.003, and \cite{solar_like_superflares}, using Kepler data, found that an increase of 0.1\% in flux (flare peak of 1.001) is enough for those flares to be categorized as superflares.\\
While the folding algorithm (see section \ref{sec:data:data_reduction:lightcurve_folding}) works on most stars/fits files, it has its limitations in edge cases like V* HK Aqr or KOI-256 as described in sections \ref{results:hk_aqr} and \ref{results:koi_256}. It is set to check for an additional periodicity signal if the fit for the folded lightcurve has two peaks which are further away than 10\% of the total phase from the edge. While it is expected to find two peaks when folding and fitting a sine function due to marging of error of the fitting parameters, there has to be set a limit for when to search for additional periodicity. A well working (and near perfect) example is V471 Tau. It shows additional periodicity in the TESS lightcurves 42, 32 and 44 (see figure \ref{apB:fig:V471Tau-TESS_foldedLC} in appendix \ref{chap:apB}), but not in 70 and 71. Additionally the shift by the difference of the fit minimum to the (currently used) epoch for the fold is necessary to generate reliable results, as otherwise it has been found that the minimum of the fit/folded lightcurve can vary by up to \textasciitilde25\% depending on which first minimum is detected in the lightcurve.\\\\

\section{Flares and superflares on M-F stars and their spot dependence}

Out of a total of \textasciitilde160 M dwarfs in the list of stars to be analyzed, flares could only be detected on 49 stars. This could be due to the algorithm or instruments being possibly not sufficiently sensitive, too noisy data or it could be that there were simply no flares during the observations. For the remaining 49 stars, a total of \textasciitilde3500 flares was detected. Using all available flares, there was no significant spot dependency detected in the histogram with 10 bins. In the third bin there were \textasciitilde50 flares less detected compared to other bins. This bin is located in the transition from the phase maxima to minima.

While not being significant, the 6th bin has the most flares detected, and is located at the phase minimum.

This could show a possible dependency with more available data, similarly to what was found for K type dwarfs. The data also contain the detected flares from KOI-256 and V* HK Aqr, which were not folded correctly. Manually comparing the results for V* HK Aqr (figures \ref{fig:HKAqr-Flarecount-10_Bins} and \ref{fig:HKAqr-Flarecount-10_Bins_Period}), the folded lightcurves show that for TESS sector 29 the detected minimum ($\pm$ a quarter of the phase) the amount of detected flares flipped. While more flares should be counted in the minimum (see figure \ref{fig:HKAqr-TESS29_foldedLC_Period}) compared to the maximum (see figure \ref{fig:HKAqr-TESS29_foldedLC}), the opposite is the case. Similarly for TESS sector 42. Overall these changes make the spot dependence of flares on V* HK Aqr more clear, as the histogram (10 bins) with only the rotational period folded lightcurves indicates a spot dependency. There are significantly more flares counted around the minimum compared to the phase maximum. The flares with the highest peaks V* HK Aqr were also detected during the phase minimum in TESS sector 29 with a normalized peak of up to 1.8. KOI-256 shows a similar behaviour, revealing a clear spot dependence when using only period folded lightcurves for the histogram, while having more spread out peaks around the phase minimum when using all spot modulation folded lightcurves.\\
2MASS J19230963+3739397 on the other hand is a star, which shows an inverted spot dependency. This could be an indication that similarly to what \cite{kepler_411_210_comparison} found, the spot area is not the only important parameter.\\
Limiting the flare by maximum flare peak indicates a dependency of flares on spots, which can be seen in figures \ref{fig:M-Flarecount-10_Bins_1.25_peak} to \ref{fig:M-Flarecount-10_Bins_1.05_maxpeak}. While no flare energies were calculated in this study, this could be parameters to look at in the future. Limiting the flare peaks to a maximum of 1.01 shows a higher count in the phase maxima compared to he phase minima. The same dip as with all flares can be seen here already too. Increasing the flare peak limit to 1.05 shows a nearly identical histogram to the one with all flares. A noteworthy difference here is the peak in the bin at the phase minimum at $1 \pi$. \cite{connection_starspots_flares_ms_kepler} found an increase of flares in M and K dwarfs at phase minimum with flares which had a flux increase at their peaks between 1\% and 5\%. The differences could be due to a different set of stars and flare detection methods.

Out of a total of \textasciitilde40 K dwarfs in the list of stars to be analyzed, flares could only be detected on 37 stars. This could be due to the algorithm or instruments being possibly not sufficiently sensitive, too noisy data or it could be that there were simply no flares during the observations. Overall the results for the flare distribution of K dwarfs is similar to those of M dwarfs. With the exception of the bin (bins for the histogram with 30 bins) around the phase minimum. This bin shows a significantly increased flare count. One of the, but not the sole cause for this is V* V471 Tau (see section \ref{results:v471_tau}), which is in close orbit with a white dwarf (\cite{v471tau_revised}, \cite{V471tau_magnetic_activity}). This can lead to magnetic interactions between the K dwarf and the white dwarf (\cite{V471tau_magnetic_activity}), which may lead to the increased flarecount seen.\\
Limiting the flare peaks to greater than 1.05 shows two peaks around the center bin, with one higher bin being at the maximum at phase $0 \pi$. While the two peaks around the phase minimum could indicate a dependency on spots, it is not the only relevant bin found.
Limiting the flare peaks to a maximum of 1.01 shows an interesting pattern. There is a larger count of flares found during the phase minimum, but also during the phase maximum, while less flares have been detected in the transition between phase miminum/maximum. Increasing the allowed flare peak to 1.05 shows a similar pattern, but the gaps between peaks/dips vanishes and the histogram becomes already very similar to the histogram with all flares.

Out of a total of \textasciitilde80 G dwarfs in the list of stars to be analyzed, flares could only be detected on 21 stars. This could be due to the algorithm or instruments being possibly not sufficiently sensitive, too noisy data or it could be that there were simply no flares during the observations. Most of the flares detected show a peak of below 1.05, but as \cite{solar_like_superflares} found, flares with a flux increase between 0.1 to 1\% (peaks of 1.001 to 1.01) would already be categorized as superflares for G-star flares detected in broad-band photometry such as Kepler/K2 and TESS. Therefore all flares detected for G stars shown in figure \ref{fig:G-Flarecount} are superflares as the threshold of the flare detection algorithm is 0.3\%.
For the flares found in this study for G type stars, there is a spot dependency, as the flare count peaks around the phase minimum. Unlike the other results, there is a gradual fall off to each sides till the phase maximum is reached. As no energies have been deduced from the Kepler/K2 and TESS observations a categorization in flares and superflares is difficult for all stars investigated in the present study.\\
Limiting the flare peaks to a minimum of 1.05 shows three major peaks. The largest being at the phase minimum, while the other two are in the transition between maximum and miminum and minimum and maximum. This does not indicate a pure spot dependency, and a more detailed look at the individual events is necessary.\\
BD-08 995, which is according to its BV color index and effective temperature a late G type star, reflects this trend well. It shows the same bell curve style histogram as the overall flare number histogram of G-stars. Additionally though it also shows a slight increase in flare number around the phase maximum, its highest flare peak was detected around the phase maximum (see figure \ref{fig:BD-08_995-flarepeaks_1.2}). The maximum flare count for TYC 4595-107-1 on the other hand is slightly offset before the phase minimum (see figure \ref{fig:TYC_4595-107-1-Flarecount-10_Bins}). It also shows a slight increase of flares around the maximum. Its highest flare peak was detected in the same bin as the highest flare count (see figure \ref{fig:TYC_4595-107-1-flarepeaks_1.27}).

Out of a total of \textasciitilde13 F dwarfs in the list of stars to be analyzed, flares could only be detected on four stars. This could be due to the algorithm or instruments being possibly not sufficiently sensitive, too noisy data or it could be that there were simply no flares during the observations. While all flares detected are centered around the phase minimum, the total of 5 flares detected is not a sufficiently large sample to draw a definite conclusion on the spot to flare/superflare relation.

For two stars, namely the K-dwarf TYC 1360-957-1 and the M-dwarf HK Aqr we find that the most energetic flares occur at the same phase. For TYC 1360-957-1 (see figure \ref{fig:TYC_1360-957-1-flarepeaks_1.31}) the flares with largest flare peak originate all from phase $0.7$ to $0.8 \pi$. Two flares were detected in TESS sector 44 and one two sectors later (sector 46). From the Sun we know that spots can have lifetimes of severeal rotation periods i.e. several months. This maybe also the case for the spot or spot group being the origin of the three strong flares on TYC 1360-957-1.

A similar finding was made on HK Aqr. Also the three strongest flares have been found to occur at the same phase. For HK Aqr this happened in one TESS sector (sector 29, see figure \ref{fig:HKAqr-TESS29_foldedLC_Period}). Also here the it is reasonable to assume that these three flares have been generated by the same spot or spot group. For both stars the phases at which these strong flares have occurred are close to the phase minimum, i.e. correspond to hemispheres of the stars showing a hugh spottedness. 

Looking at all results together, there is a trend that more flares occur when a more spotted stellar hemisphere is visible, than vice versa. This is mostly influenced by the results for K and G stars. The dip in the otherwise seemingly stable histogram for the results of M dwarfs dominates the overall results. 
There is at the moment no explanation for the significant dip in the histogram and we doubt that it has a physical meaning. %The results of the study support the results from \cite{connection_starspots_flares_ms_kepler} for G+F stars and the overall picture of flares being caused by reconnecting stellar magnetic fields originating in stellar spots rather than being triggered from close-in orbiting planets. As the histogram of G-star flares is representative for superflares the statement above counts for both flares and superflares.
All results will be published on github. The program will be available at \href{URL}{text} while the data will be available at \href{URL}{text}.
