Skip to main content

a simple ais parser

Project description

I needed a simple AIS decoder for a small art project. I couldn’t find one, so I’m making something minimally adequate for my needs. Decoders are generated automatically from public protocol documentation, but since I use few of the fields myself, I haven’t verified much of the decoding. This code is rough and doesn’t worry much about correctness, and so shouldn’t be used for anything that matters. It especially shouldn’t be used for ship navigation.

SimpleAIS also provides some handy command-line tools, including:

  • aisgrep - pulls out sentences matching given criteria

  • aist - a text dump of sentences, one per line

  • aisburst - takes a large file of sentences and splits it into one file per sender

  • aisinfo - give summary reports for a file of sentences with optional details on each sender

  • aisdump - detailed dumps of individual sentences, including bits

If you would like to try it out and don’t have any AIS data handy, try tests/sample.ais.

Contributions welcome.

Library usage

Here’s an example, a simplified version of the aist tool, which prints one line per complete AIS message:

for sentence in sentences_from_sources(sources):
    result = []
    if sentence.time:
        result.append(sentence.time.strftime(TIME_FORMAT))
    result.append("{:2}".format(sentence.type_id()))
    result.append("{:9}".format(str(sentence['mmsi'])))
    location = sentence.location()
    if location:
        result.append("{:9.4f} {:9.4f}".format(location[0], location[1]))
    if sentence.type_id() == 5:
        result.append("{}->{}".format(sentence['shipname'], sentence['destination']))

    print(" ".join(result))

The sentence_from_sources() function will pull from a wide variety of sources (local files, serial ports, HTTP URLs), yielding only complete sentences as they arrive. Each sentence has a wide variety of readable information. Documented fields can all be referred to by name. For example, sentence['mmsi'] or sentence['shipname']. The location() method will return a tuple of the form (longitude, latitude). Missing or invalid fields will return None.

Command-line usage

Suppose you have a file with a bunch of AIS data from the San Francisco area. You’d like to pull out location transmissions from various sorts of ships and then plot a map of signal density. Further, you’d like to mark the locations of Fort Point and Fort Mason with asterisks just so you have some idea of what you’re seeing. To do that, you can use aisgrep to get the relevant packets and aisinfo to plot the map:

$ aisgrep -t 1 -t 2 -t 3 -t 5 -t 18 -t 19 bayarea.ais | \
aisinfo --map --point -122.4775 37.8108 --point -122.4321 37.8065

Found 51 senders in 15419 good sentences with 39 invalid (0.25%).
      top left: -122.9261, 37.9233
  bottom right: -122.3013, 37.5967
         width: 55.06 km
        height: 36.33 km
+------------------------------------------------------------+
|                                            .   .           |
|                                                 .          |
|                                             . . ..         |
|                                         ..1... ....        |
|                                           ...........      |
|                                          ......1... ..     |
|                                       ....*..1*19.....     |
|        .                          ......          . ..    .|
|              .....          .......                        |
|                   . .........                              |
|                       ...                                  |
|                    ... .                                   |
|                 ....  .                                    |
|                ..     .                                    |
|                       .                                    |
|          ..                                                |
|                                                            |
|                                                            |
|.                                                           |
+------------------------------------------------------------+

Sources

My main source for protocol information is here: http://catb.org/gpsd/AIVDM.html

More protocol info is here: http://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.1371-5-201402-I!!PDF-E.pdf

The protocol checksum is here: https://en.wikipedia.org/wiki/NMEA_0183

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

simpleais-0.6.5.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

simpleais-0.6.5-py3.4.egg (44.4 kB view details)

Uploaded Source

File details

Details for the file simpleais-0.6.5.tar.gz.

File metadata

  • Download URL: simpleais-0.6.5.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for simpleais-0.6.5.tar.gz
Algorithm Hash digest
SHA256 614a0c1238a7538b9fe52041a98b5ead43d39f2d3a59608a4054a8662f1c50b4
MD5 d2c0e4cfe9c36861f0607c0b47017335
BLAKE2b-256 0bd5d1b53da0e35d0a3a9d7e7624f5532505f1c8e203f43e1e6f34c2164eb84e

See more details on using hashes here.

File details

Details for the file simpleais-0.6.5-py3.4.egg.

File metadata

  • Download URL: simpleais-0.6.5-py3.4.egg
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for simpleais-0.6.5-py3.4.egg
Algorithm Hash digest
SHA256 f4c49105ee8abc022b590709cc06e14f844b989300c7a8e2eebc6a7339f76ebb
MD5 0ea358f20b21d5edf9c63f7a0d854c53
BLAKE2b-256 a1852b716b7cb50855829aa964568d06534351bb05b30d89d46661728db34722

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