# Abnormal Ship Behavior Detection Based on AIS Data
## 3 Materials and Methods
### Overview of Study Area and AIS Data Preprocessing
#### 3.1.2 AIS Data Preprocessing  
In 2002, the International Maritime Organization (IMO) approved the automatic identification system (AIS). The AIS has become an indispensable tool for maritime safety detection in the world [31]. The AIS data can be transmitted to the relevant equipment through the satellite receiving system or the shore-based receiving system for storage. There are four types of AIS messages: static messages, dynamic messages, voyage-related messages, and safety-related messages [8]. Since the dynamic and static information can reflect the ship's kinematics information and fixed information at the data level, we filtered the key fields, and the information is shown in Table 1.  
Using the National Water Transport Information Service Platform and the China Port Network, we obtained the navigation data for all vessels of fishing boats, cargo ships, oil tankers, passenger ships, and engineering ships in Zhejiang Province from 25 October 2021 to 24 November 2021. The AIS data arise from the integration of multiple sensor devices. The quality of the AIS data is uneven due to maritime route congestion, navigation equipment failure, and tampering, which may lead to bad data, duplicate data, and missing data. Therefore, we needed to preprocess the crawler data. We preprocessed the AIS data in four aspects: map matching, data cutting, data deletion, and data completion:  
1. **Map matching**. Map matching is essentially a process of matching trajectory points with maps. The geographic coordinate system for the AIS data is WGS84. However, due to the data encryption problem for the data crawler, we needed to perform artificial offset correction by comparing them with the WGS84 map. 2. **Data deletion**. In order to ensure the accuracy of the research, it was necessary to delete illogical data. We directly deleted data in the following cases: (1) trajectory data whose MMSI was null or whose length was not 9, (2) duplicate AIS data, (2) the trajectory of a vessel sailing in a foreign sea area bordering on China, as the study only considered vessels sailing within China's sea areas, and (4) the intersection points of the track segments whose lengths of the adjacent track segments were all greater than the average length of all the segments of the target track. 3. **Data cutting**. As the data obtained by the crawler are accidental, it was possible for multiple navigations to mark a single voyage, so we cut the ship track from the spatial and time angle. 4. **Data completion**. (1) After completion of the data cleaning and cutting, since the offshore environment is unstable, and the probability of shore-based satellite dot drift is high, we chose the Kalman filter algorithm for processing the ship trajectory data. \begin{table}
\begin{tabular}{c c} \hline \hline
**AIS Data Type** & **AIS Data Message Content** \\ \hline \multirow{3}{*}{Static} & Maritime Mobile Service Identification (MMSI), International Maritime \\  & Organization (IMO), callsign, ship width, ship type, ship draught, navigation port \\ \cline{1-1}  & Position, timestamp, speed over ground (SOC), course over ground (COG) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: AIS data message content. on the one hand, it can eliminate abnormal points for the distance offset, and it can effectively smooth the trajectory, making it more in line with the mapping features of the real world. (2) For the continuity of the follow-up study, we then interpolated the trajectory data. For the problem of data completion, we chose the Lagrange first-order interpolation algorithm and the Lagrange second-order interpolation algorithm to complete the trajectory according to the concave-convex trajectory points until the interval condition of the trajectory segment was satisfied. (3) Since some dynamic attributes appeared as null locus points after interpolation, the attributes of the vessel locus points were calculated and completed according to the actual situation.