Blame view

allanplot.py 2.75 KB
9706dd154   mer0m   Add files via upload
1
  #!/usr/bin/env python
677c5d1d0   bmarechal   resolve some bugs
2
3
  import argparse, allantools, numpy, csv, glob, Gnuplot, fnmatch, os
  import matplotlib.pyplot as plt
9706dd154   mer0m   Add files via upload
4
5
6
7
8
  
  #==============================================================================
  
  # Default filename
  FILENAME = '*.dat'
3c94f78ab   bmarechal   -
9
  COLUMNS = '2'
9706dd154   mer0m   Add files via upload
10
11
12
13
14
  RATE = 1
  
  #==============================================================================
  
  def parse():
87cea8f7e   bmarechal   replace 4 spaces ...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  	"""
  	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\' -c 2 3\' compute and plot Allan Deviation form columns 2 and 3 of toto.dat')
  
  	parser.add_argument('-f',
  						action='store',
  						dest='filename',
  						default=FILENAME,
  						help='File(s) to import (default '+FILENAME+')')
  
  	parser.add_argument('-c',
  						nargs = '+',
  						action='store',
  						dest='columns',
  						default=COLUMNS,
  						help='Columns to import (default '+str(COLUMNS)+')')
  
  	parser.add_argument('-r',
  						action='store',
  						dest='rate',
  						default=RATE,
  						help='Time rate in seconds (default '+str(RATE)+')')
  
  	parser.add_argument('-R',
  						action='store_true',
  						dest='rel',
  						default=False,
  						help='Relative ADev')
  
  	args = parser.parse_args()
  	return args
9706dd154   mer0m   Add files via upload
49
50
51
52
  
  #==============================================================================
  
  def main():
87cea8f7e   bmarechal   replace 4 spaces ...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  	"""
  	Main script
  	"""
  	# Parse command line
  	args = parse()
  	# filename
  	filename = args.filename
  	# columns
  	columns = map(int, args.columns)
  	# rate
  	rate = int(args.rate)
  	# rel
  	rel = bool(args.rel)
  
  	try:
  		list_files = []
  		filename = filename.split()
  		for name in filename:
  			list_files.extend(sorted(glob.glob(name)))
  
  		for name in list_files:
  			print(name)
  		data = []
  
  		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)
  
  		data = numpy.asarray(data, dtype = float)
  
  		del(temp_data, list_files, value, f)
  
  		g = Gnuplot.Gnuplot(persist = 1)
  		g('set logscale x')
  		g('set logscale y')
  		g('set grid')
  		g('set format y "%0.1e"')
  		g.xlabel('Tau (s)')
  		g.ylabel('Adev')
  
  		for i in columns:
  			if rel:
  				(tau2, ad, ade, adn) = allantools.adev(data[:,i]/data[:,i].mean(), rate=rate, data_type="freq", taus='decade')
  			else:
  				(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))))
  
  	except Exception as ex:
  			print 'Oups '+str(ex)
  	print 'Program ending
  '
9706dd154   mer0m   Add files via upload
106
107
108
109
  
  #==============================================================================
  
  if __name__ == "__main__":
87cea8f7e   bmarechal   replace 4 spaces ...
110
  	main()