def main(): # Can we read a data file from the standard data directory? If # this succeeds, we've read it successfully. with open(os.path.join(data_directory(), 'SampleFlightsUS.csv')) as infile: data = infile.read() if len(data) == 0: return 1 else: return 0
signature = [] signature.append(cha(trajectory)) signature.append(distance(trajectory[0], trajectory[len(trajectory)-1])) return convert_to_feature_vector(signature) # Now we need to collect our data from our dataset and organize it into trajectories. # We save the trajectories to a list so we can work with them as many times as we want. from tracktable.domain.terrestrial import TrajectoryPointReader from tracktable.source.trajectory import AssembleTrajectoryFromPoints from tracktable.analysis.dbscan import compute_cluster_labels from tracktable.core import data_directory import os.path data_filename = os.path.join(data_directory(), 'april_04_2013.csv') inFile = open(data_filename, 'r') reader = TrajectoryPointReader() reader.input = inFile reader.comment_character = '#' reader.field_delimiter = ',' reader.object_id_column = 0 reader.timestamp_column = 1 reader.coordinates[0] = 2 reader.coordinates[1] = 3 builder = AssembleTrajectoryFromPoints() builder.input = reader builder.minimum_length = 5 builder.separation_time = timedelta(minutes=20)
# Purpose: Sample code to render heatmap of points # Imports from tracktable.domain.terrestrial import TrajectoryPointReader from tracktable.render import mapmaker from tracktable.render.histogram2d import render_histogram from tracktable.render import maps from tracktable.core import data_directory from matplotlib import pyplot import os.path # First we set up our point source by reading points from a file. Then we dump the points to a list. # We do not care about extra data in this example, so we leave all the column fields as default. points = [] data_filename = os.path.join(data_directory(), 'SampleHeatmapPoints.csv') with open(data_filename, 'r') as inFile: reader = TrajectoryPointReader() reader.input = inFile reader.comment_character = '#' reader.field_delimiter = ',' for point in reader: points.append(point) # Now we generate a map and create a heatmap from the points we generated. # Set up the canvas and map projection # Set up a bounding box based off of a default def get_bbox(area, domain): coords = []
# Imports from tracktable.domain import terrestrial from tracktable.render import mapmaker from tracktable.core import data_directory from tracktable.render import paths from tracktable.feature import annotations import numpy import matplotlib from matplotlib import pyplot import os.path # **Requirements**: We will need data points built into trajectories. Replace the following with your own code to build the trajectories or use the provided example. trajectory_filename = os.path.join(data_directory(), 'SampleTrajectories.traj') infile = open(trajectory_filename, 'r') trajectories = terrestrial.TrajectoryReader() trajectories.input = infile # Set up the canvas and map projection # 8 x 6 inches at 100 dpi = 800x600 image figure = pyplot.figure(dpi=100, figsize=(8, 6)) (mymap, map_actors) = mapmaker.mapmaker(domain='terrestrial', map_name='region:world') color_scale = matplotlib.colors.Normalize(vmin=0, vmax=1) paths.draw_traffic(traffic_map=mymap, trajectory_iterable=trajectories) # It is possible the scale of the selected map is not appropriate for the trajectories you wish to render. The rendered example map is of the continental United States (CONUS for short). This is one of the preset convenience maps and was set as the map name when we called the render function. Other convenience maps are europe, north_america, south_america, australia and world. #
# object id, timestamp, longitude, and latitude. # Imports from tracktable.domain.terrestrial import TrajectoryPointReader from tracktable.core import data_directory import os.path # To create a point, we create a generic TrajectoryPointReader object and give it the following: # input file - File stream connected to a data file # delimiter - The character separating fields in the fileie, a csv will have ',' as a delimiter) # comment character - The character marking comments in the file and will be ignored by the point reader # Note: The domain will default to terrestrial, which is what we typically use for real data. inFile = open(os.path.join(data_directory(), 'SampleASDI.csv'), 'r') reader = TrajectoryPointReader() reader.input = inFile reader.comment_character = '#' reader.field_delimiter = ',' # In order to view the points the reader has read, we iterate over the reader. # Note: Data is not actually read from file until accessed. This means that even # though we have configured the reader, the reader is not finished with the input # file until the points have been read below. i = 10 # Used to limit how many results we see for x in reader: # Only need this line and the next to see all the data print(x) i -= 1 if i <= 0: