aisdb.aisdb module

Functions imported from Rust

aisdb.aisdb.binarysearch_vector(arr, search)

Vectorized implementation of binary search for fast array indexing. In out-of-bounds or missing value cases, the nearest search index will be returned

Parameters:
  • arr (Vec<f64>) – sorted array of values to be indexed. values can be sorted either by ascending or descending

  • search (Vec<f64>) – values to be searched within arr

Returns:

indexes (Vec<i32>)

aisdb.aisdb.decoder(dbpath, psql_conn_string, files, source, verbose)

Parse NMEA-formatted strings, and create databases from raw AIS transmissions

Parameters:
  • dbpath (str) – Output SQLite database path. Set this to an empty string to only use Postgres

  • psql_conn_string (str) – Postgres database connection string. Set this to an empty string to only use SQLite

  • files (array of str) – array of .nm4 raw data filepath strings

  • source (str) – data source text. Will be used as a primary key index in database

  • verbose (bool) – enables logging

Returns:

None

aisdb.aisdb.encoder_score_fcn(x1, y1, t1, x2, y2, t2, speed_thresh, dist_thresh)

This function is used internally by aisdb.denoising_encoder.encode_score().

Assigns a score for likelihood of two points being part of a sequential vessel trajectory. A hard cutoff will be applied at distance_threshold, after which all scores will be set to -1.

Parameters:
  • x1 (float) – longitude of coordinate pair 1

  • y1 (float) – latitude of coordinate pair 1

  • t1 (float) – Timestamp for coordinate pair 1 in epoch seconds

  • x2 (float) – longitude of coordinate pair 2

  • y2 (float) – latitude of coordinate pair 2

  • t2 (float) – Timestamp for coordinate pair 2 in epoch seconds

  • speed_threshold (float) – Tracks will be segmented between points where computed speed values exceed this threshold. Segmented tracks will be scored for reconnection. Measured in knots

  • distance_threshold (float) – Used as a numerator when determining score; this value is divided by the distance between xy1 and xy2. If the distance between xy1 and xy2 exceeds this value, the score will be set to -1. Measured in meters

Returns:

f64)

Return type:

score (float

aisdb.aisdb.haversine(x1, y1, x2, y2)

fast great circle distance

Parameters:
  • x1 (float64) – longitude of coordinate pair 1

  • y1 (float64) – latitude of coordinate pair 1

  • x2 (float64) – longitude of coordinate pair 2

  • y2 (float64) – latitude of coordinate pair 2

Returns:

distance in metres (float64)

aisdb.aisdb.receiver(sqlite_dbpath=Ellipsis, postgres_connection_string=Ellipsis, tcp_connect_addr=Ellipsis, tcp_listen_addr=Ellipsis, udp_listen_addr=Ellipsis, multicast_addr_parsed=Ellipsis, multicast_addr_raw=Ellipsis, tcp_output_addr=Ellipsis, udp_output_addr=Ellipsis, dynamic_msg_bufsize=Ellipsis, static_msg_bufsize=Ellipsis, tee=Ellipsis)

Receive raw AIS data from an upstream UDP data source, parse the data into JSON format, and create a websocket listener to send parsed results downstream. If dbpath is given, parsed data will be stored in an SQLite database.

Parameters:
  • sqlite_dbpath (Option<String>) – If given, raw messages will be parsed and stored in an SQLite database at this location

  • postgres_connection_string (Option<String>) – Postgres database connection string

  • udp_listen_addr (String) – UDP port to listen for incoming AIS data streams e.g. “0.0.0.0:9921” or “[::]:9921”

  • tcp_listen_addr (String) – if not None, a thread will be spawned to forward TCP connections to incoming port udp_listen_addr

  • multicast_addr (String) – Raw UDP messages will be parsed and then routed to TCP socket listeners via this channel.

  • multicast_rebroadcast (Option<String>) – Optionally pass a rebroadcast address where raw data will be filtered and rebroadcasted to this channel for e.g. forwarding to downstream networks

  • tcp_output_addr (String) – TCP port to listen for websocket clients to send parsed data in JSON format

  • dynamic_msg_bufsize (Option<usize>) – Number of positional messages to keep before inserting into the database. Defaults to 256 if none is given

  • static_msg_bufsize (Option<usize>) – Number of static messages to keep before inserting into database. Defaults to 64

  • tee (bool) – If True, raw input will be copied to stdout

aisdb.aisdb.simplify_linestring_idx(x, y, precision)

linear curve decimation using visvalingam-whyatt algorithm.

Parameters:
  • x (array of float32) – longitudes

  • y (array of float32) – latitudes

  • precision (float32) – coordinates will be rounded to the nearest value. e.g. 0.01 for decimation to within a few km radius

Returns:

Vec<usize>

Array of indices along (x,y)