Versioning started.
[pycomedi.git] / pycomedi / test.py
1 #!/usr/bin/python
2 #
3 # With analog output 0 cabled directly to analog input 0
4 # output a single period of a 1000kHz sine wave
5 # and perform a linear regression between the output and input data.
6 # If the input is closely correlated to the output (gradient > 0.7)
7 # consider the synchronized input/output a success.
8 # Prints the success rate for num_runs
9
10 from scipy.stats import linregress
11 from scipy.io import read_array, write_array
12 from os import system
13 from numpy import zeros
14
15 # I had been checking at different waits between AO arming and AI triggering,
16 # thinking that the problem might be due to my patch.
17 # But I get failure rates of ~ 20% regardless of the wait time (-t option)
18 # So currently only use waits of 0 seconds to get more data.
19
20 def test() :
21     #waits = range(5, -1, -1)
22     waits = [0]
23     
24     num_runs = 200
25     runs  = range(0, num_runs)
26     results = zeros((1, num_runs))
27     good_run_arr = []
28
29     fails = 0
30     successes = 0
31     good_run = 0
32     for wait in waits :
33         for run in runs :
34             call = './simult_aio -n 50 -F 50000 -w 1000 -t%d' % wait
35             if system(call) != 0 :
36                 return 1
37             if system('int16s_to_ascii_array out in > data') != 0 :
38                 return 1
39             data = read_array('data')
40             gradient, intercept, r_value, p_value, std_err = linregress(data)
41             results[wait,run] = gradient
42             print "wait %2d, run %2d, gradient %g" % (wait, run, gradient)
43             if gradient < .7 :
44                 fails += 1
45                 good_run_arr.append(good_run)
46                 good_run = 0
47             else :
48                 successes += 1
49                 good_run += 1
50     print "failure rate ", (float(fails)/float(fails+successes))
51     call = 'echo "'
52     for num in good_run_arr :
53         call += "%d " % num
54     call += '" | stem_leaf 2'
55     print "good runs:"
56     system(call)
57
58 if __name__ == "__main__" :
59     test()