def render_frame_batch(self, batch_info): """Render a single group of frames. In order to preserve maximum image quality, we encode each movie chunk with FFMPEG's 'ffv1' lossless codec. We will maintain lossless encoding until right at the end when we encode the final movie with the user's desired compression parameters. Args: batch_info (list): Group of ( numeric_id, start_frame_number, num_frames, temp_directory ) Returns: Filename (with path) for encoded movie fragment """ batch_id = batch_info[0] start_frame = batch_info[1] num_frames = batch_info[2] self.temp_directory = batch_info[3] chunk_writer = example_movie_rendering.setup_encoder(encoder='ffmpeg', codec='ffv1', fps=self.fps) chunk_filename = os.path.join(self.temp_directory, 'movie_chunk_{}.mkv'.format(batch_id)) # hand off to the movie renderer to draw them example_movie_rendering.render_trajectory_movie(chunk_writer, self.basemap, self.trajectories, first_frame=start_frame, num_frames=num_frames, num_frames_overall=self.num_frames_overall, trail_duration=self.trail_duration, figure=self.figure, dpi=self.dpi, filename=chunk_filename, start_time=self.start_time, end_time=self.end_time, savefig_kwargs=self.savefig_kwargs, trajectory_rendering_args=self.trajectory_rendering_kwargs, frame_batch_size=100, axes=self.axes, utc_offset=self.utc_offset, timezone_label=self.timezone_label, batch_id=batch_id) return chunk_filename
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(): 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