Bathymetric Data
Merge GEBCO global bathymetric grids onto AIS tracks with AISdb, then color and visualize vessel movement by the depth of water it traveled through.
Process AIS data with Bathymetric Data
1
Downloading the GEBCO bathymetry grid
import os
import aisdb
from datetime import datetime
from aisdb import SQLiteDBConn, DBQuery, DomainFromPoints
from aisdb.webdata.bathymetry import Gebco
# set the path to the data storage directory
bathymetry_data_dir = "./bathymetry_data/"
os.makedirs(bathymetry_data_dir, exist_ok=True)
# opening Gebco as a context manager triggers the download if the
# raster tiles aren't already present in data_dir
with Gebco(data_dir=bathymetry_data_dir) as bathy:
print("Bathymetry rasters ready:", list(bathy.rasterfiles.keys()))Bathymetry rasters ready: ['gebco_2022_n0.0_s-90.0_w0.0_e90.0.tif', 'gebco_2022_n90.0_s0.0_w-90.0_e0.0.tif']2
Querying the AIS data
dbpath = "YOUR_DATABASE.db" # path to your AISdb database
start_time = datetime.strptime("2018-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
end_time = datetime.strptime("2018-01-02 00:00:00", "%Y-%m-%d %H:%M:%S")
domain = DomainFromPoints(points=[(-63.6, 44.6)], radial_distances=[500000])
with SQLiteDBConn(dbpath=dbpath) as dbconn:
qry = DBQuery(
dbconn=dbconn, start=start_time, end=end_time,
xmin=domain.boundary["xmin"], xmax=domain.boundary["xmax"],
ymin=domain.boundary["ymin"], ymax=domain.boundary["ymax"],
callback=aisdb.database.sqlfcn_callbacks.in_time_bbox_validmmsi,
)
tracks = aisdb.track_gen.TrackGen(qry.gen_qry(), decimate=False)3
4
Coloring the tracks by depth
def add_color(tracks):
for track in tracks:
# average depth across all positions in the track
avg_depth = sum(track["depth_metres"]) / len(track["depth_metres"])
if avg_depth <= 200:
track["color"] = "yellow" # continental shelf
elif avg_depth <= 2000:
track["color"] = "orange" # continental slope
elif avg_depth <= 6000:
track["color"] = "pink" # abyssal plain
else:
track["color"] = "red" # deep ocean trench
yield trackLast updated
