def read_points_from_string(text): print("Input text:\n{}(end)".format(text)) input = version_appropriate_string_buffer(text) reader = TrajectoryPointReader(input) points = list(reader) return points
def test_trajectory_point_reader(filename, expected_num_points): print("Attempting to read {} points from file {}.".format(expected_num_points, filename)) with open(filename, 'rb') as infile: reader = TrajectoryPointReader() reader.input = infile reader.field_delimiter = "\t" reader.coordinates[0] = 2 reader.coordinates[1] = 3 all_points = [] for point in reader: # print("Next point: {}, serial number {}".format(point, point.serial)) all_points.append(point) if len(all_points) != expected_num_points: print("ERROR: Expected to see {} points but saw {} instead.".format( expected_num_points, len(all_points))) return 1 else: return 0
def test_trajectory_point_reader(filename, expected_num_points): print("Attempting to read {} points from file {}.".format(expected_num_points, filename)) with open(filename, 'rb') as infile: reader = TrajectoryPointReader() reader.input = infile reader.field_delimiter = "," # reader.coordinates[0] = 2 # reader.coordinates[1] = 3 # reader.object_id_column = 0 # reader.timestamp_column = 1 all_points = [] for point in reader: print("Next point: {}".format(point)) all_points.append(point) if len(all_points) != expected_num_points: print("ERROR: Expected to see {} points but saw {} instead.".format(expected_num_points, len(all_points))) return 1 else: return 0
def test_trajectory_point_reader(filename, expected_num_points): print("Attempting to read {} points from file {}.".format( expected_num_points, filename)) with open(filename, 'rb') as infile: reader = TrajectoryPointReader() reader.input = infile reader.field_delimiter = "," # reader.coordinates[0] = 2 # reader.coordinates[1] = 3 # reader.object_id_column = 0 # reader.timestamp_column = 1 all_points = [] for point in reader: print("Next point: {}".format(point)) all_points.append(point) if len(all_points) != expected_num_points: print("ERROR: Expected to see {} points but saw {} instead.".format( expected_num_points, len(all_points))) return 1 else: return 0
def test_trajectory_point_reader(filename, expected_num_points): print("Attempting to read {} points from file {}.".format( expected_num_points, filename)) with open(filename, 'rb') as infile: reader = TrajectoryPointReader() reader.input = infile reader.field_delimiter = "\t" reader.coordinates[0] = 2 reader.coordinates[1] = 3 all_points = [] for point in reader: # print("Next point: {}, serial number {}".format(point, point.serial)) all_points.append(point) if len(all_points) != expected_num_points: print("ERROR: Expected to see {} points but saw {} instead.".format( expected_num_points, len(all_points))) return 1 else: return 0
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) all_trajectories = list(builder)
# 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 = [] location = maps.CONVENIENCE_MAPS[area] coords.append(location['min_corner'][0])
def read_points_from_string(text): print("Input text:\n{}(end)".format(text)) input = StringIO(text) reader = TrajectoryPointReader(input) points = list(reader) return points
# 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: break