Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate logpps.py @ 72:da3558dec4e3
Fetch large data blocks correctly.
Add ask function.
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Wed, 25 Sep 2024 20:56:39 +0930 |
parents | 6ffa6fcf278e |
children |
rev | line source |
---|---|
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
2 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
3 # Copyright (c) 2021 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
5 # |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
6 # Redistribution and use in source and binary forms, with or without |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
7 # modification, are permitted provided that the following conditions |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
8 # are met: |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
9 # 1. Redistributions of source code must retain the above copyright |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
10 # notice, this list of conditions and the following disclaimer. |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
11 # 2. Redistributions in binary form must reproduce the above copyright |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
12 # notice, this list of conditions and the following disclaimer in the |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
13 # documentation and/or other materials provided with the distribution. |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
14 # |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
25 # SUCH DAMAGE. |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
26 # |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
27 # Expected DB schema |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
28 # CREATE TABLE ppslog ( |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
29 # name TEXT, |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
30 # time TIMESTAMP WITH TIME ZONE, |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
31 # delta12 NUMERIC(15, 12), |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
32 # delta13 NUMERIC(15, 12) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
33 # ); |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
34 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
35 import datetime |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
36 import numpy |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
37 import psycopg2 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
38 #import sqlite3 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
39 import sys |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
40 import time |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
41 # Should try this code instead: https://github.com/python-ivi/python-usbtmc |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
42 import usb488 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
43 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
44 def main(): |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
45 u = usb488.USB488Device() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
46 print('Found device') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
47 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
48 # See "TDS2000 Programmer.pdf" |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
49 res = u.ask('*IDN?') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
50 print('IDN reports ' + res) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
51 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
52 hostname = 'radartest1' |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
53 nchan = 2 |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
54 #dbh = sqlite3.connect('logpps.db') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
55 dbh = psycopg2.connect('host=vm11 user=ppslog dbname=ppslog') |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
56 #dbh = None |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
57 test(u, nchan, dbh, hostname) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
58 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
59 def test(u, nchan, dbh = None, name = None): |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
60 if dbh != None: |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
61 cur = dbh.cursor() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
62 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
63 u.write('ACQ:MODE SAMPLE') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
64 u.write('ACQ:STATE STOP') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
65 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
66 #u.write('DATA:ENC RIB') # Big endian signed |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
67 #u.write('DATA:WIDTH 2') # 2 bytes wide |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
68 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
69 vscales = [] |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
70 for i in range(nchan): |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
71 tmp = float(u.ask('CH%d:SCALE?' % (i + 1)).split()[1]) |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
72 vscales.append(tmp) |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
73 print(('Channel %d scale is %.2f volts/div' % (i + 1, tmp))) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
74 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
75 hscale = float(u.ask('HOR:MAIN:SCALE?').split()[1]) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
76 print(('Horizontal scale is %.5f nsec/div' % (hscale * 1e9))) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
77 # TEK2024B doesn't grok HOR:DIV? so hard code 10 (has 8 vertically) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
78 acqwindow = hscale * 10.0 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
79 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
80 while True: |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
81 arys = acquire(u, vscales) |
70
6ffa6fcf278e
Move pylab import to where graphing is so we don't need an X server
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
69
diff
changeset
|
82 #import matplotlib.pylab as pylab |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
83 #for a in arys: |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
84 # pylab.plot(a) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
85 #pylab.show() |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
86 sampletime = acqwindow / len(arys[0]) |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
87 deltas = [] |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
88 for i in range(nchan - 1): |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
89 delta = getpdiffedge(arys[0], arys[i + 1]) * sampletime |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
90 deltas.append(delta) |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
91 print('Delta 1-%d is %.1f nsec' % (i + 2, delta * 1e9)) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
92 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
93 if dbh != None: |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
94 now = datetime.datetime.now() |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
95 d12 = deltas[0] |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
96 d13 = None |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
97 if nchan > 2: |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
98 d13 = deltas[1] |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
99 cur.execute('INSERT INTO ppslog(name, time, delta12, delta13) VALUES(%s, %s, %s, %s)', (name, now, d12, d13)) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
100 dbh.commit() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
101 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
102 def getchannel(u, ch, vscale): |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
103 u.write('DAT:SOU CH%d' % (ch)) # Set the curve source to desired channel |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
104 result = u.ask('CURVE?', 1.0) # Ask for the curve data |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
105 data1 = buffer(result[13:]) # Chop off the header (should verify this really..) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
106 ary = numpy.frombuffer(data1, dtype = '>h') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
107 ary = ary / 32768.0 * vscale # Scale to volts |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
108 return ary |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
109 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
110 def acquire(u, vscales): |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
111 u.write('ACQ:STATE 1') # Do a single acquisition |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
112 u.write('*OPC?') |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
113 u.read(2.0) # Wait for it to complete |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
114 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
115 arys = [] |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
116 for i in range(len(vscales)): |
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
117 arys.append(getchannel(u, i + 1, vscales[i])) |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
118 |
69
7386f2888508
Make function more configurable
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
62
diff
changeset
|
119 return arys |
62
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
120 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
121 def getpdiffedge(ary1, ary2): |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
122 '''Return phase difference in samples between two signals by edge detection''' |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
123 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
124 # Rescale to 0-1 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
125 ary1 = ary1 - ary1.min() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
126 ary1 = ary1 / ary1.max() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
127 ary2 = ary2 - ary2.min() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
128 ary2 = ary2 / ary2.max() |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
129 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
130 # Find rising edge of each |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
131 ary1pos = numpy.argmax(ary1 > 0.2) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
132 ary2pos = numpy.argmax(ary2 > 0.2) |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
133 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
134 return ary1pos - ary2pos |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
135 |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
136 if __name__ == '__main__': |
ffc9292eb00b
Use edge detection to log time differences between edges
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
137 main() |