Skip to content
Snippets Groups Projects
Unverified Commit 004d6737 authored by Sam Yates's avatar Sam Yates Committed by GitHub
Browse files

Make tsplot python2/python3 compatible. (#624)

* Use python3 version of print.
* Use dict update method instead of item concatenation, as in Python3 dict.items() no longer returns a list.
parent 3f3cd9f9
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2 #!/usr/bin/env python
#coding: utf-8 #coding: utf-8
from __future__ import print_function
import argparse import argparse
import json import json
import numpy as np import numpy as np
...@@ -39,7 +41,6 @@ def parse_clargs(): ...@@ -39,7 +41,6 @@ def parse_clargs():
P.add_argument('inputs', metavar='FILE', nargs='+', P.add_argument('inputs', metavar='FILE', nargs='+',
help='time series data in JSON format') help='time series data in JSON format')
P.add_argument('-A', '--abscissa', metavar='AXIS', dest='axis', P.add_argument('-A', '--abscissa', metavar='AXIS', dest='axis',
type=unicode,
help='use values from AXIS instead of \'time\' as abscissa') help='use values from AXIS instead of \'time\' as abscissa')
P.add_argument('-t', '--trange', metavar='RANGE', dest='trange', P.add_argument('-t', '--trange', metavar='RANGE', dest='trange',
type=parse_range_spec, type=parse_range_spec,
...@@ -226,7 +227,9 @@ def read_json_timeseries(j, axis='time', select=[]): ...@@ -226,7 +227,9 @@ def read_json_timeseries(j, axis='time', select=[]):
for key in jdata.keys(): for key in jdata.keys():
if key==axis: continue if key==axis: continue
meta = dict(j.items() + {'label': key, 'data': None, 'units': units(key)}.items()) meta = j.copy()
meta.update({'label': key, 'data': None, 'units': units(key)})
del meta['data'] del meta['data']
if not select or any([all([run_select(s, meta) for s in term]) for term in select]): if not select or any([all([run_select(s, meta) for s in term]) for term in select]):
...@@ -450,11 +453,11 @@ for filename in args.inputs: ...@@ -450,11 +453,11 @@ for filename in args.inputs:
if args.list: if args.list:
for ts in tss: for ts in tss:
print 'name:', ts.meta['name'] print('name:', ts.meta['name'])
print 'label:', ts.meta['label'] print('label:', ts.meta['label'])
for k in [x for x in sorted(ts.meta.keys()) if x not in ['name', 'label']]: for k in [x for x in sorted(ts.meta.keys()) if x not in ['name', 'label']]:
print k+':', ts.meta[k] print(k+':', ts.meta[k])
print print()
else: else:
if args.trange: if args.trange:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment