Blame view
allanplot.py
2.84 KB
9706dd154 Add files via upload |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/usr/bin/env python import argparse, allantools, numpy, csv, glob, Gnuplot #============================================================================== # Default filename FILENAME = '*.dat' COLUMNS = [2] RATE = 1 #============================================================================== def parse(): """ Specific parsing procedure for Allan Deviation plotting tool. :returns: populated namespace (parser) """ parser = argparse.ArgumentParser(description = 'Plot Allan Deviation from timeseries file', epilog = 'Example: \'./allanplot.py -f toto.dat\' compute and plot Allan Deviation form toto.dat values') parser.add_argument('-f', action='store', dest='filename', default=FILENAME, help='File(s) to import (default '+FILENAME+')') |
d8cd5af60 - |
27 |
|
9706dd154 Add files via upload |
28 29 30 31 32 33 |
parser.add_argument('-c', nargs = '+', action='store', dest='columns', default=COLUMNS, help='Columns to import (default '+str(COLUMNS)+')') |
d8cd5af60 - |
34 |
|
9706dd154 Add files via upload |
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
parser.add_argument('-r', action='store', dest='rate', default=RATE, help='Time rate in seconds (default '+str(RATE)+')') args = parser.parse_args() return args #============================================================================== def main(): """ Main script """ # Parse command line args = parse() # filename filename = args.filename # columns columns = args.columns # rate rate = int(args.rate) try: list_files = [] filename = filename.split() for name in filename: list_files.extend(sorted(glob.glob(name))) |
d8cd5af60 - |
64 |
|
9706dd154 Add files via upload |
65 |
data = [] |
d8cd5af60 - |
66 |
|
9706dd154 Add files via upload |
67 68 69 70 71 |
for f in list_files: with open(f, 'r') as dest_f: data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') temp_data = [value for value in data_iter] data.extend(temp_data) |
d8cd5af60 - |
72 |
|
9706dd154 Add files via upload |
73 |
data = numpy.asarray(data, dtype = float) |
d8cd5af60 - |
74 |
|
9706dd154 Add files via upload |
75 |
del(temp_data, list_files, value, f) |
d8cd5af60 - |
76 77 |
g = Gnuplot.Gnuplot(persist = 1) |
9706dd154 Add files via upload |
78 79 80 |
g('set logscale x') g('set logscale y') g('set grid') |
d8cd5af60 - |
81 |
g('set format y "%0.1e"') |
9706dd154 Add files via upload |
82 83 |
g.xlabel('Tau (s)') g.ylabel('Adev') |
d8cd5af60 - |
84 |
|
9706dd154 Add files via upload |
85 86 87 |
for i in columns: (tau2, ad, ade, adn) = allantools.adev(data[:,i], rate=rate, data_type="freq", taus='decade') g.replot(Gnuplot.Data(tau2, ad, ade, with_='yerrorbars', title='%s : %s'%(name, str(i)))) |
d8cd5af60 - |
88 |
|
9706dd154 Add files via upload |
89 90 91 92 93 94 95 96 97 |
except Exception as ex: print 'Oups '+str(ex) print 'Program ending ' #============================================================================== if __name__ == "__main__": main() |