Skip to main content

ais tools package

Project description

aisUtils

A tool package for MITS AIS users.

Install

pip install aisUtils

Develop

git clone https://github.com/aisUtils.git

Usage

The package can satisfy fundamental demand for the use of AIS, which is what I usually do.

Preprocessing

Suppose we start with AIS messages. We need to decode, crawl static information and perform filtering operations.

decoder

The decoder process requires the package—libais.

Parameters include source file path, destination file path and original timestamp, no return value. If you want to decode multiple files, it is easy to use a loop outside the call.

from aisUtils import Preprocessing as pp
sourcePath = r'D:/data/2021-08-28_CST.txt' # source file path
desPath = r'D:/data/2021-08-28_output.csv' # destination file path
timestr = '2021-08-28:00:00:00;' # AIS initial timestamp

pp.decode(sourcePath, desPath, timestr)

crawl

If you need some static data such as length, ship type, crawl them from a mmsi list. Then you will get a static data table.

from aisUtils import Preprocessing as pp

sourcePath = r'D:/python/data' # a directory stored all ais files
mmsiPath = r'D:/python/mmsiall.csv' # store mmsilist
staticDataPath = r'D:/python/staticData.csv' # store ais static data

# get the mmsilist
mmsiList = pp.getMmsiList(sourcePath)
# write the mmsilist
pp.writeMmsiList(mmsiPath, mmsiList)
# crawl
pp.crawl(mmsiPath, staticDataPath)

matching

Match the static data — length and ship type with the ais files.

from aisUtils import Preprocessing as pp

staticDataPath  = r'D:/python/staticData.csv'
aisPath = r'D:/data/2021-08-28_output.csv'
desPath = r'D:/data/2021-08-28_matching.csv'

pp.match(staticDataPath, aisPath, desPath)

others

This part includes area, speed and ship type filtering.

from aisUtils import Preprocessing as pp

sourcePath = r'D:/data/2021-08-28_matching.csv'
desPath = r'D:/data/2021-08-28_prep.csv'

max_Lon = 122.757
min_Lon = 122.145
max_Lat = 30.749
min_Lat = 30.409
speed = [2, 20]
shiptype_list = [6, 7, 8]

pp.filtering(sourcePath, desPath, max_Lon, min_Lon, max_Lat, min_Lat, speed, shiptype_list)

if you want to read the file, you can use the code block, which returns a array type.

import pandas as pd
data = pd.read_csv(r'D:/data/2021-08-28_prep.csv')
data_p = data.values
#print(type(data_p)) #numpy.ndarray

Interpolation

Package scipy has powerful statistical tools. CSDN link

from scipy import interpolate as inter
from scipy.interpolate import lagrang
import numpy as np
# sort the data according the index
# data = data[np.lexsort((data[:,1], data[:,0]))]
xli = np.arange(0,constants.pi*2,0.1)   #   Interval points
yli = inter.interp1d(x,y,kind ="linear")(xli) # Linear interpolation
ycub = inter.interp1d(x,y,kind ="cubic")(xli) # Cubic spline interpolation
yquadratic = inter.interp1d(x,y,kind ="quadratic")(xli)     #  Quadratic spline interpolation
ynear = inter.interp1d(x,y,kind ="nearest")(xli) # Nearest neighbor interpolation

# Lagrange interpolation
def lagrangePoly(poly, x, length):
    result = []
    for i in range(len(x)):
        subresult = 0
        for j in range(length):
            subresult += poly[j] * (x[i] ** j)
        result.append(subresult)
    return result

x = np.linspace(0,constants.pi*2,4)
y = np.cos(x**2/3+4)

poly = lagrange(x, y)   
length = len(x)
ylagrange = lagrangePoly(poly, xli, length)

Calculation

Haversine

from haversine import haversine
lyon=(45.7597,4.8422)# (lat, lon)
paris=(48.8567,2.3508)
haversine(lyon,paris)

scipy spatial

from scipy.spatial.distance import cdist
cdist(x1, x2, metric = ' euclidean') # Euclidean distance
cdist(x1, x2, metric = 'minkowski')
cdist(x1, x2, metric = ' jaccard')

Project

Some codes for project, including section flow statistics, ship types statistics and track point drawing.

Description

Although I have created many functions in the package according my own ideas, there are still many possible requirements that can be improved later. I am tired. Thanks to senior fellow apprentice Chunshen for supporting the development of the crawl function.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aisUtils-0.1.4.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

aisUtils-0.1.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file aisUtils-0.1.4.tar.gz.

File metadata

  • Download URL: aisUtils-0.1.4.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.8

File hashes

Hashes for aisUtils-0.1.4.tar.gz
Algorithm Hash digest
SHA256 504c58243a489efe1aef5bc791ca1363264c66dc69877a35b7e0037c9db427ff
MD5 fc77dcb09fcd9229a92ac1f529ff70c3
BLAKE2b-256 8ec29c7bea83451b89c119ffbd3b0cb8730a9d2e0f36a42a79c7cea9b6ba927b

See more details on using hashes here.

File details

Details for the file aisUtils-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: aisUtils-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.8

File hashes

Hashes for aisUtils-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a90f68f1c616bf378f93900c2e783cea792aed56fe0b04c5d09a400c9009e05d
MD5 77878b1b28935af08226adcc4d333b0f
BLAKE2b-256 254cf00bc90977cd3dd6a1c0589b61363a1e8834e09a3fc1cc7f34eccb1c6d6d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page