Magnetic Activities of M-type Stars Based on LAMOST DR5 and Kepler and K2 Missions

We performed a statistical study of magnetic activities of M-type stars by combining the spectra of LAMOST DR5 with light curves from the Kepler and K2 missions. We mainly want to study the relationship between chromospheric activity and flares, and their relations of magnetic activity and rotation period. We have obtained the maximum catalog of 516,688 M-type stellar spectra of 480,912 M stars from LAMOST DR5 and calculated their equivalent widths of chromospheric activity indicators (Hα, Hβ, Hγ, Hδ, Ca ii H&K, and He i D3). Using the Hα indicator, 40,464 spectra of 38,417 M stars show chromospheric activity, and 1791 of these 5499 M-type stars with repeated observations have Hα variability. We used an automatic detection plus visual inspection method to detect 17,432 flares on 8964 M-type stars from the catalog by cross-matching LAMOST DR5 and the Kepler and K2 databases. We used the Lomb–Scargle method to calculate their rotation periods. We find that the flare frequency is consistent with the ratio of activities of these chromospheric activity indicators as a function of spectral type in M0–M3. We find the equivalent widths of Hα and Ca ii H have a significant statistical correlation with the flare amplitude in M-type stars. We confirm that the stellar flare is affected by both the stellar magnetic activity and the rotation period. Finally, using the Hα equivalent width equal to 0.75 Å and using the rotation period equal to 10 days as the threshold for the M-type stellar flare time frequency are almost equivalent.


Introduction
Stellar magnetic activity is a common phenomenon in late-type stars. Stellar magnetic activities, such as stellar flares, coronal mass ejections, and high-energy emissions, are important factors in the formation and evolution of exoplanets (Poppenhaeger 2015). The Kepler Mission was designed mainly to detect earth-like planets around large numbers of stars like our Sun . Unexpectedly, most of the planets detected were around the M-type stars. M-type stars, which are common in the Milky Way, have a long main-sequence evolution life and remain magnetically active for a long time. Therefore, studying the M-type stars is of great significance for exploring magnetic activity properties and extraterrestrial civilization (Chang et al. 2018).
Before the advent of ground-based spectroscopic survey telescopes and space photometric telescopes, statistical studies of stellar magnetic activity could only use a small amount of photometric or spectroscopic data. Robinson et al. (1990) used CaII H&K and Hα spectral lines to study the magnetic activity of 50 late-type stars. Saar et al. (1997) investigated the magnetic activity of 53 late-type stars with the HeI D3 spectral line. Shakhovskaia (1989) used photometric data of about 80 red dwarf stars to perform statistical analysis on stellar flares. However, with the Sloan Digital Sky Survey (SDSS; Abazajian et al. 2009), the LAMOST survey (Wang et al. 1996;Su & Cui 2004;Cui et al. 2012), and the Kepler ) and TESS (Ricker et al. 2014) missions, it is possible to perform statistical studies on the magnetic activity of M-type stars using photometric or spectroscopic data. West et al. (2008) analyzed the Hα line of the spectrum of more than 38,000 low-mass stars from the SDSS DR5, confirming that the ratio of magnetically active stars is a function of the vertical distance from the Galactic plane. They also found the dependence of the function of magnetically active stars with vertical distance from the galactic disk is very weak for M0-M3 stars, while strongly pronounced for M4-M9 stars. West et al. (2011b) also studied the Hα, Hβ, Hγ, Hδ, and CaII K emission lines of the 70,841 M dwarfs from SDSS DR7 to examine the magnetic activity of M dwarfs. Yi et al. (2014) investigated the magnetic activity properties of the 58,360 M dwarfs in the LAMOST pilot survey through the Hα emission line. Zhang et al. (2016) detected 6391 magnetically active M-type stars among the 99,741 M-type stars from the LAMOST survey and found that 163 of 898 M stars with repeated spectra show variability in Hα emission.
There are also many studies that analyzed the magnetic activity of M-type stars, such as flares, by using the data of space photometry. Walkowicz et al. (2011), the first to use Kepler's photometric data for statistical studies of stellar flares, found that M dwarfs tend to flare more frequently but for shorter durations than K dwarfs. Candelaresi et al. (2014) used Kepler data to find 380 late-type dwarfs with superflares and studied the superflare frequency and energy. Doyle et al. (2018) confirmed that rapidly rotating stars tend to show more stellar flares by analyzing the K2 short-cadence photometric data of 34 M-type dwarfs. Recently, Günther et al. (2019) found 632 flaring M dwarfs in the 2 minute cadence photometric data from the first two months of the TESS mission. In addition, Chang et al. (2017) combined the LAMOST and Kepler observations to study the magnetic activity of 54 M-type dwarfs and found that M-type dwarfs with strong Hα emission usually have large flare activity. Yang et al. (2017) used Kepler's long-cadence photometric data to find 540 M-type flaring stars, and then cross-identified the 540 dwarfs with LAMOST DR4 and obtained the spectra of 89 M-type flaring dwarfs. It was found that the flare activity gradually increased from the spectral type M0-M4. Recently, Lin et al. (2019) presented a comparative study of the magnetic activities of M, K, and G low-mass stars and obtained that their power-law indices of flare frequency distributions are nearly the same. Yang & Liu (2019) published a new catalog of 3420 flare stars from the Kepler mission and proposed a scenario for the activity-rotation relation in the Hertzsprung-Russell (H-R) diagram.
Recently, LAMOST DR5 released numerous spectra of M-type stars. The Kepler and K2 missions also released a large amount of photometric data for M-type stars. These arouse our interest in studying magnetic activities of M-type stars by combining the spectroscopic data of LAMOST DR5 with the photometric data from the Kepler and K2 missions. In Section 2, we perform statistical studies on stellar magnetic activity using the M-type spectra of LAMOST DR5. In Section 3, we study the stellar flares using the long-cadence Kepler and K2 data of the 8964 M-type stars (observed by LAMOST DR5 and the Kepler or K2 mission). In Section 4, we analyze the statistical correlation between the results of spectroscopic studies and the results of photometric studies of M-type stars. Finally, a summary of this work is presented in the Section 5.

LAMOST DR5
LAMOST (also known as Guoshoujing Telescope), located in Xinglong Station of the National Astronomical Observatories of the Chinese Academy of Sciences (NAOC), is a special meridian reflecting Schmidt telescope with about 4 meter effective aperture and a 5°field of view (Wang et al. 1996;Su & Cui 2004;Cui et al. 2012). LAMOST is equipped with 16 spectrographs, each of which is fed by 250 fibers. Each spectrograph uses two 4K×4K CCDs to record the red and blue spectra of the corresponding target sources. Therefore, LAMOST can obtain about 4000 spectra with a wavelength range of 3650-9000 Å and a resolution R∼1800 in one single exposure.
After two years of commissioning and one year of pilot survey, LAMOST officially began a five-year regular survey in 2012 September. This regular survey includes the LAMOST ExtraGAlactic Survey (LEGAS) and the LAMOST Experiment for Galactic Understanding and Exploration (LEGUE; Zhao et al. 2012), where the main goal of the LEGUE is to observe the spectra of stars covering 9-17.8 mag (r band) in the Milky Way. The raw stellar spectra are first processed by the LAMOST 2D pipeline, and then spectral type classification and radial velocity measurement are performed by the LAMOST 1D pipeline (Luo et al. 2012(Luo et al. , 2015. The five-year regular survey ended on 2017 June 16, and all spectra were provided through the LAMOST DR5. 6 The LAMOST DR5 released 8,171,443 stellar spectra, of which 529,629 are M-type stellar spectra. In addition, LAMOST has performed at least one observation of all 14 subfields of the Kepler field in the LK project (De Cat et al. 2015;Ren et al. 2016;Zong et al. 2018). There are also some overlaps between the observation areas of the LAMOST and K2 missions (Howell et al. 2014). This provides an excellent opportunity for us to study the magnetic activity of M-type stars using the spectra of LAMOST and the light curves of the Kepler and K2 missions.

Spectral Type Determination and Equivalent Width Calculation
The Hammer spectral typing facility (West et al. 2004;Covey et al. 2007;West et al. 2011aWest et al. , 2011b, written in IDL code, has an automatic mode and an interactive mode. In order to make the spectral types of our sample more accurate, we use the interactive mode of the Hammer to visually inspect the 529,629 M-type stellar spectra candidates and manually assign spectral types. The Hammer's manual "eye check" spectral types are accurate to within ±1 subclasses (Covey et al. 2007). In the interactive mode, we remove the low signal-to-noise ratio spectra (S/N<3 at ∼8300 Å) and other spectra except the M-type stellar spectrum, and finally we obtain 516,688 M-type stellar spectra. The parameters of these 516,688 LAMOST spectra are listed in Table 1. In Table 1, the first column is the spectral name, the second column to the fourth column are the magnitude of the riz bands, the fifth column is the exposure time of the spectrum, the sixth column is the beginning of the spectrum exposure time, the seventh column is the spectral type visually calibrated with the Hammer program, and the last column is the S/N of the spectrum in the R band. After statistics, we plot the distribution of the LAMOST DR5 M-type stellar spectra in Figure 1. From Figure 1 we can see that 98.2% of the spectra are between M0 and M3, while the number of spectra from M4 to M9 is small.
The Balmer lines (Hα, Hβ, Hγ, and Hδ), CaII H&K lines, CaII IRT lines, and HeI D3 line are significant indicators of stellar magnetic activity (Duncan et al. 1991;Huenemoerder 1991;Montes et al. 2004;Hall 2008). In order to accurately determine whether these lines are emitted or absorbed, we calculate the corresponding equivalent widths (EWs) of these lines. The calculation process of EW is as follows. First, we integrate over the specific region of each line (8 Å wide centered on the line) and subtract the mean flux calculated from two adjacent continuum regions (see Table 2 for details). Then we calculate the EWs for each line by dividing the integrated line flux by the mean continuum value (West et al. 2004(West et al. , 2008(West et al. , 2011b. Referring to the activity criteria of the EW of the emission lines given by West et al. (2011b), we present the activity threshold for the EW of the Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 line, as shown in the last column of Table 2. Active M-type stars are searched by the following criteria: (1) the EW of any one of the special lines is greater than the corresponding threshold, (2) the value of the EW is greater than three times its uncertainty, and (3) the height of the emission line must be larger than three times the noise in the emission line center. It should be pointed out that the above-mentioned spectral lines of some targets have EWs below the corresponding threshold, but they may still be potential active M-type stars (West et al. 2004). The EWs of these spectral lines are listed in Table 3. In Table 3, the first column is the LAMOST spectral name, the second column is the observation time of the corresponding spectrum, and the third column is the spectral type visually calibrated with the Hammer program. The fourth column to the thirteenth column are the EWs of the above 10 special spectral lines, and after each EW value, the letter "Y" indicates that the spectral line conforms to the activity standard, and the letter "N" indicates the corresponding line does not meet the activity criteria. Figure 2 presents two M-type LAMOST spectra (LAMOST J034018.97+264540.4 and LAMOST J055105.96+082234.3) with Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 line emission.

Magnetic Activity Statistics
By statistically studying the EWs of Table 3, we list the magnetic activity fraction of Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 line in Table 4. Table 4 contains the line names, the number of active spectra and active stars, and the corresponding activity fraction. As can be seen from Table 4, there is the largest number of spectra with Hα activity, and the corresponding activity fraction is also the largest. The activity ratio decreases in the order of Hα, Hβ, Hγ, and Hδ. In addition, we first calculate the activity ratio of the CaII H, CaII IRT, and HeI D3 of the M-type stellar spectrum. The ratio of   ( Note.1. "-" indicates that the EW of the line cannot be calculated because the S/N around the line is too low. 2. "Y" indicates that the corresponding line meets the activity criteria, and "N" indicates that the corresponding line does not meet the activity criteria. 3. This is part of Table 3. The full Table 3 will be published online. (This table is available in its entirety in machine-readable form.) activities of CaII H and CaII K is very close, and the proportion of activities of CaII IRT lines is very low. Previous studies (West et al. 2004(West et al. , 2011bYi et al. 2014;Zhang et al. 2016) have shown that the Hα activity ratio is a function of M-type stellar spectral type. In this paper, we also present the Hα activity fraction in M0-M9 spectral types, as shown in panel (a) of Figure 3. From panel (a), we can see that the proportion of Hα activity is gradually increasing from M0 to M3; that is to say, in our sample, the proportion of Hα activity is also a function of spectral type in M0-M3. However, the Hα activity fraction between M4 and M9 varies randomly. It seems that there is a distinction of statistics between M0-M3 and M4-M9 stars, although we cannot confirm that. Because there are only 9296 spectra between M4 and M9 in our sample, accounting for only 1.8% of the total sample, we need more data to confirm that. More importantly, we first present the variation of the activity fraction of Hβ, Hγ, Hδ, CaII H&K, and HeI D3 between M0 and M9, as shown in panels (b)-(g) of Figure 3. From panel (b) to panel (g), the proportion of activities of Hβ, Hγ, Hδ, CaII H&K, and HeI D3 gradually increases from M0 to M3. This indicates that the proportion of activities of Hβ, Hγ, Hδ, CaII H&K, and HeI D3 is in excellent agreement with the Hα activity fraction, and the activity fraction of these lines is a function of spectral type in M0-M3. For CaII IRT, we have not found a similar phenomenon because of the small activity fraction of these three lines in our sample.

EW-EW Relationships
From the statistical analysis of Section 2.3, it can be seen that the activity fractions of Hα, Hβ, Hγ, Hδ, CaII H&K, and HeI D3 all increase gradually from M0 to M3. This arouses our interest in whether there is some correlation between the EWs of these lines. Previous studies analyzed the relationship between magnetic activity indicators CaII H&K, Hα, and CaII IRT (Strassmeier et al. 1990;Martínez-Arnáiz et al. 2011), but most of these indicator lines are not observed simultaneously, and the study samples are small. For this research, we use 40,464 M-type LAMOST spectra with Hα activity to study the EW-EW relationships between the spectral lines. Our data set has two noteworthy advantages: the first is that the wavelength range of each M-type LAMOST spectrum covers the Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 line simultaneously; the second is that our research sample has greatly improved in number.
In Figure 4, we compare the EWs between Hα and Hβ, Hγ, Hδ, CaII H&K, CaII IRT, HeI D3 and Hγ and Hδ, CaII H and CaII K, and CaII λ8498 Å and CaII λ8542 Å. EW-EW relationships between the above lines have been determined by fitting the data to a relation of the type where EW1 and EW2 are the equivalent widths of two different lines, c1 and c2 are the fitting parameters, and err1 and err2 are corresponding errors. From panels (a) to (i) in Figure 4, it is obvious that the EWs of Hβ, Hγ, Hδ, CaII H&K, CaII IRT, and HeI D3 are linearly related to the EWs of Hα. Martínez-Arnáiz et al. (2011) attempted to search for a linear correlation between Hα and CaII K and CaII λ8498 Å through flux-flux relationships using 298 active late-type stars. Panels (e) and (f) in Figure 4 again confirm the linear correlation between Hα and CaII K and CaII λ8498 Å using the EW-EW relationships. In addition, it can be seen in panels (a)-(c) and (j)-(l) of Figure 4 that the EW-EW relationships between the same line series (such as Balmer lines, Ca II H&K lines, and Ca II IRT lines) also have a linear correlation. In the EW-EW relationship diagram, it is important to mention that the slope (c1) between lines of the same series (such as panels (a)-(c) and (j)-(l)) is greater than the slope (c1) between lines from the different series (such as panels (d)-(i)).

Hα Variability
From the 40,464 Hα activity M-type spectra counted in Section 2.3, we find that LAMOST performed at least two observations on 5499 M-type stars (see Table 5 for details) at different times. Among the 5499 M-type stars, their Hα lines have a high S/N. Therefore, we use the spectrum of these 5499 stars to study their Hα variability. First, we search for the maximum and minimum values of their EWs in the LAMOST spectra of these 5499 stars, which are listed in the fifth and seventh columns of Table 5. Subsequently, we calculate the corresponding R EW value (R EW =Max(Hα_EW)/Min(Hα_EW)), as shown in the ninth column of Table 5, and plot the relationship between the R EW value and the spectral type in Figure 5. The distribution of these stars is asymmetrical, and the number of stars from M0 to M3 accounts for 98.6%. In Figure 5, the large R EW values of M2 and M3 have significant extensions relative to M0 and M1. This is consistent with the previous results (Kruse et al. 2010;Lee et al. 2010;Bell et al. 2012) in which the Hα variability increases at later spectral type. In addition, we also calculate !EW (!EW=Max (Hα_EW) − Min(Hα_EW)), listed in the tenth column of Table 5. Using the same method as Zhang et al. (2016), we find the !EW value is greater than three times its corresponding uncertainty, indicating that the star has Hα variability and is marked with Yes, as shown in the last column of Table 5. We find that 1791 of these 5499 M-type stars have Hα variability. We plot the LAMOST spectra of one of the M-type stars with Hα variability (LAMOST J011921.66−011701.8, panel (a)) and its corresponding EW as a function of observation time (panel (b)) in Figure 6.      (Huber et al. 2014). In 2013 May, the second of four reaction wheels was lost on the Kepler spacecraft, ending Kepler's scientific mission for more than four years. In 2014 June, the K2 mission was fully operational, which represents a new concept for spacecraft operations. The K2 mission is a series of sequential observing "campaigns" of fields distributed around the ecliptic plane and provides a photometric precision close to the original Kepler mission (Howell et al. 2014). The duration of each campaign is approximately 80 days. From Campaign 0 to Campaign 16, the K2 mission has observed more than 470,000 objects. In addition, the Kepler-LAMOST project was proposed by De Cat et al. (2015), which allows many stars in the Kepler observation area to have both photometric and spectroscopic data. The observation area of LAMOST and the observation area of the K2 mission also partially overlap. Therefore, this provides an excellent opportunity to study the magnetic activity of M-type stars using both photometric and spectroscopic data. Both the Kepler and K2 missions provide both uncorrected simple aperture photometry data and presearch data conditioning (PDC) data, where the instrumental effects of PDC data have been removed. Because of the way K2 is pointed, the center of the stellar point-spread function usually moves about 1 pixel in 6 hr (Van Cleve et al. 2016). Without the use of photometric correction, the error produced on the light curve may be much higher than on Kepler. In our study, considering the effects of Kepler and K2, we finally choose the PDC data. In the second part, we have searched 516,688 M-type stellar spectra from the LAMOST DR5. By cross-matching these LAMOST spectral data with the Kepler catalog (Huber et al. 2014) and the K2 catalog (including Campaigns 0 to 16) with a tolerance of 3″, we obtain the photometric data (LC) of 918 and 8232 M-type stars from Kepler and K2, respectively. After the Kepler spacecraft lost two spacecraft reaction wheels, the Science Data Processing Pipeline of K2 limited the position fitting of the target to 1.5 pixels (about 3 98) when constructing a model to process K2 data (Jenkins 2017). Therefore, in order to make the flare search more accurate, we removed targets with neighboring stars within 4″ (4″), after which we obtain the photometric data (LC) of 834 and 8130 M-type stars from the Kepler and K2 missions, respectively. The Kepler ID or K2 ID of the 8964 M-type stars is listed in the first column of Table 6. The corresponding LAMOST spectral names, spectral observation times, and spectral types are listed in the second, third, and fourth columns of Table 6, respectively. In addition, we list the observation time of the 8964 M-type stars observed by the Kepler or K2 mission in the fifth column of Table 6. The stellar effective temperatures and stellar radii obtained from the literature (Huber et al. 2014(Huber et al. , 2016 are listed in the sixth and seventh columns of Table 6, respectively. We also list the EWs of Hα, CaII H, and HeI D3 in the eighth, ninth, and tenth columns of Table 6, respectively. We will use these cross-matched Kepler and K2 LC photometric data to study the flares of M-type stars.

Flare Search Method
Flares are sudden explosions on the surface of a star and last from a few minutes to a few hours. Usually, a flare can be divided into three stages: an impulsive rise, an impulsive decay, and a gradual decay. Based on the characteristics of the flare, some methods for detecting flares from the light curve have been developed (Walkowicz et al. 2011;Osten 2012;Shibayama et al. 2013;Wu et al. 2015;Van Doorsselaere et al. 2017;Yang et al. 2017). Wu et al. (2015) used such a method to detect stellar flares by first subtracting the background light curve from the original light curve and then detecting the flare on the detrended data. In this work, we use the same method as Wu et al. (2015) to detect flares.
First, we normalize the photometric data (PDC Flux) of the 8964 M-type stars downloaded from the Kepler and K2 missions using the following two formulas: where F average is the average value of the PDC Flux of each data set downloaded from the Kepler or K2 missions, F PDC (max) is the maximum value of the PDC Flux of each    Note.1. "-" indicates that the value cannot be obtained. 2. "Y" indicates that the corresponding line meets the activity criteria, and "N" indicates that the corresponding line does not meet the activity criteria. 3. This is part of Table 6. The full Table 6 will be published online.
(This table is available in its entirety in machine-readable form.) data set, and F PDC (min) is the minimum value.
where F norm is the normalized flux, and F PDC is the PDC Flux of each data set. The top panel of Figure 7 is the normalized light curve. To obtain the stellar background flux (F background ), we use the following formula (4) to calculate the average of the four adjacent points (F ave ) in F norm : , 1, 2, 3, , 4 t ave 0 3 norm where i is the serial number of each data point in the data set. Then, we calculate the median absolute deviation (MAD) of the residuals (F norm − F ave ). Subsequently, we use MAD to scan each point in the data set. If the residuals (F norm − F ave ) are greater than six times the corresponding MAD, they are treated as outliers and removed from the second four-point average. The schematic of F background is shown in the middle panel of Figure 7. Finally, we calculate the detrended flux (F flare ) by subtracting F background from F norm . The schematic of F flare is shown in the bottom panel of Figure 7. In the detrended flux (F flare ), the flare can be easily distinguished. Therefore, we can programmatically search for flares. After completing the above steps, we use the program to automatically search for the flare candidates from the detrended data. The process of automatically searching for flare candidates is as follows. First, the standard deviation (σ) of each detrended data set is calculated. Then we search for the phase of sudden brightness increase from the detrended data set, and we record the peak of the phase as A, and the point after the peak as B. If the value of A is greater than three times the corresponding σ and the value of B is greater than two times the corresponding σ, our program will list the phase as a flare candidate and display the corresponding sudden brightness increase in F norm in the form of a picture. At the same time, the program will automatically determine the start and end times of the flare candidate by the following two criteria: (1) at the impulse increase phase of the flare candidate, a point below 5% of the peak flare amplitude is defined as the starting point of the flare; and (2) at the gradual decay phase, a point below 5% of the peak flare amplitude is defined as the flare end moment.
In order to accurately search for flares, we visually inspect the pictures of the flare candidates automatically searched by the program. In the automatic detection of flares, the light curves of some eclipsing binaries and some transit events can become contaminated (Shibayama et al. 2013). These contaminants will be removed during visual inspection of the flare candidates. After visual inspection, the contaminants we removed accounted for about 20% of the total flare candidates.

Flare Search Results
After the above flare search steps, we finally detect 17,432 flares (flare energy > 10 30 erg) from 4143 M-type stars, including 9041 flares from 578 M-type stars from the Kepler mission, and another 8391 flares from 3565 M-type stars from the K2 mission. That is to say, among our 8964 M-type stars, 4143 are flare stars, accounting for about 46.2%. We list the number of flares for each source in the eleventh column of Table 6. In addition, we list the parameters of these 17,432 M-type stellar flares in Table 7, where the first column is the Kepler or K2 ID, the second column is the flare start time, the third column is the flare peak moment, the fourth column is the flare end time, the fifth column is the flare duration, and the sixth column is the amplitude of the flare. We also plot eight M-type stellar flares as an example in Figure  In this work, we use the following equation to calculate the flare energy: where σ sb is the Stefan-Boltzmann constant, F flare is the normalized flare flux (the flare amplitude is the peak value of this parameter), R * is the stellar radius, and T is the stellar effective temperature; these last two parameters come from the stellar parameter catalog of Kepler and K2 (Huber et al. 2014(Huber et al. , 2016. The energy of each flare is listed in the last column of Table 7. Figure 9 represents the frequency distribution of flares in M-type stars as a function of the flare energy. The values of the power-law index α are estimated to be 2.02±0.11, which is very close to the results (α∼2.07 ± 0.35) of Yang et al. (2017). In the study of superflares of G-type stars, the values of the power-law index α obtained by Maehara et al. (2012) were from 2.0 to 2.3, the α value obtained by Shibayama et al. (2013) was 2.2, and the α value obtained by Wu et al. (2015) was 2.04±0.17. By comparing the values of the power-law index α of the M-type star with the α values of the G-type star, we found that their power-law index α is close to 2. Therefore, we concluded that the mechanism of flares on G-type stars may be similar to that of M-type stars. In addition, we also use the Lomb-Scargle method (Lomb 1976;Scargle 1982) to analyze the light curve of the 8964 M-type stars and calculate the corresponding stellar rotational period. First, we use the Lomb-Scargle method (Lomb 1976;Scargle 1982) to calculate the possible rotation periods of each M-type star in each data set (these data sets come from different quarters (Kepler mission) or different campaigns (K2 mission)), and we then average these possible rotation periods to obtain the final rotation period of the corresponding source. The results are listed in the twelfth column of Table 6.

Flare Activity and Spectral Type
Stellar flares are a sudden explosion of magnetic energy on the stellar surface, which means that the stellar flare is closely related to the stellar magnetic activity. Figure 10 presents the number distribution of 8964 M-type stars observed simultaneously by LAMOST DR5 and the Kepler or K2 mission, 4143 M-type flaring stars, and flare frequency of M-type stars as a function of spectral type. It can be seen from panel (a) of Figure 10 that the M-type stars (black line) and M-type flaring stars (blue line) are mainly distributed in M0-M3, followed by M4-M7, and M8 and M9 have few. There are many sources of M0 type, and the corresponding M0-type flaring stars are also more abundant. But from the distribution of flaring stars from M1 to M3, and from M4 to M7, we can see that both parts have shown an increasing trend. In addition, from panel (b) of Figure 10, it can be seen from the trend of the flare frequency (red line) that the frequency of flare activity from M0 to M3 is gradually increasing, which is similar to the trend of Hα activity from M0 to M3 in Section 2.3. The flare frequency also shows an increasing trend from M5 to M8. In previous studies, West et al. (2008) analyzed the spectra of 38,000 M dwarfs of SDSS DR5 and found that the magnetic activity distribution of M dwarfs is a function of stellar spectral type, and the magnetic activity ratio increases from M0 to M7. On the other hand, Yang et al. (2017) analyzed the flaring fraction of 540 M dwarfs in Kepler and found that the flaring ratio is a function of the spectral type, and the flaring ratio tends to increase from M0 to M4. Therefore, flaring activity and Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 are important parameters for measuring the magnetic activity of M-type stars. But we also need to continue to observe more samples in the future, especially to increase the stellar samples from the M4 to M9 spectral type in order to more clearly understand the magnetic activity of the M-type stars.

EWs of Spectral Lines and Flare Amplitude
Many observations and theoretical models agree that stellar flares have a great influence on the chromospheric activity of stars. During flares, the energy deposition sites in the chromosphere appear as bright ribbons in Hα and other chromospheric diagnostics such as CaII H&K, MgII H&K, and CaII λ8542 Å (Benz 2008;Fletcher et al. 2011;Danilovic et al. 2014;Sindhuja et al. 2019). The results of Karoff et al. (2016) indicated that superflare stars usually have larger chromospheric emission than other stars. In addition, the emission of the HeI D3 line is often observed during flares (Zhang & Gu 2008;Zeng et al. 2014). Figure 11 presents the relationship between the EWs of the spectral lines and the flare amplitude in the 4143 M-type flaring stars. Panels (a), (c), and (e) are the relationship between the EW of Hα, CaII H, and HeI D3 and the maximum flare amplitude of the corresponding star, respectively. Panels (b), (d), and (f) are the relationship between the EW of Hα, CaII H, and HeI D3 and the average flare amplitude of the corresponding star, respectively. It can be seen from panels (a) and (b) of Figure 11 that the EW of the Hα line has a significant correlation with the maximum flare amplitude and the average flare amplitude of the corresponding M-type star. In these two panels, we attempt to use parabola to fit the maximum flare amplitude and the average flare Note.1. This is part of Table 7. The full Table 7 will be published online.
(This table is available in its entirety in machine-readable form.) amplitude with Hα EW, and the fitting parameters are listed in the corresponding panel. Chang et al. (2017) studied 54 M-type stars observed by Kepler and LAMOST and agreed that there is a strong correlation between the EW of Hα and its corresponding maximum flare amplitude. In our work, the research sample of M-type flaring stars has been greatly increased to 4143, and study of the Hα EW and the average flare amplitude has been added, further confirming that there is a significant correlation between the EW of Hα and the flare amplitude. It can be seen from panels (c) and (d) of Figure 11 that there is also a correlation between the EW of CaII H and the corresponding flare amplitude, but not as obvious as the relationship between the Hα EW and the flare amplitude, which may be because the S/N near the CaII H line is lower than the S/N near the Hα line in the LAMOST spectrum. In panels (c) and (d), we also attempt to use a parabola to fit the maximum flare amplitude and the average flare amplitude with CaII H EW, and the fitting parameters are listed in the corresponding panels. However, there is no obvious correlation between the EW of HeI D3 and the flare amplitude from panels (e) and (f) of Figure 11. Libbrecht et al. (2019) observed that both the absorption and emission of the HeI D3 line can be present in stellar flares. They believe that whether there is a HeI D3 absorption or emission signal does not depend on the intensity of the flare, but on the physical conditions that govern the local plasma and line formation mechanisms.

Effect of Stellar Rotation Period
Stellar rotation plays a significant role in the generation of stellar magnetic fields (Skumanich 1972;Parker 1979). The combination of stellar rotation and convective motion generates a strong magnetic field inside the star and produces different magnetic activity phenomena, including stellar flares and the emission of characteristic magnetic activity lines, such as the Balmer lines and CaII H&K lines (Suárez Mascareño et al. 2016;Yang et al. 2017;Mittag et al. 2018). In Section 3.3, we have used the Lomb-Scargle method to analyze the light curve of 8964 M-type stars and obtained the rotation period of 8028 M-type stars. Combining the analysis results of the 8028 M-type stellar LAMOST spectra, we present the relationship between the rotation period and the EWs of Hα, CaII H, and HeI D3 in panels (a)-(c) of Figure 12, respectively. From panel (a) of Figure 12, it can be clearly seen that the EW value of Hα gradually decreases as the rotation period increases. Therefore, we try to linearly fit it, as shown by the red line in panel (a). The correlation between the EW of CaII H and HeI D3 and the rotation period is also similar. We performed a linear fitting on them, and the results are shown in the red line in panels (b) and (c). The relationship between the EW of Hα, CaII H, and HeI D3 and the rotation period presented by panels (a)-(c) of Figure 12 can be explained by the influence of the stellar rotation on the stellar magnetic activity. In addition, we also discuss the relationship between the stellar flare amplitude and the rotation period. Panels (d) and (e) of Figure 12 present the flare amplitude of 3811 M-type flaring stars as a function of the rotation period. It can be seen from panels (d) and (e) that the normalized maximum flare amplitude value and average flare amplitude value of the M-type flaring star decrease with the increase in the stellar rotation period. We linearly fit their trends, and the results are shown by the red lines in the panels. The relationship between the flare amplitude and the rotation period shown in panels (d) and (e) can be explained by the influence of the stellar rotation period on the stellar flare. Combining this with Section 4.2, we can conclude that the stellar flare is affected by both the stellar magnetic activity and the stellar rotation period.

Flare Time Frequency
In this section, we define the stellar flare time frequency as the total duration of the stellar flares divided by the observation time of the corresponding star. Panel (a) of Figure Maehara et al. (2012) and Shibayama et al. (2013) studied superflares on solar-type stars, they all took the stellar rotation period equal to 10 days as the threshold of the superflare frequency. The statistical results of panel (b) in Figure 13 confirm that the stellar rotation period equals 10 days, which can be used as a threshold for flare activity in M-type stars. In addition, we also find an interesting result: using the Hα EW equal to 0.75 Å and using the stellar rotation period equal to 10 days as the threshold for the M-type stellar flare time frequency are almost equivalent, because when Hα EW is greater than 0.75 Å, the average of the logarithm of the flare time frequency (−2.3609) is very close to the average of the logarithm of the flare time frequency (−2.3724) with the rotation period less than 10 days, and the result (−2.7504) when the Hα EW is less than 0.75 Å is also very close to the result (−2.7632) of the rotation period greater than 10 days.

Summary
In this work, we have combined the spectroscopic data of LAMOST DR5 and photometric data from the Kepler and K2 missions to study magnetic activities of M-type stars. In Section 2, we have used the Hammer program (West et al. 2004;Covey et al. 2007;West et al. 2011aWest et al. , 2011b to visually assign the spectral type of the M-type stellar spectral candidates in LAMOST DR5 and removed the low-S/N spectra, and we finally obtained 516,688 M-type stellar spectra (see Table 1 for details). In the 516,688 M-type stellar spectra, the spectrum of M0-M3 accounts for 98.2%, and only 1.8% of the spectrum is M4-M9. In addition, we have calculated the EWs of the Hα, Hβ, Hγ, Hδ, CaII H&K, CaII IRT, and HeI D3 spectral lines and determined the activity of these lines based on the defined activity criteria. The results are listed in Table 3. Previous studies (West et al. 2004(West et al. , 2011bYi et al. 2014;Zhang et al. 2016) have shown that the Hα activity ratio is a function of M-type stellar spectral type. In our research samples, 98.2% of them are stellar spectra from M0 to M3 type. Therefore, we mainly analyzed samples from M0 to M3 type. By conducting a statistical study of the EW results in Table 3, we confirmed that the proportion of Hα activity is a function of spectral type in M0-M3. More importantly, we first found that the proportion of activities of Hβ, Hγ, Hδ, CaII H&K, and HeI D3 is also a function of spectral type in M0-M3. Moreover, we have studied the EW-EW relationships between Hα and Hβ, Hγ, Hδ, CaII H&K, CaII IRT, HeI D3 and Hγ and Hδ, CaII H and CaII K, and CaII λ8498 Å and CaII λ8542 Å (see Figure 4 for details). From Figure 4, we found that (1) the EWs of Hβ, Hγ, Hδ, CaII H&K, CaII IRT, and HeI D3 are linearly related to the EWs of Hα; (2) the EW-EW relationships between the same line series (such as Balmer lines, Ca II H&K lines, Ca II IRT lines) also have a linear correlation; (3) the slope (c1) between lines of the same series is greater than the slope (c1) between lines from different series. At the end of Section 2, we have studied the relationship between the R EW value and the spectral type in 5499 M-type stars observed by LAMOST at least twice at different times. The results confirmed the previous results (Kruse et al. 2010;Lee et al. 2010;Bell et al. 2012) that the Hα variability increases at later spectral type. Through the analysis of !EW, we also found that 1791 of the 5499 M-type stars have Hα variability.
In Section 3, we have cross-matched the 516,688 M-type stellar spectra with the Kepler catalog (Huber et al. 2014) and K2 catalog (including Campaigns 0 to 16) with a tolerance of 3″. After removing targets with neighboring stars within 4″ (4″), we obtained the high-precision white-light photometric data (LC) of 834 and 8130 M-type stars from the Kepler and K2 missions, respectively (see Table 6 for details). Then we have used a method similar to Wu et al. (2015) to search for flares from the Kepler/K2 photometric data (long cadence) of the 8964 M-type stars. After using the program to automatically search for flares and visually remove the contaminants, we finally detected 17,432 flares (flare energy > 10 30 erg) from 4143 M-type stars, including 9041 flares from 578 M-type stars from the Kepler mission, and another 8391 flares from 3565 M-type stars from the K2 mission. The parameters of the 17,432 M-type stellar flares are listed in Table 7. After comparing with the previous results (Chang et al. 2017;Yang et al. 2017;Doyle et al. 2018;Schmidt et al. 2019;Günther et al. 2019), we found that the 4143 M-type flaring stars constitute the largest M-type flaring star sample found so far. In addition, we calculated the flare energy and analyzed the relationship between the frequency distribution of flares in M-type stars and the flare energy. The power-law index α is estimated to be 2.02±0.11, and the result is very close to the previous results (Maehara et al. 2012;Shibayama et al. 2013;Wu et al. 2015;Yang et al. 2017). Therefore, we concluded that the flare mechanism of the M-type star may be similar to that of the G-type star. We also used the Lomb-Scargle method (Lomb 1976;Scargle 1982) to analyze the light curve of the 8964 M-type stars and obtained the rotation period of 8028 M-type stars.
In Section 4, we analyzed the statistical correlation between the results of spectroscopic studies and the results of photometric studies of M-type stars. First of all, Figure 10 presents the number distribution of the 8964 M-type stars, the 4143 M-type flaring stars, and the flare frequency of M-type stars as a function of spectral type. It can be seen from Figure 10 that the frequency of flare activity from M0 to M3 is gradually increasing, which is similar to the trend of Hα activity with M-type stellar spectral type in Section 2.3. Combining the results of West et al. (2008) and Yang et al. (2017), we concluded that the flare frequency is an important parameter for measuring the magnetic activity of M-type stars, as well as Balmer lines, CaII H&K lines, CaII IRT lines, and HeI D3 line. Second, Figure 11 presents the relationship between the EWs of the spectral lines (Hα, Ca II H, and He I D3) and the flare amplitude in the 4143 M-type flaring stars. It can be seen from Figure 11 that the EWs of Hα and CaII H have a significant statistical correlation with the flare amplitude in M-type stars. However, there is no obvious statistical correlation between the EW of HeI D3 and the flare amplitude in M-type stars, which could be explained as follows: whether there is HeI D3 absorption or an emission signal does not depend on the intensity of the flare, but on the physical conditions that govern the local plasma and line formation mechanisms (Libbrecht et al. 2019). Third, we have presented the relationship between the rotation period and the EWs of Hα, CaII H, and HeI D3 of the 8028 M-type stars in panels (a)-(c) of Figure 12. From panels (a)-(c) of Figure 12, it can be clearly seen that the EWs of Hα, CaII H, and HeI D3 gradually decrease as the rotation period increases, which could be explained by the influence of the stellar rotation on the stellar magnetic activity. In addition, we have presented the flare amplitude of the 3811 M-type flaring stars as a function of the rotation period in panels (d) and (e) of Figure 12. It can be seen from panels (d) and (e) of Figure 12 that the flare amplitude of the M-type flaring star decreases with the increase in the stellar rotation period, which could be explained by the influence of the stellar rotation period on the stellar flare. Based on the above analysis of Figure 12, we know that the flare amplitude decreases with the increase in stellar rotation period, and the increase in stellar rotation period leads to the decrease in stellar magnetic activity. Therefore, we conclude that the flare amplitude increases with the increase in stellar magnetic activity. Finally, we have studied the relationship between the stellar flare time frequency and the Hα EW in 4143 M-type flaring stars in panel (a) of Figure 13. The results confirm that Hα EW=0.75 Å can be used as a criterion for determining the magnetic activity of M-type stars (West et al. 2011b). Furthermore, we have studied the relationship between the flare time frequency and the rotation period in 3811 M-type flaring stars with rotation period in panel (b) of Figure 13. The statistical results agree that a stellar rotation period equaling 10 days can be used as a threshold for flare activity in M-type stars. We also found that using the Hα EW equal to 0.75 Å and using the stellar rotation period equal to 10 days as the threshold for the M-type stellar flare time frequency are almost equivalent.
In the future, we want to extend our study to the full SDSS spectral database (Abazajian et al. 2009) and the new TESS photometric database (Ricker et al. 2014). Such large, high S/N, and high time-resolution samples will present more accurate statistical results than we reported in this paper. This will greatly increase the M4-M9 spectral type of research samples, allowing us to more comprehensively study the magnetic activity of M-type stars. In addition, the full sample of the automated M-type stellar flare detection in the Kepler and K2 missions should be cross-referenced with previous studies (such as Van Doorsselaere et al. 2017;Yang et al. 2017), which will make the M-type stellar flare database more robust.