Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/maxfield-plan
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ if __name__ == "__main__":
parser.add_argument(
'--skip_step_plots', action='store_true',
help=('Skip generating step-by-step linking plots.'))
parser.add_argument('--skip_step_gif', action='store_true',
help=('Skip generating step-by-step linking GIF.'))
parser.add_argument(
'-r', '--res_colors', action='store_true',
help='Use Resistance color scheme.')
Expand Down
6 changes: 5 additions & 1 deletion maxfield/maxfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def maxfield(filename, num_agents=1, num_field_iterations=1000,
num_cpus=1, max_route_solutions=1000,
max_route_runtime=60,
outdir='.', skip_plots=False, skip_step_plots=False,
res_colors=False, google_api_key=None,
skip_step_gif=False, res_colors=False, google_api_key=None,
google_api_secret=None, output_csv=False, verbose=False):
"""
Given a portal list file, determine the optimal linking and
Expand Down Expand Up @@ -202,6 +202,8 @@ def maxfield(filename, num_agents=1, num_field_iterations=1000,
If True, don't generate any figures
skip_step_plots :: boolean
If True, don't generate link-by-link figures
skip_step_gif :: boolean
If True, don't generate link-by-link GIF
res_colors :: boolean
If True, use resistance color scheme, otherwise enlightened
google_api_key :: string
Expand Down Expand Up @@ -256,6 +258,8 @@ def maxfield(filename, num_agents=1, num_field_iterations=1000,
results.link_map()
if not skip_step_plots:
results.step_plots()
if not skip_step_gif:
results.step_gif()
end_time = time.time()
if verbose:
print("Total maxfield runtime: {0:.1f} seconds".
Expand Down
15 changes: 10 additions & 5 deletions maxfield/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def __init__(self, plan, outdir='', res_colors=False,
format(err))
self.extent = [0, 640, 0, 640]

self.frames = []

def key_prep(self):
"""
Save key preparation file to: outdir/key_preparation.txt
Expand Down Expand Up @@ -577,7 +579,6 @@ def step_plots(self):
fig, ax = self.make_portal_fig()
drawn_agents = []
agents_last_pos = []
frames = []
for agent in range(self.plan.num_agents):
#
# Find agent's first location
Expand All @@ -604,7 +605,7 @@ def step_plots(self):
'AP: {0:>7d}'.format(num_ap), fontsize=18)
fname = os.path.join(outdir, 'frame_00000.png')
fig.savefig(fname, dpi=300)
frames.append(fname)
self.frames.append(fname)
#
# Group assignments by arrival time, and plot each arrival
# time actions as a single frame.
Expand Down Expand Up @@ -676,7 +677,7 @@ def step_plots(self):
format(frame))
frame += 1
fig.savefig(fname, dpi=300)
frames.append(fname)
self.frames.append(fname)
#
# Remove drawn lines
#
Expand Down Expand Up @@ -717,7 +718,7 @@ def step_plots(self):
format(frame))
frame += 1
fig.savefig(fname, dpi=300)
frames.append(fname)
self.frames.append(fname)
#
# Remove red patch, update to color and re-add
#
Expand All @@ -728,12 +729,16 @@ def step_plots(self):
plt.close(fig)
if self.verbose:
print("Frames saved to: {0}/".format(outdir))

def step_gif(self):
if self.verbose:
print("Generating plan movie.")
#
# Generate GIF
#
fname = os.path.join(self.outdir, 'plan_movie.gif')
with imageio.get_writer(fname, mode='I', duration=0.5) as writer:
for frame in frames:
for frame in self.frames:
image = imageio.imread(frame)
writer.append_data(image)
optimize(fname)
Expand Down