###### Abstract  
P-wave first-motion polarity is important for the inversion of earthquake focal mechanism solutions. The focal mechanism solution can further contribute to our understanding of the source rupture process, the fault structure, and the regional stress field characteristics. By using the abundant focal mechanism solutions of small and moderate earthquakes, we can deepen our understanding of fault geometry and the seismogenic environment. In this paper, we propose an automatic workflow, FocMech-Flow (Focal Mechanism-Flow), for identifying P-wave first-motion polarity and focal mechanism inversion with deep learning and applied it to the 2021 Yangbi earthquake sequence. We use a deep learning model named DiTingMotion to detect the P-wave first-motion polarity of 2389 waveforms, resulting in 98.49% accuracy of polarity discrimination compared with human experts. The focal mechanisms of 112 earthquakes are obtained by using the CHNYTX program, which is 3.7 times more than that of the waveform inversion method, and the results are highly consistent. The analysis shows that the focal mechanisms of the foreshock sequence of the Yangbi earthquake are highly consistent and are all of the strike-slip type; the focal mechanisms of the aftershock sequence are complex, mainly the strike-slip type, but there are also reverse and normal fault types. This study shows that the deep learning method has high reliability in determining the P-wave first-motion polarity, and FocMech-Flow can obtain a large number of focal mechanism solutions from small and moderate earthquakes, having promising application in fine-scale stress inversion. P-wave first-motion; focal mechanism; Yangbi earthquake; deep learning Article  
19 January 2023  
1  
can give a good focal mechanism solution even when there are few stations. However, most of the earthquakes recorded by the regional seismic network are small earthquakes below M3.0, with short propagation distances and high-frequency components, making their waveforms difficult to fit and their focal mechanism solutions difficult to obtain. On the other hand, because the rupture of small earthquakes is relatively simple, the results based on the P-wave first-motion polarity are generally consistent with the results based on waveform fitting. Therefore, for small earthquakes (M < 3.0), the first-motion polarity of P-wave inversion is often used to retrieve focal mechanism solutions [1; 6; 13; 14; 15; 16]. Manually identifying the first-motion polarity of a P-wave is stable, reliable, and easy to operate, and it was the earliest method used to study the source mechanism of earthquakes [17]. With the continuous advancement of technology, many focal mechanism inversion methods have been developed, such as [18; 19], combining P-wave first-motion polarity and the S/P wave amplitude ratio to determine focal mechanisms, which was called the HASH method. Moreover, [20] used a high-frequency full waveform combined with P-wave first-motion and the S/P wave amplitude ratio to invert the focal mechanism of small earthquakes in a sparse network, and the GPAT [21] method combines P-wave first-motion polarity and generalized maximum amplitude to invert the focal mechanism of earthquakes. The identification of the P-wave first-motion polarity was performed manually in the past. In recent years, with the construction of the National Intensity Rapid Report and Earthquake Early Warning Project, the number of seismic stations in China has increased from \(\sim\)1200 to more than 15,000. Manual processing can no longer meet the needs for the development of earthquake monitoring. In order to quickly identify the polarity of a P-wave, seismologists have developed a variety of methods.