def test_europe_map(ground_truth_dir, test_output_dir, image_filename='EuropeMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='region:europe', lonlat_linewidth=0.25, lonlat_color='#4040A0', state_border_color='#806060', country_border_color='#408040', draw_coastlines=True, draw_countries=True, draw_states=True, draw_lonlat=True, fill_land=True, fill_water=True, coastline_linewidth=2, coastline_color='#B0B0B0', land_fill_color='#404040', water_fill_color='#000030') pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth( image_filename, ground_truth_dir, test_output_dir)
def main(): print("command line:\n{}\n".format(' '.join(sys.argv))) args = parse_args() dpi = args.dpi image_resolution = args.resolution figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing canvas") figure = pyplot.figure(figsize=figure_dimensions) axes = figure.add_axes([0, 0, 1, 1], frameon=False) axes.set_frame_on(False) print("STATUS: Initializing trajectory source") trajectory_source = setup_trajectory_source(args.trajectory_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_trajectories = itertools.chain(list(trajectory_source)) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points args.map_bbox = data_bbox print("STATUS: Creating map projection") mapmaker_args = argument_groups.extract_arguments("mapmaker", args) (mymap, map_actors) = mapmaker.mapmaker(**mapmaker_args) print("STATUS: Reading trajectories and rendering data") color_scale = matplotlib.colors.Normalize(vmin=0, vmax=1) render_trajectories(mymap, trajectory_source, args) print("STATUS: Saving figure to file") pyplot.savefig( args.image_file[0], # facecolor=figure.get_facecolor(), facecolor='white', figsize=figure_dimensions, dpi=dpi, frameon=False) pyplot.close() return 0
def main(): print("command line:\n{}\n".format(' '.join(sys.argv))) args = parse_args() dpi = args.dpi image_resolution = args.resolution figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing canvas") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) print("STATUS: Initializing point source") point_source = setup_point_source(args.point_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_points = [ point for point in point_source ] # list(point_source) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points args.map_bbox = data_bbox print("STATUS: Creating map projection") mapmaker_args = argument_groups.extract_arguments("mapmaker", args) (mymap, map_actors) = mapmaker.mapmaker(**mapmaker_args) print("STATUS: Initializing trajectory source") trajectory_source = setup_trajectory_source(point_source, args) print("STATUS: Reading points, assembling trajectories and rendering data") color_scale = matplotlib.colors.Normalize(vmin=0, vmax=1) render_trajectories(mymap, trajectory_source, args) print("STATUS: Saving figure to file") pyplot.savefig(args.image_file[0], facecolor=figure.get_facecolor(), figsize=figure_dimensions, dpi=dpi, frameon=False) pyplot.close() return 0
def test_conus_map(ground_truth_dir, test_output_dir, image_filename='ConusMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(map_name='conus', domain='terrestrial') pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth( image_filename, ground_truth_dir, test_output_dir)
def test_conus_map(ground_truth_dir, test_output_dir, image_filename='ConusMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(map_name='conus', domain='terrestrial') pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth(image_filename, ground_truth_dir, test_output_dir)
def test_europe_map(ground_truth_dir, test_output_dir, image_filename='EuropeMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='europe', lonlat_linewidth=0.25, lonlat_color='#6060FF') pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth( image_filename, ground_truth_dir, test_output_dir)
def test_north_america_map(ground_truth_dir, test_output_dir, image_filename='NorthAmericaMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='region:north_america', state_color='#FF8080', country_color='#80FF80', lonlat_color='#0000FF', lonlat_linewidth=0.5) pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth( image_filename, ground_truth_dir, test_output_dir)
def test_europe_map(ground_truth_dir, test_output_dir, image_filename='EuropeMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='europe', lonlat_linewidth=0.25, lonlat_color='#6060FF') pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth(image_filename, ground_truth_dir, test_output_dir)
def test_map_for_airport(ground_truth_dir, test_output_dir, image_filename='MapForAirport.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(map_name='airport:ORD', domain='terrestrial', region_size=(400, 400), land_color='#505050', draw_coastlines=True) pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth(image_filename, ground_truth_dir, test_output_dir)
def test_north_america_map(ground_truth_dir, test_output_dir, image_filename='NorthAmericaMap.png'): pyplot.figure(figsize=(8, 6)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='north_america', state_color='#FF8080', country_color='#80FF80', lonlat_color='#0000FF', lonlat_linewidth=0.5) pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth(image_filename, ground_truth_dir, test_output_dir)
def test_florida_map(ground_truth_dir, test_output_dir, image_filename='CustomBboxMap.png'): pyplot.figure(figsize=(8, 8)) # This is approximately Florida bounding_box = terrestrial.BoundingBox((-88, 24), (-79.5, 31)) (mymap, artists) = mapmaker(domain='terrestrial', map_name='custom', map_bbox=bounding_box, state_color='#FF8080', country_color='#80FF80', lonlat_color='#0000FF', lonlat_linewidth=0.5) pyplot.savefig(os.path.join(test_output_dir, image_filename), dpi=150) pyplot.close() return test_utilities.compare_image_to_ground_truth( image_filename, ground_truth_dir, test_output_dir)
def test_geographic_histogram(outfilename): min_corner = BasePoint(-180, -23.4378) max_corner = BasePoint(180, 23.4378) bbox = BoundingBox(min_corner, max_corner) num_points = 100000 points_in_tropics = random_box_uniform(min_corner, max_corner, num_points) pyplot.figure() pyplot.subplot(111, aspect='equal') mymap = mapmaker(domain='terrestrial', map_name='region:world') histogram2d.render_histogram(map_projection=mymap, point_source=points_in_tropics, bounding_box=bbox, bin_size=0.5, colormap='gist_heat', colorscale=matplotlib.colors.LogNorm()) pyplot.savefig(outfilename, figsize=(4, 4), dpi=150) return True
def example_heatmap_rendering(): #Sample code to render heatmap of points # In this example, data points are filtered and only a set number of cities are represented. num_cities = 40 num_points_per_city = 1000 cities = gen_sample.n_largest_cities(num_cities) all_sources = [ gen_sample.points_near_city(city, num_points_per_city) for city in cities ] all_points = list(itertools.chain(*all_sources)) #The type of map, colors, scaling can be customised depending the on the desired look and feel of the finished map. (figure, axes) = initialize_matplotlib_figure([20, 15]) (mymap, map_actors) = mapmaker.mapmaker(domain='terrestrial', map_name='region:world') render_histogram(mymap, domain='terrestrial', point_source=all_points, bin_size=0.25, color_map='gist_heat', scale_type='logarithmic') print("STATUS: Saving figure to file") savefig_kwargs = { } pyplot.savefig('Example_Heatmap_Rendering.png', figsize=[800,600], dpi=72, frameon=False, facecolor='black' ) pyplot.close() return 0
def main(): args = parse_args() dpi = args.dpi image_resolution = args.resolution if image_resolution is None: image_resolution = [ 800, 600 ] figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing image") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, base_artists) = mapmaker.mapmaker(**mapmaker_kwargs) print("STATUS: Initializing point source for main data file") main_point_source = setup_point_source(args.point_data_file[0], args) print("STATUS: Initializing trajectory source for main data file") main_trajectory_source = setup_trajectory_source(main_point_source, args) print("STATUS: Collecting all trajectories from main source") all_trajectories = list(main_trajectory_source) highlight_trajectories = [] if len(args.highlight) > 0: print("STATUS: Initializing point source for highlight data file") highlight_point_source = setup_point_source(args.highlight[0], args) print("STATUS: Initializing trajectory source for highlight data file") highlight_trajectory_source = setup_trajectory_source(highlight_point_source, args) print("STATUS: Collecting trajectories to highlight") highlight_trajectories = list(highlight_trajectory_source) movie_kwargs = argument_groups.extract_arguments("movie_rendering", args) movie_writer = example_movie_rendering.setup_encoder(**movie_kwargs) # This set of arguments will be passed to the savefig() call that # grabs the latest movie frame. This is the place to put things # like background color, tight layout and friends. savefig_kwargs = { 'facecolor': figure.get_facecolor(), 'figsize': figure_dimensions, 'frameon': False } trajectory_kwargs = argument_groups.extract_arguments("trajectory_rendering", args) example_movie_rendering.render_trajectory_movie( movie_writer, basemap=mymap, trajectories=all_trajectories, dpi=args.dpi, figure=figure, filename=args.movie_file[0], num_frames=movie_kwargs['fps'] * movie_kwargs['duration'], start_time=movie_kwargs['start_time'], end_time=movie_kwargs['end_time'], trail_duration = datetime.timedelta(seconds=args.trail_duration), savefig_kwargs=savefig_kwargs, axes=axes, trajectory_rendering_args=trajectory_kwargs, highlight_trajectories=highlight_trajectories ) pyplot.close() return 0
def main(): args = parse_args() dpi = args.dpi image_resolution = args.resolution if image_resolution is None: image_resolution = [ 800, 600 ] figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing canvas") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) print("STATUS: Initializing point source") point_source = setup_point_source(args.point_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. data_bbox = None if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_points = list(point_source) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points print("STATUS: Initializing map projection") mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, base_artists) = mapmaker.mapmaker(computed_bbox=data_bbox, **mapmaker_kwargs) print("STATUS: Initializing trajectory source") trajectory_source = setup_trajectory_source(point_source, args) print("STATUS: Collecting all trajectories") print("DEBUG: Trajectory source is a {}".format(type(trajectory_source))) all_trajectories = list(trajectory_source) print("STATUS: Done collecting trajectories") movie_kwargs = argument_groups.extract_arguments("movie_rendering", args) movie_writer = example_movie_rendering.setup_encoder(**movie_kwargs) # This set of arguments will be passed to the savefig() call that # grabs the latest movie frame. This is the place to put things # like background color, tight layout and friends. savefig_kwargs = { 'facecolor': figure.get_facecolor(), 'figsize': figure_dimensions, 'frameon': False } trajectory_kwargs = argument_groups.extract_arguments("trajectory_rendering", args) example_movie_rendering.render_trajectory_movie( movie_writer, map_projection=mymap, trajectories=all_trajectories, dpi=args.dpi, figure=figure, filename=args.movie_file[0], num_frames=movie_kwargs['fps'] * movie_kwargs['duration'], start_time=movie_kwargs['start_time'], end_time=movie_kwargs['end_time'], trail_duration = datetime.timedelta(seconds=args.trail_duration), savefig_kwargs=savefig_kwargs, axes=axes, trajectory_rendering_args=trajectory_kwargs ) pyplot.close() return 0
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]) coords.append(location['min_corner'][1]) coords.append(location['max_corner'][0]) coords.append(location['max_corner'][1]) return mapmaker._make_bounding_box(coords, domain) # 100 DPI * (8,6) gives an 800X600 pixel image figure = pyplot.figure(dpi=100, figsize=(8,6)) (mymap, map_actors) = mapmaker.mapmaker(domain='terrestrial', map_name='region:conus') bbox = get_bbox('conus', 'terrestrial') heatmap.render_histogram(mymap, point_source=points, # Our list of points we created above bounding_box = bbox, # Bounding box is generated from mymap bin_size=0.25, color_map='gist_heat')
def example_trajectory_rendering(): '''Sample code to render trajectories from points In some cases, you may wish to read in trajectories with certain constraints. For example, we can have trajectories with a minimum number of points. Or we acknowledge that the points in the trajectory should be within a certain time and/or distance threshold to belong to the same trajectory. The Trajectory Builder does this.''' # First, We will need data points built into trajectories. Replace the following with your own code to build the trajectories or use the provided example. fileName = './tracktable/examples/data/SampleTrajectories.csv' trajectories = example_trajectory_builder(fileName) # Set up the canvas and map projection dpi = 160 figure = pyplot.figure(figsize=[20, 15]) axes = figure.add_subplot(1, 1, 1) #(figure, axes) = initialize_matplotlib_figure([10, 7.5]) (mymap, map_actors) = mapmaker.mapmaker(domain='terrestrial', map_name='region:conus', draw_coastlines=True, draw_countries=True, draw_states=True, draw_lonlat=True, fill_land=True, fill_water=True, land_fill_color='#101010', water_fill_color='#222222', land_zorder=0, water_zorder=0, lonlat_spacing=90, lonlat_color='#A0A0A0', lonlat_linewidth=0.2, lonlat_zorder=2, coastline_color='#808080', coastline_linewidth=1, coastline_zorder=5, country_border_color='#606060', country_fill_color='#FFFF80', country_linewidth=0.5, country_zorder=5, state_border_color='#404040', state_fill_color='none', state_linewidth=0.3, state_zorder=2, draw_largest_cities=50, draw_cities_larger_than=None, city_label_size=12, city_dot_size=2, city_dot_color='white', city_label_color='white', city_zorder=6, border_resolution='110m', axes=axes, map_projection='PlateCarree') color_scale = matplotlib.colors.Normalize(vmin=0, vmax=1) render_trajectories(mymap, trajectories, trajectory_linewidth=2) print("STATUS: Saving figure to file") pyplot.savefig('./Example_Trajectory_Rendering_CONUS.png', figsize=[800, 600], dpi=dpi, frameon=False, facecolor='black') pyplot.close()
def main(): args = parse_args() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) dpi = args.dpi image_resolution = args.resolution figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] logger.info("Initializing image canvas.") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, facecolor='black') axes.set_frame_on(False) logger.info("Initializing point source.") point_filename = args.point_data_file[0] with open(point_filename, 'r') as infile: point_source = points_from_file( infile, args.coordinate0, args.coordinate1, comment_character=args.comment_character, field_delimiter=args.delimiter, domain=args.domain) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. if args.domain == 'cartesian2d': if args.map_bbox is None: logger.info(('Collecting points to compute Cartesian ' 'bounding box.')) point_source = list(point_source) data_bbox = geomath.compute_bounding_box(point_source) else: # The bounding box on the command line is # [x_min, y_min, x_max, y_max] data_bbox = cartesian2d.BoundingBox( (args.map_bbox[0], args.map_bbox[1]), (args.map_bbox[2], args.map_bbox[3]) ) else: # Default to taking the histogram bounds from the map extent. data_bbox = None if args.map_bbox is not None: # The bounding box on the command line is # [x_min, y_min, x_max, y_max] data_bbox = terrestrial.BoundingBox( (args.map_bbox[0], args.map_bbox[1]), (args.map_bbox[2], args.map_bbox[3]) ) logger.info("Creating map projection.") # There are a lot of keyword arguments for the map -- see # tracktable.script_helpers.argument_groups.mapmaker -- # so rather than pull them out individually like we did for # the point reader we extract the whole dict using # tracktable.script_helpers.argument_groups.extract_arguments(). mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, artists) = mapmaker.mapmaker(**mapmaker_kwargs) logger.info("Rendering histogram.") render_histogram(mymap, domain=args.domain, bounding_box=data_bbox, point_source=point_source, bin_size=args.histogram_bin_size, color_map=args.colormap, scale_type=args.scale) # We're done with the points so we exit the with: block where we held # the input file open. if args.title is not None: logger.info("Setting title: {}".format(args.title)) figure.suptitle(args.title, color='white') logger.info("STATUS: Saving figure to file") savefig_kwargs = {'figsize': figure_dimensions, 'dpi': dpi, 'facecolor': args.bgcolor } pyplot.savefig(args.image_file[0], **savefig_kwargs) pyplot.close() return 0
def main(): args = parse_args() dpi = args.dpi image_resolution = args.resolution if image_resolution is None: image_resolution = [800, 600] figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing canvas") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) print("STATUS: Initializing point source") point_source = setup_point_source(args.point_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. data_bbox = None if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_points = list(point_source) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points print("STATUS: Initializing map projection") mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, base_artists) = mapmaker.mapmaker(computed_bbox=data_bbox, **mapmaker_kwargs) print("STATUS: Initializing trajectory source") trajectory_source = setup_trajectory_source(point_source, args) print("STATUS: Collecting all trajectories") print("DEBUG: Trajectory source is a {}".format(type(trajectory_source))) all_trajectories = list(trajectory_source) print("STATUS: Done collecting trajectories") movie_kwargs = argument_groups.extract_arguments("movie_rendering", args) movie_writer = example_movie_rendering.setup_encoder(**movie_kwargs) # This set of arguments will be passed to the savefig() call that # grabs the latest movie frame. This is the place to put things # like background color, tight layout and friends. savefig_kwargs = { 'facecolor': figure.get_facecolor(), 'figsize': figure_dimensions, 'frameon': False } trajectory_kwargs = argument_groups.extract_arguments( "trajectory_rendering", args) example_movie_rendering.render_trajectory_movie( movie_writer, map_projection=mymap, trajectories=all_trajectories, dpi=args.dpi, figure=figure, filename=args.movie_file[0], num_frames=movie_kwargs['fps'] * movie_kwargs['duration'], start_time=movie_kwargs['start_time'], end_time=movie_kwargs['end_time'], trail_duration=datetime.timedelta(seconds=args.trail_duration), savefig_kwargs=savefig_kwargs, axes=axes, trajectory_rendering_args=trajectory_kwargs) pyplot.close() return 0
def main(): logger = logging.getLogger(__name__) args = parse_args() mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) # Some of the argument names for trajectory rendering are out of # sync with their command-line parameter names. We extract those # arguments manually at the render_annotated_trajectories # call instead of using extract_arguments("trajectory_rendering") # here. # Step 1: Load all the trajectories into memory. point_filename = args.point_data_file[0] field_assignments = extract_field_assignments(vars(args)) with open(point_filename, 'r') as infile: logger.info('Loading points and building trajectories.') trajectories = list( trajectories_from_point_file( infile, object_id_column=args.object_id_column, timestamp_column=args.timestamp_column, coordinate0_column=args.coordinate0, coordinate1_column=args.coordinate1, string_fields=field_assignments['string'], real_fields=field_assignments['real'], time_fields=field_assignments['time'], comment_character=args.comment_character, field_delimiter=args.delimiter, separation_distance=args.separation_distance, separation_time=datetime.timedelta( minutes=args.separation_time), minimum_length=args.minimum_length, domain=args.domain)) # Add the 'progress' annotation to all of our trajectories so # we have some way to color them trajectories = [annotations.progress(t) for t in trajectories] # We can compute the bounding box for Cartesian data automatically. # We don't need to do so for terrestrial data because the map will # default to the whole world. if (args.domain == 'cartesian2d' and (args.map_bbox is None or len(args.map_bbox) == 0)): args.map_bbox = geomath.compute_bounding_box( itertools.chain(*trajectories)) # # Step 3: Set up the map. # # There are a lot of keyword arguments for the map -- see # tracktable.script_helpers.argument_groups.mapmaker -- # so rather than pull them out individually like we did for # the point reader we extract the whole dict using # tracktable.script_helpers.argument_groups.extract_arguments(). logger.info('Initializing map canvas for rendering.') (figure, axes) = initialize_canvas(args.resolution, args.dpi) (mymap, map_artists) = mapmaker.mapmaker(**mapmaker_kwargs) if args.trajectory_linewidth == 'taper': linewidth_style = 'taper' linewidth = args.trajectory_initial_linewidth final_linewidth = args.trajectory_final_linewidth else: linewidth_style = 'constant' linewidth = args.trajectory_linewidth final_linewidth = linewidth # Eventually we will be able to use argument_groups.extract_arguments() for # this, but right now it's broken. Not all of the parameters in the # trajectory rendering argument group are supported and some of the names # have changed. # trajectory_rendering_kwargs = { 'decorate_head': args.decorate_trajectory_head, 'head_color': args.trajectory_head_color, 'head_size': args.trajectory_head_dot_size, 'color_map': args.trajectory_colormap, 'scalar': args.trajectory_color, 'scalar_min': args.scalar_min, 'scalar_max': args.scalar_max, 'linewidth_style': linewidth_style, 'linewidth': linewidth, 'final_linewidth': final_linewidth } render_annotated_trajectories(trajectories, mymap, **trajectory_rendering_kwargs) print("STATUS: Saving figure to file") pyplot.savefig(args.image_file[0], facecolor=figure.get_facecolor(), figsize=compute_figure_dimensions(args.resolution, args.dpi), dpi=args.dpi) pyplot.close() return 0
def main(): args = parse_args() dpi = args.dpi image_resolution = args.resolution figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing image") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) print("STATUS: Initializing point source") point_source = setup_point_source(args.point_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_points = [point for point in point_source] # list(point_source) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points args.map_bbox = data_bbox print("STATUS: Creating map projection") mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, artists) = mapmaker.mapmaker(**mapmaker_kwargs) print("STATUS: Rendering histogram") render_histogram(mymap, domain=args.domain, bounding_box=args.map_bbox, point_source=point_source, bin_size=args.histogram_bin_size, color_map=args.colormap, scale_type=args.scale) if args.title is not None: print("Setting title: {}".format(args.title)) figure.suptitle(args.title, color='white') print("STATUS: Saving figure to file") savefig_kwargs = { 'figsize': figure_dimensions, 'dpi': dpi, 'frameon': False, 'facecolor': args.bgcolor } pyplot.savefig(args.image_file[0], **savefig_kwargs) pyplot.close() return 0
def main(): args = parse_args() dpi = args.dpi image_resolution = args.resolution figure_dimensions = [ float(image_resolution[0]) / dpi, float(image_resolution[1]) / dpi ] print("STATUS: Initializing image") figure = pyplot.figure(figsize=figure_dimensions, facecolor='black', edgecolor='black') axes = figure.add_axes([0, 0, 1, 1], frameon=False, axisbg='black') axes.set_frame_on(False) print("STATUS: Initializing point source") point_source = setup_point_source(args.point_data_file[0], args) # This is a little bit ugly but I don't yet know of a better way # to do it. If we want to automatically compute the bounding box # of the data points before we render anything we must read all the # points at least once. # # That gives us a choice: read them once and keep them all in # memory, or make one pass through the file to compute the # bounding box and then another to read and render the points? # # For the moment I elect to read the points and keep them in memory. if args.domain == 'cartesian2d' and args.map_bbox is None: print("STATUS: Collecting points to compute bounding box") all_points = [ point for point in point_source ] # list(point_source) data_bbox = geomath.compute_bounding_box(all_points) point_source = all_points args.map_bbox = data_bbox print("STATUS: Creating map projection") mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) (mymap, artists) = mapmaker.mapmaker(**mapmaker_kwargs) print("STATUS: Rendering histogram") render_histogram(mymap, domain=args.domain, bounding_box=args.map_bbox, point_source=point_source, bin_size=args.histogram_bin_size, color_map=args.colormap, scale_type=args.scale) if args.title is not None: print("Setting title: {}".format(args.title)) figure.suptitle(args.title, color='white') print("STATUS: Saving figure to file") savefig_kwargs = { 'figsize': figure_dimensions, 'dpi': dpi, 'frameon': False, 'facecolor': args.bgcolor } pyplot.savefig(args.image_file[0], **savefig_kwargs) pyplot.close() return 0
def main(): logger = logging.getLogger(__name__) # Step 0: Parse the command line arguments and grab sets we will need # later. args = parse_args() mapmaker_kwargs = argument_groups.extract_arguments("mapmaker", args) movie_kwargs = argument_groups.extract_arguments("movie_rendering", args) # Some of the keyword arguments for trajectory rendering have been renamed. # For now, we'll extract them by hand farther down in this function. # trajectory_rendering_kwargs = argument_groups.extract_arguments( # "trajectory_rendering", args) # Step 1: Load all the trajectories into memory. point_filename = args.point_data_file[0] field_assignments = extract_field_assignments(vars(args)) with open(point_filename, 'r') as infile: logger.info('Loading points and building trajectories.') trajectories = list( trajectories_from_point_file( infile, object_id_column=args.object_id_column, timestamp_column=args.timestamp_column, coordinate0_column=args.coordinate0, coordinate1_column=args.coordinate1, string_fields=field_assignments['string'], real_fields=field_assignments['real'], time_fields=field_assignments['time'], comment_character=args.comment_character, field_delimiter=args.delimiter, separation_distance=args.separation_distance, separation_time=datetime.timedelta(minutes=args.separation_time), minimum_length=args.minimum_length, domain=args.domain) ) # Add the 'progress' annotation to all of our trajectories so # we have some way to color them trajectories = [annotations.progress(t) for t in trajectories] # We can compute the bounding box for Cartesian data automatically. # We don't need to do so for terrestrial data because the map will # default to the whole world. if (args.domain == 'cartesian2d' and (args.map_bbox is None or len(args.map_bbox) == 0)): args.map_bbox = geomath.compute_bounding_box( itertools.chain(*trajectories) ) # # Step 3: Set up the map. # # There are a lot of keyword arguments for the map -- see # tracktable.script_helpers.argument_groups.mapmaker -- # so rather than pull them out individually like we did for # the point reader we extract the whole dict using # tracktable.script_helpers.argument_groups.extract_arguments(). logger.info('Initializing map canvas for rendering.') (figure, axes) = initialize_canvas(args.resolution, args.dpi) (mymap, map_artists) = mapmaker.mapmaker(**mapmaker_kwargs) # # Step 4: Set up the video encoder. # # movie_kwargs = argument_groups.extract_arguments("movie_rendering", args) movie_writer = setup_encoder(**movie_kwargs) # This set of arguments will be passed to the savefig() call that # grabs the latest movie frame. This is the place to put things # like background color, tight layout and friends. savefig_kwargs = {'facecolor': figure.get_facecolor(), 'figsize': compute_figure_dimensions(args.resolution, args.dpi), 'frameon': False} # # Lights! Camera! Action! # if args.trajectory_linewidth == 'taper': linewidth_style = 'taper' linewidth = args.trajectory_initial_linewidth final_linewidth = args.trajectory_final_linewidth else: linewidth_style = 'constant' linewidth = args.trajectory_linewidth final_linewidth = linewidth # Eventually we will be able to use argument_groups.extract_arguments() for # this, but right now it's broken. Not all of the parameters in the # trajectory rendering argument group are supported and some of the names # have changed. # trajectory_rendering_kwargs = { 'decorate_head': args.decorate_trajectory_head, 'head_color': args.trajectory_head_color, 'head_size': args.trajectory_head_dot_size, 'color_map': args.trajectory_colormap, 'scalar': args.trajectory_color, 'scalar_min': args.scalar_min, 'scalar_max': args.scalar_max, 'linewidth_style': linewidth_style, 'linewidth': linewidth, 'final_linewidth': final_linewidth } render_trajectory_movie( movie_writer, axes=mymap, trajectories=trajectories, dpi=args.dpi, figure=figure, filename=args.movie_file[0], num_frames=movie_kwargs['fps'] * movie_kwargs['duration'], start_time=movie_kwargs['start_time'], end_time=movie_kwargs['end_time'], trail_duration=datetime.timedelta(seconds=args.trail_duration), savefig_kwargs=savefig_kwargs, trajectory_rendering_kwargs=trajectory_rendering_kwargs, domain=args.domain ) pyplot.close() logger.info("Movie render complete. File saved to {}".format(args.movie_file[0])) return 0