def count_message_types_example(): """ Example for decoding a file and counting the number of message per type :return: """ with open("ais.exploratorium.edu", "r") as file: message_types = dict() for aline in file: try: msg = aline.rstrip("\n") ais_data = pyAISm.decod_ais(msg) # Return a dictionnary if 'type' in ais_data: if ais_data['type']: msg_type = ais_data['type'] if msg_type in message_types: message_types[msg_type] += 1 else: message_types[msg_type] = 1 except pyAISm.UnrecognizedNMEAMessageError as e: pass except pyAISm.BadChecksumError as e: pass except Exception as e: print e print('End of file') print(message_types)
def decode_file_example(): """ Example for decoding a file :return: """ with open("ais.exploratorium.edu", "r") as file: for aline in file: try: msg = aline.rstrip("\n") ais_data = pyAISm.decod_ais(msg) # Return a dictionnary ais_format = pyAISm.format_ais(ais_data) # A more human readable dictionnary print(ais_format) # Accessing the value of the key except pyAISm.UnrecognizedNMEAMessageError as e: print e except pyAISm.BadChecksumError as e: print e except Exception as e: print e print('End of file')
def decode_stream_example(): """ Example for decoding an online data stream :return: """ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("ais.exploratorium.edu", 80)) s.sendall("GET / HTTP/1.1\r\nHost: www.cnn.com\r\n\r\n".encode()) while (True): msg = (s.recv(4096).decode('utf-8')).splitlines() for m in msg: try: msg = m.rstrip("\n") ais_data = pyAISm.decod_ais(msg) # Return a dictionnary ais_format = pyAISm.format_ais(ais_data) # A more human readable dictionnary print(ais_format) # Accessing the value of the key except pyAISm.UnrecognizedNMEAMessageError as e: print e except pyAISm.BadChecksumError as e: print e except Exception as e: print e
import pandas as pd import numpy as np import pyAISm raw_data = pd.read_csv("CCG_AIS_Log_2018-05-01.csv", sep="\\") # print(raw_data) df = raw_data.iloc[:, 2] print(df) data = pd.DataFrame(columns=[ 'type', 'repeat', 'mmsi', 'status', 'turn', 'speed', 'knots', 'accuracy', 'lon', 'lat', 'course', 'heading', 'second', 'maneuver', 'raim', 'radio' ]) for row in df: if type(row) == float: pass else: decoded = pyAISm.decod_ais(row) formating = pyAISm.format_ais(decoded) data.append(formating, ignore_index=True) decoded_data = data.to_csv("CCG_AIS_Log_2018-05-01_DECODED.csv")
import pyAISm string = "\c:1525143369,C:359,s:P-Parke*6F\!AIVDM,1,1,8,B,15O<@N001sG:hgHL6F?m;T6D00S@,0*7C" a = string.split("\\") ais_data = pyAISm.decod_ais(a[2]) ais_format = pyAISm.format_ais(ais_data) print(ais_format)