Git Product home page Git Product logo

aisutils's Introduction

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.

*** 最后写依赖的时候整理一下

aisutils's People

Contributors

kw411718198 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.