Commit 9706dd154119fcb622b0106875d83cc4c38ba23d
Committed by
GitHub
1 parent
7ba967f278
Exists in
master
Add files via upload
Showing 1 changed file with 95 additions and 0 deletions Inline Diff
allanplot.py
File was created | 1 | #!/usr/bin/env python | ||
2 | ||||
3 | import argparse, allantools, numpy, csv, glob, Gnuplot | |||
4 | ||||
5 | #============================================================================== | |||
6 | ||||
7 | # Default filename | |||
8 | FILENAME = '*.dat' | |||
9 | COLUMNS = [2] | |||
10 | RATE = 1 | |||
11 | ||||
12 | #============================================================================== | |||
13 | ||||
14 | def parse(): | |||
15 | """ | |||
16 | Specific parsing procedure for Allan Deviation plotting tool. | |||
17 | :returns: populated namespace (parser) | |||
18 | """ | |||
19 | parser = argparse.ArgumentParser(description = 'Plot Allan Deviation from timeseries file', | |||
20 | epilog = 'Example: \'./allanplot.py -f toto.dat\' compute and plot Allan Deviation form toto.dat values') | |||
21 | ||||
22 | parser.add_argument('-f', | |||
23 | action='store', | |||
24 | dest='filename', | |||
25 | default=FILENAME, | |||
26 | help='File(s) to import (default '+FILENAME+')') | |||
27 | ||||
28 | parser.add_argument('-c', | |||
29 | nargs = '+', | |||
30 | action='store', | |||
31 | dest='columns', | |||
32 | default=COLUMNS, | |||
33 | help='Columns to import (default '+str(COLUMNS)+')') | |||
34 | ||||
35 | parser.add_argument('-r', | |||
36 | action='store', | |||
37 | dest='rate', | |||
38 | default=RATE, | |||
39 | help='Time rate in seconds (default '+str(RATE)+')') | |||
40 | ||||
41 | args = parser.parse_args() | |||
42 | return args | |||
43 | ||||
44 | #============================================================================== | |||
45 | ||||
46 | def main(): | |||
47 | """ | |||
48 | Main script | |||
49 | """ | |||
50 | # Parse command line | |||
51 | args = parse() | |||
52 | # filename | |||
53 | filename = args.filename | |||
54 | # columns | |||
55 | columns = args.columns | |||
56 | # rate | |||
57 | rate = int(args.rate) | |||
58 | ||||
59 | try: | |||
60 | list_files = [] | |||
61 | filename = filename.split() | |||
62 | for name in filename: | |||
63 | list_files.extend(sorted(glob.glob(name))) | |||
64 | ||||
65 | data = [] | |||
66 | ||||
67 | for f in list_files: | |||
68 | with open(f, 'r') as dest_f: | |||
69 | data_iter = csv.reader(dest_f, delimiter = '\t', quotechar = '"') | |||
70 | temp_data = [value for value in data_iter] | |||
71 | data.extend(temp_data) | |||
72 | ||||
73 | data = numpy.asarray(data, dtype = float) | |||
74 |