aisdb.proc_util module

aisdb.proc_util.getfiledate(filename, source=None)[source]

attempt to parse the first valid epoch timestamp from .nm4 data file. timestamp will be returned as datetime.date if successful, otherwise will return False if no date could be found

Parameters:
  • filename (string) – raw AIS data file in .nm4 or .csv format

  • source (string) – data source of CSV file; time column handle is different if “NOAA” (case insensitive) is specified

aisdb.proc_util.glob_files(dirpath, ext='.txt', keyorder=<function <lambda>>)[source]

walk a directory to glob txt files. can be used with ZoneGeomFromTxt()

zones_dir: string

directory to walk

keyorder:

anonymous function for custom sort ordering

example keyorder:

# numeric sort on zone names with strsplit on 'Z' char
keyorder=lambda key: int(key.rsplit(os.path.sep, 1)[1].split('.')[0].split('Z')[1])
Returns:

.txt shapefile paths

aisdb.proc_util.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.proc_util.tracks_csv(tracks, skipcols: list = ['label', 'in_zone'])[source]

Yields row tuples when given a track generator. See write_csv() for more info

aisdb.proc_util.write_csv(tracks, fpath: BytesIO | str | SpooledTemporaryFile, skipcols: list = ['label', 'in_zone'])[source]

write track vector dictionaries as CSV file

Parameters:
  • tracks (iter) – track generator such as returned by aisdb.track_gen.TrackGen()

  • fpath (string) – output CSV filepath (string) or io.BytesIO buffer

  • skipcols (list) – columns to be omitted from results

aisdb.proc_util.write_csv_rows(rows, pathname='output.csv', mode='a')[source]