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