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

The flare to spot correlation 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 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 tries 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}.\\
The analysis was done with a self written python program (discussed in chapter \ref{sec:gui}). The reason a GUI was made was for ease of 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 fits files. 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 for flare detection, which was introduced to prevent failures of the flattening algorithm to be detected as (massive) flares, was introduced due to the results for the stars 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 it still generates peaks 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 high and low flare peaks, but it does not calculate the flare energy.\\
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 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 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 the minimum of the fit/folded lightcurve can vary by up to \textasciitilde25\% depending on which first minimum is detected in the lightcurve.\\\\

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 a not sensitive enough algorithm or instruments, too noisy data or it could be that there were just no flares during the observation time. For the remaining 49 stars, a total of \textasciitilde3500 flares were 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, which would be at the phase minimum. This could show a possible dependency with more available data. The data also contains 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}), as well as the folded lightcurves shows that for TESS sector 29 the detected minimum ($\pm$ 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, showing 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 height indicates a dependency of flares on spots. While no flare energies were calculated in this study, this could be parameters to look at in the future. Limiting the flare peak to 1\% above the flux 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 5\% above the flux shows a nearly identical histogram (in form) 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.

% 14 - 10; 10 - 14
%M dwarfs, all data, no significant dependency of flare appearance on phase using 10 bins.
%30 bins -> either 2 dips during the transition minima <-> maxima or increase of flare occurance during minima and maxima.
%Looking at stronger flares only (min 1.25/1.5 flare peak) peaks during minima, stronger peak during phase maxima, in both 10 and 30 bin histograms.
%Limiting to max 1.01, makes dip (compared to all data) clearer. Generally more flares during maxima than minima. 
%Limit to max 1.05, nearly identical histograms to all data. (different result to \cite{connection_starspots_flares_ms_kepler})
%\\\\

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 a not sensitive enough algorithm or instruments, too noisy data or it could be that there were just no flares during the observation time. Overall the results for the flare distribution on K dwarfs is similar to those of M dwarfs. There is no real dependence on spots visible, with the exception of the bin (bins for the histogram with 30 bins) around the phase minimum. One of the causes 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 could lead to the increased flarecount seen.\\
Limiting the flare peaks to greater than 5\% of the flux 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\% above the flux 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 5\% above the flux shows a similar pattern, but the gaps between peaks/dips closes and is already very similar to the histogram with all flares.

% K dwarfs, all data, siginificant peak at phase minimum, peak dominated by V471 Tau (discussed later). Slightly more flares from maximum to minimum than minimum to maximum in 10 bins. 30 bins larger dips but also larger peaks in second half of phase compared to first half.
% limiting to min 1.05 -> three peaks, dip after maximum and on at phase 1 $\pi$. gradual decrease after minimum. V471 Taus peaks at right before and right after phase minimum.
% limiting to <1.01 and 1.05, makes histogram look more and more like with all data, similarly to \cite{connection_starspots_flares_ms_kepler} peak in center (compared to their M/K plot), but additionally also peak at phase maximum.
% max 1.05 already most flares, very similar to with all data.

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 a not sensitive enough algorithm or instruments, too noisy data or it could be that there were just no flares during the observation time. Most of the flares detected had a peak below 5\% above the flux, but as \cite{solar_like_superflares} found, flares with a flux increase between 0.1 to 1\% would already be categorized as superflares. For the flares found in this study for G type stars, there appears to be 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.\\
Limiting the flare peaks to a minimum of 1.05 shows three major peaks. The highest 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 seems to be a late G type star, reflects this trend well. It shows the same bell curve style histogram. Additionally though it also shows a slight increase in flares around the phase maximum. Its highest flare peak was detected around the phase maximum though. The maximum flare count for TYC 4595-107-1 on the other hand is slightly offset to before the phase minimum. 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.

% G dwarfs, significant results, increase of flare appearance during phase minimum. Most flares are <1.05 (flares on solar like stars that increase brightness by 0.1\% to 1\% already superflares, \cite{solar_like_superflares}) -> most/all detected flares superflares. Overall dependency on phase/spot appearance.
% Limiting to flares >1.05 -> flares during minima and transitions between minima <-> maxima, increasing bins -> more data would be required.

Out of a total of \textasciitilde13 F dwarfs in the list of stars to be analyzed, flares could only be detected on 4 stars. This could be due to a not sensitive enough algorithm or instruments, too noisy data or it could be that there were just no flares during the observation time. While all flares detected are centered around the phase minimum, the total of 5 flares detected is not a large enough sample to come to a conclusion if there exists a flare spot dependency for these stars.

% For F dwarfs, overall too little data, but the not siginificant amount detected all during phase minimum, could be similar to G dwarfs?

Looking at all results together, there appears to be a slight flare dependence, which 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 propagates for the overall results. 

% All data combined, peak at phase minimum dominated by G/K dwarfs, dip in transition maxima -> minima dominated by dip from M dwarf results.

% Individual star results (subset taken):
% BD-08 995 (G type): shows a strong flare/spot dependence for amount, flare peaks not dependent on phase

% TYC 1360-957-1 (K type): no clear dependence on spots for flare count (1 peak around maximum, 1 during transition, another at minimum), less siginificant with more bins
% Shows strongest flares right before phase minimum though.

% TYC 4595-107-1 (G type): similar to BD-08 995, increase of flares right before minimum, slight (less significant) increase at maximum. (appending folded lightcurves in appendix)

% V471 Tau: binary with white dwarf, most flares around white dwarf transit -> magnetic interactions likely (ref. to V471 Tau specific papers)
% Strongest flares also around that

% HK Aqr (M dwarf): not fully trusted results, half period was detected for 2/4 lightcurves (original folding had 2 fit maxima too far away from edges, caused it to check for if half period signal was detected and use that)
% only full period results show overall less flares during the maxima

% KOI-256 (M dwarf): similar issue as HK Aqr, in 2/7 Kepler, 2/3 TESS lightcurves, like V471 Tau binary with white dwarf, shows siginficant dependency on spots in with period folded results. (appending folded lightcurves in appendix)
% Largest flares, when period folded only, also at around 0.8 $\pi$ (same flare shifted to 2 $\pi$ in spot modulated fold), otherwise flare energies well spread.



