Commit 3c94f78ab0b2ffb86b406fa5a903f284ff4daed3

Authored by bmarechal
1 parent 677c5d1d06
Exists in master

-

Showing 1 changed file with 2 additions and 2 deletions Inline Diff

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