forked from hebecked/PyDAQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockin.py
executable file
·78 lines (60 loc) · 3.56 KB
/
lockin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
49
50
51
52
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
#!/usr/bin/python2.7
import os, sys
from bin.parser_wrapper import parsers
from bin.lockIn import lockin
import os, sys
import numpy as np
import time
import bin.Data_IO as DIO
parser=parsers("This Program is meant as a DAQ for a hardware setup in the Astroparticle group of the Humbolt University of Berlin\nIt is written and maintained by Dustin Hebecker, Mickael Rigault and Daniel Kuesters. (2015)\nFeel free to modify and reuse for non commercial purposes as long as credit is given to the original authors.\n")
#parser.add_argument( "PortReference", "-pr", str, group="LockIn", default=None, help='Used to define the Port for the reference LockIn')
#parser.add_argument( "PortSignal", "-ps", str, group="LockIn", default=None, help='Used to define the Port for the signal LockIn')
parser.add_argument( "Autogain", "-ag", bool, group="LockIn", default=False, help='Defines if autogain will be used.')
parser.add_argument( "AverageValues", "-an", int, group="LockIn", default=10, help='Defines amount of measurements to average over.')
parser.add_argument( "ReadSignalLockIn", "-rsl", bool, group="LockIn", default=False, help='Will print the current value of the signal Lock-In to the comandline.')
parser.add_argument( "ReadReferenceLockIn", "-rrl", bool, group="LockIn", default=False, help='Will print the current value of the reference Lock-In to the comandline.')
parser.add_argument( "ReadPorts", "-rp", bool, group="Ports", default=False, help='Refreshes the device ports.')
arguments=parser.done(store_if_file_supplied=True)
ports=DIO.serialports().get_ports(refresh=arguments['ReadPorts']['val'])
if arguments["ReadSignalLockIn"]['val']:
signal=lockin( port=ports['sLockIn'], avrgn=10, autogain=arguments['Autogain']['val'], timeconstant=0.3)
if arguments["ReadReferenceLockIn"]['val']:
reference=lockin( port=ports['rLockIn'], avrgn=10, autogain=arguments['Autogain']['val'], timeconstant=0.3)
if arguments["ReadSignalLockIn"]['val'] and not arguments["ReadReferenceLockIn"]['val']:
sdata=[signal.StandardData(N=arguments['AverageValues']['val'])] # returns return np.mean(ampl),np.std(ampl),np.mean(phase),np.std(phase),np.mean(freq),np.std(freq)
print 'Amp_mean Amp_err Phase_mean Phase_err Freq_mean Freq_err'
print sdata
if arguments["ReadReferenceLockIn"]['val'] and not arguments["ReadSignalLockIn"]['val']:
rdata=[reference.StandardData(N=arguments['AverageValues']['val'])] # returns return np.mean(ampl),np.std(ampl),np.mean(phase),np.std(phase),np.mean(freq),np.std(freq)
print 'Amp_mean Amp_err Phase_mean Phase_err Freq_mean Freq_err'
print rdata
if arguments["ReadReferenceLockIn"]['val'] and arguments["ReadSignalLockIn"]['val']:
ampls=[]
amplr=[]
phases=[]
phaser=[]
freqs=[]
freqr=[]
for i in range(arguments['AverageValues']['val']):
sampl,sphase,sfreq = signal.StandardData(N=1)
ampls.append(sampl)
phases.append(sphase)
freqs.append(sfreq)
rampl,rphase,rfreq = reference.StandardData(N=1)
amplr.append(rampl)
phaser.append(rphase)
freqr.append(rfreq)
results={}
results.update({'sLockIn':np.mean(ampls)})
results.update({'sLockInErr':np.std(ampls)})
results.update({'sLockInFreq':np.mean(freqs)})
results.update({'sLockInFreqErr':np.std(freqs)})
results.update({'sLockInPhase':np.mean(phases)})
results.update({'sLockInPhaseErr':np.std(phases)})
results.update({'rLockIn':np.mean(amplr)})
results.update({'rLockInErr':np.std(amplr)})
results.update({'rLockInFreq':np.mean(freqr)})
results.update({'rLockInFreqErr':np.std(freqr)})
results.update({'rLockInPhase':np.mean(phaser)})
results.update({'rLockInPhaseErr':np.std(phaser)})
print results