aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/motan/motan_graph.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/motan/motan_graph.py')
-rwxr-xr-xscripts/motan/motan_graph.py73
1 files changed, 47 insertions, 26 deletions
diff --git a/scripts/motan/motan_graph.py b/scripts/motan/motan_graph.py
index fc1dee17..8d551340 100755
--- a/scripts/motan/motan_graph.py
+++ b/scripts/motan/motan_graph.py
@@ -7,6 +7,7 @@
import sys, optparse, ast
import matplotlib
import readlog, analyzers
+
try:
import urlparse
except:
@@ -17,6 +18,7 @@ except:
# Graphing
######################################################################
+
def plot_motion(amanager, graphs, log_prefix):
# Generate data
for graph in graphs:
@@ -27,7 +29,7 @@ def plot_motion(amanager, graphs, log_prefix):
times = amanager.get_dataset_times()
# Build plot
fontP = matplotlib.font_manager.FontProperties()
- fontP.set_size('x-small')
+ fontP.set_size("x-small")
fig, rows = matplotlib.pyplot.subplots(nrows=len(graphs), sharex=True)
if len(graphs) == 1:
rows = [rows]
@@ -38,29 +40,29 @@ def plot_motion(amanager, graphs, log_prefix):
label = amanager.get_label(dataset)
ax = graph_ax
if graph_units is None:
- graph_units = label['units']
+ graph_units = label["units"]
ax.set_ylabel(graph_units)
- elif label['units'] != graph_units:
+ elif label["units"] != graph_units:
if graph_twin_units is None:
ax = twin_ax = graph_ax.twinx()
- graph_twin_units = label['units']
+ graph_twin_units = label["units"]
ax.set_ylabel(graph_twin_units)
- elif label['units'] == graph_twin_units:
+ elif label["units"] == graph_twin_units:
ax = twin_ax
else:
graph_units = "Unknown"
ax.set_ylabel(graph_units)
- pparams = {'label': label['label'], 'alpha': 0.8}
+ pparams = {"label": label["label"], "alpha": 0.8}
pparams.update(plot_params)
ax.plot(times, datasets[dataset], **pparams)
if twin_ax is not None:
li1, la1 = graph_ax.get_legend_handles_labels()
li2, la2 = twin_ax.get_legend_handles_labels()
- twin_ax.legend(li1 + li2, la1 + la2, loc='best', prop=fontP)
+ twin_ax.legend(li1 + li2, la1 + la2, loc="best", prop=fontP)
else:
- graph_ax.legend(loc='best', prop=fontP)
+ graph_ax.legend(loc="best", prop=fontP)
graph_ax.grid(True)
- rows[-1].set_xlabel('Time (s)')
+ rows[-1].set_xlabel("Time (s)")
return fig
@@ -68,23 +70,26 @@ def plot_motion(amanager, graphs, log_prefix):
# Startup
######################################################################
+
def setup_matplotlib(output_to_file):
global matplotlib
if output_to_file:
- matplotlib.use('Agg')
+ matplotlib.use("Agg")
import matplotlib.pyplot, matplotlib.dates, matplotlib.font_manager
import matplotlib.ticker
+
def parse_graph_description(desc):
- if '?' not in desc:
+ if "?" not in desc:
return (desc, {})
- dataset, params = desc.split('?', 1)
+ dataset, params = desc.split("?", 1)
params = {k: v for k, v in urlparse.parse_qsl(params)}
- for fkey in ['alpha']:
+ for fkey in ["alpha"]:
if fkey in params:
params[fkey] = float(params[fkey])
return (dataset, params)
+
def list_datasets():
datasets = readlog.list_datasets() + analyzers.list_datasets()
out = ["\nAvailable datasets:\n"]
@@ -94,21 +99,35 @@ def list_datasets():
sys.stdout.write("".join(out))
sys.exit(0)
+
def main():
# Parse command-line arguments
usage = "%prog [options] <logname>"
opts = optparse.OptionParser(usage)
- opts.add_option("-o", "--output", type="string", dest="output",
- default=None, help="filename of output graph")
- opts.add_option("-s", "--skip", type="float", default=0.,
- help="Set the start time to graph")
- opts.add_option("-d", "--duration", type="float", default=5.,
- help="Number of seconds to graph")
- opts.add_option("--segment-time", type="float", default=0.000100,
- help="Analysis segment time (default 0.000100 seconds)")
+ opts.add_option(
+ "-o",
+ "--output",
+ type="string",
+ dest="output",
+ default=None,
+ help="filename of output graph",
+ )
+ opts.add_option(
+ "-s", "--skip", type="float", default=0.0, help="Set the start time to graph"
+ )
+ opts.add_option(
+ "-d", "--duration", type="float", default=5.0, help="Number of seconds to graph"
+ )
+ opts.add_option(
+ "--segment-time",
+ type="float",
+ default=0.000100,
+ help="Analysis segment time (default 0.000100 seconds)",
+ )
opts.add_option("-g", "--graph", help="Graph to generate (python literal)")
- opts.add_option("-l", "--list-datasets", action="store_true",
- help="List available datasets")
+ opts.add_option(
+ "-l", "--list-datasets", action="store_true", help="List available datasets"
+ )
options, args = opts.parse_args()
if options.list_datasets:
list_datasets()
@@ -131,8 +150,9 @@ def main():
]
if options.graph is not None:
graph_descs = ast.literal_eval(options.graph)
- graphs = [[parse_graph_description(g) for g in graph_row]
- for graph_row in graph_descs]
+ graphs = [
+ [parse_graph_description(g) for g in graph_row] for graph_row in graph_descs
+ ]
# Draw graph
setup_matplotlib(options.output is not None)
@@ -145,5 +165,6 @@ def main():
fig.set_size_inches(8, 6)
fig.savefig(options.output)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
main()