From e95d25887b561966f6c5076fe18c3901d1d73897 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 18 Jan 2008 10:54:01 -0500 Subject: [PATCH] Fix unit display. Allow limiting of plots. --- bin/logtool | 8 +++++++- src/log.py | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/logtool b/bin/logtool index d1fb9fa..17ebb32 100755 --- a/bin/logtool +++ b/bin/logtool @@ -35,6 +35,10 @@ following: parser.add_option("--title", help="Set the title of a plot", default="Log evaluation") + parser.add_option("--start-step", metavar="STEP", type="int", + help="Start the plot at this timestep number") + parser.add_option("--end-step", metavar="STEP", type="int", + help="End the plot at this timestep number") options, args = parser.parse_args() if len(args) < 1: @@ -83,8 +87,10 @@ following: expr_x, expr_y = args.pop(0).split(",") from pylab import xlabel, ylabel, plot + print options.start_step, options.end_step (data_x, descr_x, unit_x), (data_y, descr_y, unit_y) = \ - logmgr.get_plot_data(expr_x, expr_y) + logmgr.get_plot_data(expr_x, expr_y, + options.start_step, options.end_step) if options.units_x: xlabel(unit_x) diff --git a/src/log.py b/src/log.py index ca45f8f..d6599ec 100644 --- a/src/log.py +++ b/src/log.py @@ -289,7 +289,7 @@ class LogManager: from pymbolic import substitute, parse unit = substitute(parsed, - dict((dd.expr, parse(dd.quantity.unit)) for dd in dep_data) + dict((dd.varname, parse(dd.quantity.unit)) for dd in dep_data) ) if description is None: @@ -383,14 +383,20 @@ class LogManager: from cPickle import load self.quantity_data, self.constants, self.is_parallel = load(open(filename)) - def get_plot_data(self, expr_x, expr_y): + def get_plot_data(self, expr_x, expr_y, min_step=None, max_step=None): """Generate plot-ready data. @return: C{(data_x, descr_x, unit_x), (data_y, descr_y, unit_y)} """ (descr_x, descr_y), (unit_x, unit_y), data = \ self.get_joint_dataset([expr_x, expr_y]) - _, stepless_data = zip(*data) + if min_step is not None: + data = [(step, tup) for step, tup in data if min_step <= step] + if max_step is not None: + data = [(step, tup) for step, tup in data if step <= max_step] + + stepless_data = [tup for step, tup in data] + data_x, data_y = zip(*stepless_data) return (data_x, descr_x, unit_x), \ (data_y, descr_y, unit_y) -- GitLab