Tutorial 3: How to Write Trajectories to a .traj File

In [1]:
import tracktable.examples.tutorials.tutorial_helper as tutorial

Purpose

This notebook demonstrates how to write Tracktable trajectories to a .traj file. This will compress our trajectories and allow them to be read by Tracktable more quickly than a delimited file.

Step 1: Start with a list of trajectories.

We will use the provided example data \(^1\) for this tutorial. For the sake of brevity, the function below executes the steps from Tutorial 1 and Tutorial 2 to create a list of trajectories.

In [2]:
trajectories = tutorial.get_trajectory_list_from_csv()
INFO:tracktable.applications.assemble_trajectoriesAssembleTrajectoryFromPoints:New trajectories will be declared after a separation of 10 distance units between two points or a time lapse of at least 0:20:00 (hours, minutes, seconds).
INFO:tracktable.applications.assemble_trajectoriesAssembleTrajectoryFromPoints:Trajectories with fewer than 5 points will be discarded.
INFO:tracktable.applications.assemble_trajectoriesAssembleTrajectoryFromPoints:Done assembling trajectories. 279 trajectories produced and 22 discarded for having fewer than 5 points.

Step 2: Name your new .traj file.

In [3]:
traj_filename = 'my_trajectories.traj'

Step 3: Write your trajectories to the .traj file.

In [4]:
from tracktable.domain.terrestrial import TrajectoryWriter

with open(traj_filename, 'wb') as output:
    writer = TrajectoryWriter(output)
    writer.write(trajectories)

How do we read .traj files?

See Tutorial 4 for an example of how to read .traj files with Tracktable.

\(^1\) Bureau of Ocean Energy Management (BOEM) and National Oceanic and Atmospheric Administration (NOAA). MarineCadastre.gov. AIS Data for 2020. Retrieved February 2021 from marinecadastre.gov/data. Trimmed down to the first hour of June 30, 2020, restricted to in NY Harbor.