forked from huletlab/apparatus3-seq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
physics.py
executable file
·1310 lines (1005 loc) · 45.6 KB
/
physics.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
import numpy.ma as ma
from scipy.interpolate import interp1d, UnivariateSpline
import argparse
import glob
import os
import pprint
if os.name == 'posix':
lab = '/lab/'
else:
lab = 'L:/'
import sys
sys.path.append(lab + 'software/apparatus3/seq')
sys.path.append(lab + 'software/apparatus3/seq/utilspy')
physpath = lab + 'software/apparatus3/seq/physics/'
import pwlinterpolate, errormsg
import seqconf, gen
channel_list = [
'odtfcpow', \
'odtdepth(1uK)', \
'odtdepth(Er)', \
'odtdepth(100uK)', \
'odtfreqAx(100Hz)', \
'odtfreqRd(100Hz)', \
'odtfreqRdZ(100Hz)', \
'bfield(Amp)', \
'bfield(G)', \
'hfimg0(100MHz)', \
'analoghfimg(100MHz)', \
'bfield(100G)', \
'ainns(100a0)', \
'arice(100a0)', \
'ajochim(100a0)', \
'greenpow1(Er)',\
'greenpow2(Er)',\
'greenpow3(Er)',\
'ir1pow(Er)',\
'ir2pow(Er)',\
'ir3pow(Er)',\
'greenpow1(100mW)',\
'greenpow2(100mW)',\
'greenpow3(100mW)',\
'ir1pow(100mW)',\
'ir2pow(100mW)',\
'ir3pow(100mW)',\
'lcr1(alpha)',\
'lcr2(alpha)',\
'lcr3(alpha)',\
'lattice1V0(Er)',\
'lattice2V0(Er)',\
'lattice3V0(Er)',\
'lattice1freq(100kHz)',\
'lattice2freq(100kHz)',\
'lattice3freq(100kHz)',\
'lattice1V0(Er)',\
'lattice2V0(Er)',\
'lattice3V0(Er)',\
'lattice1freq_radial(kHz)',\
'lattice2freq_radial(kHz)',\
'lattice3freq_radial(kHz)',\
'gr1freq_radial(kHz)',\
'gr2freq_radial(kHz)',\
'gr3freq_radial(kHz)',\
'beam1freq_radial(kHz)',\
'beam2freq_radial(kHz)',\
'beam3freq_radial(kHz)',\
't1(Er)',\
't2(Er)',\
't3(Er)',\
't1(kHz)',\
't2(kHz)',\
't3(kHz)',\
'wannierF1(Er/a)',\
'wannierF2(Er/a)',\
'wannierF3(Er/a)',\
'U1(Er)',\
'U2(Er)',\
'U3(Er)',\
'U1(kHz)',\
'U2(kHz)',\
'U3(kHz)',\
]
#
#IR and GR photodiode calibrations
#
## Historically used beam waists.
# May 17, 2013
# New values for IR waists
# wIR1 = 46.6
# wIR2 = 47.2
# wIR3 = 43.6
# May 02, 2013
# IR obtained from lattice depth measurements
# GR obtained from anticonfiment freq measurements
# wIR1 = 44.9
# wIR2 = 51.9
# wIR3 = 43.9
# Retro factor used on the IR is 0.86
#
# wGR1 = 37.2
# wGR2 = 42.6
# wGR3 = 37.2
#
# Up to May 02, 2013
# w01 = 40.6
# w02 = 40.7
# w03 = 41.5
# Up to Jun 11, 2013
# w01 = 46.6
# w02 = 47.2
# w03 = 43.6
# wGR1 = 43.6
##Lattice Raidla Freqeuncy Calibrations##
## f^2 (kHz^2) = m * IRPower(mW) + offset
lattice_radial_f_m={}
lattice_radial_f_m["ir1"]= 1.0/274.6
lattice_radial_f_m["ir2"]= 1.0/239.2
lattice_radial_f_m["ir3"]= 1.0/160.7
lattice_radial_f_offset={}
lattice_radial_f_offset["ir1"]= -0.13
lattice_radial_f_offset["ir2"]= -0.21
lattice_radial_f_offset["ir3"]= -0.35
##Gr Raidla Freqeuncy Calibrations##
## delta f^2 (kHz^2) = m * GrPower(mW)
gr_radial_f_m={}
gr_radial_f_m["gr1"]= -1.0/607.1
gr_radial_f_m["gr2"]= -1.0/528.9
gr_radial_f_m["gr3"]= -1.0/480.3
#beam waist
w0d = {}
w0d['ir1pow'] = 47.3 / (0.86**0.25) # was 50.2
w0d['ir2pow'] = 47.1 / (0.86**0.25) # was 47.8
w0d['ir3pow'] = 43.7 / (0.86**0.25) # was 43.9
w0d['greenpow1'] = 42.9#43.8 # was 43.4
w0d['greenpow2'] = 41.4#40.8 # was 42.8
w0d['greenpow3'] = 40.4#39.2 # was 41.8
#PD slopes
# Slopes for IR PD's are from Ernie's calibration plus
# empirical correction factor from the points we collected
# when measuring lattice frequencies.
m1d = {}
m1d['ir1pow'] = 4.27e-3#4.38e-3
m1d['ir2pow'] = 5.07e-3#5.14e-3
m1d['ir3pow'] = 5.02e-3#5.23e-3
m1d['greenpow1'] = 5.85e-3#6.09e-3
m1d['greenpow2'] = 4.58e-3#4.86e-3
m1d['greenpow3'] = 4.91e-3#4.91e-3
#PD offset
V0d = {}
V0d['ir1pow'] = 1.35e-2#2.87e-2
V0d['ir2pow'] = 8.29e-3#2.40e-2
V0d['ir3pow'] = -1.7e-3#-1.59e-3
V0d['greenpow1'] = 3.18e-2#5.08e-3
V0d['greenpow2'] = 3.19e-2#1.84e-2
V0d['greenpow3'] = 1.52e-2#1.52e-2
#Er max
ErMaxd = {}
ErMaxd['ir1pow'] = 88.0
ErMaxd['ir2pow'] = 88.0
ErMaxd['ir3pow'] = 100.0
ErMaxd['greenpow1'] = 8.3
ErMaxd['greenpow2'] = 10.5
ErMaxd['greenpow3'] = 32.0
#V max
VMaxd = {}
VMaxd['ir1pow'] = 8.56
VMaxd['ir2pow'] = 10.0
VMaxd['ir3pow'] = 10.0
VMaxd['greenpow1'] = 3.12
VMaxd['greenpow2'] = 3.18
VMaxd['greenpow3'] = 10.0
#V min Servo
VMinServod = {}
VMinServod['ir1pow'] = 0.022 + 0.005
VMinServod['ir2pow'] = 0.019 + 0.005
VMinServod['ir3pow'] = 0.035 + 0.005
VMinServod['greenpow1'] = 0.014 + 0.010
VMinServod['greenpow2'] = 0.017 + 0.005
VMinServod['greenpow3'] = 0.01 + 0.005
try:
ODT = gen.getsection('ODT')
ODTCALIB = gen.getsection('ODTCALIB')
if ODT.use_servo == 0:
b = ODTCALIB.b_nonservo
m1 = ODTCALIB.m1_nonservo
m2 = ODTCALIB.m2_nonservo
m3 = ODTCALIB.m3_nonservo
kink1 = ODTCALIB.kink1_nonservo
kink2 = ODTCALIB.kink2_nonservo
elif ODT.use_servo == 1:
b = ODTCALIB.b
m1 = ODTCALIB.m1
m2 = ODTCALIB.m2
m3 = 0.
kink1 = ODTCALIB.kink
kink2 = 11.
except:
print
print "Could not setup odtpow calibration parameters."
print "Possibly because the report is not loaded."
print "If you are running this module as standalone"
print "the odtpow calibration params will be loaded"
print "from params.INI"
print
from configobj import ConfigObj
report=ConfigObj( lab + 'software/apparatus3/log/params/params.INI' )
#print report
b=float(report['ODTCALIB']['b'])
m1=float(report['ODTCALIB']['m1'])
m2=float(report['ODTCALIB']['m2'])
m3=0.001
kink1=float(report['ODTCALIB']['kink'])
kink2=11
class odtpow_ch:
def __init__(self):
self.GT10warning = True
self.LT0warning = True
def cnvcalib(self, phys):
# odt phys to volt conversion
# max odt power = 10.0
volt = b+m1*kink1 + m2*(kink2-kink1) + m3*(phys-kink2) if phys > kink2 else \
b+m1*kink1 + m2*(phys-kink1) if phys > kink1 else b+m1*phys
if volt >10:
volt=10.
if self.GT10warning==False:
errormsg.box('OdtpowConvert','Odtpow conversion has resulted in a value greater than 10 Volts!'\
+' \n\nResult will be coerced and this warning will not be shown again')
self.GT10warning=True
if volt <0.:
volt=0.
if self.LT0warning==False:
errormsg.box('OdtpowConvert','Odtpow conversion has resulted in a value less than 0 Volts!' \
+ '\n\nResult will be coerced and this warning will not be shown again')
self.LT0warning=True
return volt
def invcalib(self, volt):
phys=(volt-b-m1*kink1-m2*(kink2-kink1))/m3+kink2 if volt> b+m1*kink1+m2*(kink2-kink1) \
else (volt-b-m1*kink1)/m2+kink1 if volt > b+m1*kink1 \
else (volt-b)/m1
if phys > 11.:
phys = 11.
if phys < 0.:
phys = 0.
return phys
def f( self, p ): return p
def g( self, p ): return p
def physlims(self):
return np.array([0., 11.0] )
def voltlims(self):
return np.array([0., 10.0] )
class lattice_ch:
def __init__(self, name, w0, m, V0, ErMax, Vmax, VminServo):
self.name = name
self.w0 = w0
self.m = m
self.V0 = V0
self.ErMax = ErMax
self.Vmax = Vmax
self.VminServo = VminServo
### CALIB : power in mW
### FS : PD voltag
def cnvcalib( self, val ):
if 'ir' in self.name:
return 1000. * val / 4. / 38709. * 1.4 * self.w0 * self.w0
if 'gr' in self.name:
return 1000. * val / 1. / 39461. * 1.4 * self.w0 * self.w0
def invcalib( self, val ):
if 'ir' in self.name:
return val / 1000. * 4. * 38709. / 1.4 / self.w0 / self.w0
if 'gr' in self.name:
return val / 1000. * 1. * 39461. / 1.4 / self.w0 / self.w0
def f(self, p):
Vout = self.m * p + self.V0
Vout = np.clip( Vout, self.VminServo, 11. )
return Vout
def g(self, p):
return (p-self.V0)/self.m
def physlims(self):
return np.array([0, self.ErMax] )
def voltlims(self):
return np.array([-0.01, self.Vmax] )
class gradient_ch:
def __init__(self, name, m, V0):
self.name = name
self.m = m
self.V0 = V0
### CALIB : Voltage
def cnvcalib( self, val ):
#~ print val
cnved = self.m*val + self.V0
#~ print cnved
return cnved if cnved >0. else 0.
def invcalib( self, val ):
return (val -self.V0)*1.0/self.m
def f(self, p):
return p
def g(self, p):
return p
def physlims(self):
#return np.array([self. invcalib(0), self. invcalib(10)] )
return np.array([0., self. invcalib(10)] )
def voltlims(self):
return np.array([0., 10] )
#
#Class for making physical to voltage conversions
#
class convert:
def cnv(self, ch, val,errorshow = 1):
if ch not in self.fs.keys():
print "Channels with defined conversions: "
pprint.pprint(self.fs.keys())
if errorshow:
errormsg.box('CONVERSION : ' + ch, 'No conversion defined for this channel')
raise ValueError("No conversion has been defined for channel = %s" % ch )
return None
out = self.fs[ch]( self.cnvcalib[ch]( val) )
return self.check( ch, val, out)[0]
def inv(self, ch, val,errorshow = 1):
if ch not in self.fs.keys():
print "Channels with defined conversions: "
pprint.pprint(self.fs.keys())
if errorshow:
errormsg.box('CONVERSION : ' + ch, 'No conversion defined for this channel')
raise ValueError("No conversion has been defined for channel = %s" % ch )
return None
out = self.invcalib[ch]( self.gs[ch]( val) )
return self.check( ch, out, val)[1]
def __init__(self):
### This dictionaries define the functions used for conversion
self.fs={}
self.gs={}
self.cnvcalib={}
self.invcalib={}
self.physlims={}
self.voltlims={}
### The for loop below takes care of all the channels that
### are associated with a calibration file
dats = glob.glob(lab + 'software/apparatus3/convert/data/*.dat')
for d in dats:
table = np.loadtxt(d, usecols = (1,0))
ydat = table[:,1] # voltages
xdat = table[:,0] # calibrated quantity
ch = os.path.splitext( os.path.split(d)[1] )[0]
try:
f = pwlinterpolate.interp1d( xdat, ydat , name = ch)
g = pwlinterpolate.interp1d( ydat, xdat , name = ch)
except ValueError as e:
print e
print "Could not define piecewiwse linear nterpolation function for : \n\t%s" % d
exit(1)
self.fs[ch] = f
self.gs[ch] = g
if ch == 'trapdet':
### IN : MHz detuning at atoms
### CALIB : Double-pass AOM frequency
shift = -1.1
self.cnvcalib[ch] = lambda val: (val+shift+120.+120.)/2.
self.invcalib[ch] = lambda val: 2*val -shift -120 - 120.
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([2.0, 8.0])
elif ch == 'repdet':
### IN : MHz detuning at atoms
### CALIB : Double-pass AOM frequency
shift = -1.1
self.cnvcalib[ch] = lambda val: (val+shift+228.2 -80.0 + 120.)/2.
self.invcalib[ch] = lambda val: 2*val -shift -228.2 + 80.0 - 120.
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([2.0, 8.0])
elif ch == 'motpow':
### IN : Isat/beam at atoms
### CALIB : Power measured by MOT TA monitor
w0 = 0.86 # beam waist
ta = 1.682 # power lost to TA sidebands
op = 1.37 # power loss in MOT optics
self.cnvcalib[ch] = lambda val: op*ta*6*val*5.1*(3.14*w0*w0)/2.
self.invcalib[ch] = lambda val: 2*val/op/ta/6/5.1/(3.14*w0*w0)
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0.1, 10.])
elif ch == 'trappow' or ch == 'reppow':
### IN : power injected to TA
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 10.])
elif ch == 'bfield':
### IN : current measured on power supply
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 9.0])
elif ch == 'uvdet':
### IN : UV detuning in MHz
### CALIB : Double-pass AOM frequency
self.cnvcalib[ch] = lambda val: (val + 130.17)/2.0
self.invcalib[ch] = lambda val: val*2.0 - 130.17
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([2.744, 4.744])
elif ch == 'uvpow':
### IN : power measured after 75 um pinhole
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 7.0])
elif ch == 'uv1freq':
### IN : Frequency of uvaom1 in MHz
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 10.0])
elif ch == 'analogimg':
### IN : Frequency of offset lock beat signal MHz
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 10.0])
elif ch == 'lcr1' or ch == 'lcr2' or ch == 'lcr3':
### IN : Lattice ratio: 1=lattice 0=dimple
### CALIB : same as IN
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
self.voltlims[ch] = np.array([0., 10.0])
else:
self.cnvcalib[ch] = lambda val:val
self.invcalib[ch] = lambda val:val
self.physlims[ch] = None
self.voltlims[ch] = None
### Channels that are NOT associated with calibration files are
### defined below
chs = ['uvpow2', 'ipganalog', 'rfmod']
for ch in chs:
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.fs[ch] = lambda x: x
self.gs[ch] = lambda x: x
self.physlims[ch] = np.array([0., 10.])
self.voltlims[ch] = np.array([0., 10.])
latticechs = ['ir1pow', 'ir2pow', 'ir3pow','greenpow1', 'greenpow2', 'greenpow3' ]
for ch in latticechs:
### CALIB : power in mW
### FS : PD voltag
l = lattice_ch( ch, w0d[ch], m1d[ch], V0d[ch], ErMaxd[ch], VMaxd[ch], VMinServod[ch])
self.cnvcalib[ch] = l.cnvcalib
self.fs[ch] = l.f
self.invcalib[ch] = l.invcalib
self.gs[ch] = l.g
self.physlims[ch] = l.physlims()
self.voltlims[ch] = l.voltlims()
### ODTPOW
o = odtpow_ch()
ch = 'odtpow'
self.cnvcalib[ch] = np.vectorize(o.cnvcalib)
self.fs[ch] = o.f
self.invcalib[ch] = np.vectorize(o.invcalib)
self.gs[ch] = o.g
self.physlims[ch] = o.physlims()
self.voltlims[ch] = o.voltlims()
###Gradient field gradientfield
### Gradient
gradientslope = 0.0971
gradientoffset = -2.7232
ch = 'gradientfield'
gradientfield = gradient_ch(ch,gradientslope,gradientoffset )
self.cnvcalib[ch] = np.vectorize(gradientfield.cnvcalib)
self.fs[ch] = gradientfield.f
self.invcalib[ch] = np.vectorize(gradientfield.invcalib)
self.gs[ch] = gradientfield.g
self.physlims[ch] = gradientfield.physlims()
self.voltlims[ch] = gradientfield.voltlims()
### TUNNELING / WANNIERFACTOR to LATTICE DEPTH
tANDu = ['t_to_V0','wF_to_V0']
for ch in tANDu:
### CALIB : unity
### FS : interpolation
if 't_' in ch:
table = np.loadtxt(physpath+'tANDU.dat', usecols = (1,0))
elif 'wF_' in ch:
table = np.loadtxt(physpath+'tANDU.dat', usecols = (2,0))
else:
msg = 'ERROR initializing physics.py conversion ch = %s' % ch
errormsg.box('PHYSICS.PY', msg)
exit(1)
ydat = table[:,1] # lattice depths
xdat = table[:,0] # tunneling / wFactor
try:
f = pwlinterpolate.interp1d( xdat, ydat , name = ch)
g = pwlinterpolate.interp1d( ydat, xdat , name = ch)
except ValueError as e:
print e
print "Could not define piecewiwse linear nterpolation function for : \n\t%s" % d
exit(1)
self.fs[ch] = f
self.gs[ch] = g
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = self.invcalib[ch]( np.array( [ np.amin(xdat), np.amax(xdat) ] ) )
# Max Er for t, U calculation
maxEr = 81.
self.voltlims[ch] = np.array([0., maxEr])
### SCATTERING LENGTH to BFIELD
ch = 'as_to_B'
### CALIB : unity
### FS : interpolation
#Use latest data from Jochim group
table = np.loadtxt(physpath+'ajochim_truncated.dat', usecols = (1,0))
ydat = table[:,1] # bfield (Gauss)
xdat = table[:,0] # scattering length (a0)
try:
f = pwlinterpolate.interp1d( xdat, ydat , name = ch)
g = pwlinterpolate.interp1d( ydat, xdat , name = ch)
except ValueError as e:
print e
print "Could not define piecewiwse linear nterpolation function for : \n\t%s" % d
exit(1)
self.fs[ch] = f
self.gs[ch] = g
self.cnvcalib[ch] = lambda val: val
self.invcalib[ch] = lambda val: val
self.physlims[ch] = np.array( [ np.amin(xdat), np.amax(xdat) ] )
self.voltlims[ch] = np.array( [ np.amin(ydat), np.amax(ydat) ] )
def plotcnv( self, ch ):
import matplotlib.pyplot as plt
print "-------- %s --------" % ch
print "physical limits = ", self.physlims[ch]
print "voltage limits = ", self.voltlims[ch]
physvals = np.linspace( self.physlims[ch][0] , self.physlims[ch][1] , 40 )
plt.plot( self.cnv(ch,physvals), physvals, '--', lw=2)
plt.legend([ch+'_cnv'], loc='best')
plt.grid()
plt.show()
def plotcnvinv( self, ch ):
import matplotlib.pyplot as plt
print "-------- %s --------" % ch
print "physical limits = ", self.physlims[ch]
print "voltage limits = ", self.voltlims[ch]
voltvals = np.linspace( self.voltlims[ch][0] , self.voltlims[ch][1] , 40 )
physvals = np.linspace( self.physlims[ch][0] , self.physlims[ch][1] , 40 )
#~ try:
plt.plot( self.cnv(ch,physvals), physvals, '--', lw=2)
plt.plot( voltvals, self.inv(ch,voltvals), '-')
#~ except ValueError as e:
#~ print "Error in producing conversion plot for ch = %s" % ch
#~ print "voltvals = ", voltvals
#~ print "physvals = ", physvals
#~ print xdat
#~ print e
plt.legend([ch+'_cnv', ch+'_inv'], loc='best')
plt.grid()
plt.show()
def plot(self):
import matplotlib.pyplot as plt
dats = glob.glob(lab + 'software/apparatus3/convert/data/*.dat')
plotdat = raw_input("Do you wish to plot calibrations in .dat files? (y/n)")
datchs = []
for d in dats:
ch = os.path.splitext( os.path.split(d)[1] )[0]
datchs.append(ch)
table = np.loadtxt(d, usecols = (1,0))
xdat = table[:,0]
ydat = table[:,1]
print "-------- %s --------" % ch
print "physical limits = ", self.physlims[ch]
print "voltage limits = ", self.voltlims[ch]
if plotdat == 'y':
plt.plot( xdat, ydat, 'o')
xvals = np.union1d ( np.linspace( np.amin(xdat), np.amax(xdat) , 20 ), xdat )
try:
plt.plot( xvals, self.fs[ch](xvals), '-')
except ValueError as e:
print "Error in producing interpolation data plot for ch = %s" % ch
print xvals
print xdat
print e
plt.legend([ch,'interpolation'], loc='best')
plt.show()
plotdat = raw_input("Do you wish to plot conversions for channels NOT in .dat files? (y/n)")
print "\nThe following channels are available:"
available = []
for ch in self.fs.keys():
if ch not in datchs and ( 'ir' in ch or 'gr' in ch or 'odt' in ch or 'V0' in ch or 'ajochim' in ch):
available.append(ch)
pprint.pprint( available )
for ch in self.fs.keys():
if ch not in datchs and ( 'ir' in ch or 'gr' in ch or 'odt' in ch or 'V0' in ch or 'ajochim' in ch):
if plotdat == 'y':
plotcnvinv( ch)
else:
print "-------- %s --------" % ch
print "physical limits = ", self.physlims[ch]
print "voltage limits = ", self.voltlims[ch]
def check( self, ch , phys, volt ):
physa = np.asarray(phys)
volta = np.asarray(volt)
#Give a little room for rounding errors
#and some wiggle room for the physical limits
physMin = self.physlims[ch][0] - 0.000001
physMax = self.physlims[ch][1] + 0.000001
physMin = physMin - (physMax-physMin)*0.015
physMax = physMax + (physMax-physMin)*0.015
voltMin = self.voltlims[ch][0] - 0.000001
voltMax = self.voltlims[ch][1] + 0.000001
#print type(val)
#print type(out)
below_bound_phys = physa < physMin
above_bound_phys = physa > physMax
below_bound_volt = volta < voltMin
above_bound_volt = volta > voltMax
if below_bound_phys.any() or above_bound_phys.any():
print "phys =", physa
print "physMin,PhysMax =",physMin,physMax
out_of_bounds_phys = None
print "Error in conversion of %s with length = %d" % ( type(physa), len(physa) )
msg = "Physical limits [%f,%f]\n" % (physMin, physMax)
msg += "The following values are outside the physical limits:"
if physa.ndim < 1:
out_of_bounds_phys = physa
msg = msg + '\n\t' + str(out_of_bounds_phys)
else:
out_of_bounds_phys = np.concatenate( (physa[ np.where( physa < physMin ) ],physa[np.where( physa > physMax)] ))
msg = msg + '\n\t' + str(out_of_bounds_phys)
print msg
errormsg.box('CONVERSION CHECK:: ' + ch, msg)
raise ValueError("A value is outside the physics range. ch = %s" % ch)
if below_bound_volt.any() or above_bound_volt.any():
out_of_bounds_volt = None
msg = "Voltage limits [%f,%f]\n" % (voltMin, voltMax)
msg += "The following values are outside the voltage limits:"
if volta.ndim < 1:
out_of_bounds_volt = volta
msg = msg + '\n\t' + str(out_of_bounds_volt)
else:
out_of_bounds_volt = np.concatenate( (volta[ np.where( volta < voltMin ) ], volta[np.where( volta > voltMax)]))
msg = msg + '\n\t' + str(out_of_bounds_volt)
print msg
errormsg.box('CONVERSION CHECK :: ' + ch, msg)
raise ValueError("A value is outside the voltage range. ch = %s" % ch)
return (volt, phys)
dll = convert();
def cnv( ch, val ):
global dll
return dll.cnv(ch, val)
def inv( ch, val ):
global dll
return dll.inv(ch, val)
#
#General operations for physical data calculations
#
def interpdat( datfile, x, y, dat):
table = np.loadtxt( datfile, usecols = (x,y))
if 'ajochim.dat' in datfile:
print "Inside interpolation routine."
try:
f = interp1d( table[:,0], table[:,1], kind='cubic')
except ValueError as e:
print e
print "Could not define interpolation function"
f = lambda x: x
if 'ajochim.dat' in datfile:
print "Succesfully defined interpolation function."
try:
out = f(dat[:,1])
except ValueError as e:
out = dat[:,1]
print "Error when trying to interpolate from:"
print "\t",datfile
print "\tTable range is (%f,%f)" % (np.amin(table[:,0]), np.amax(table[:,0]) )
print "\tData xrange is (%f,%f)" % (np.amin(dat[:,1]), np.amax(dat[:,1]))
print dat
return (dat[:,0], out)
def scaleFactor( dat, scale ):
"""Takes some calculate data and scales the Y array"""
return (dat[0], dat[1]*scale)
#Run standalone to test interpolation of a table file
if __name__ == '__main__':
#dll.plot()
#exit(0)
parser = argparse.ArgumentParser('physics.py')
parser.add_argument('channel',action="store",type=str, help='Channel to convert')
parser.add_argument('value',action="store",type=float, help='value to convert')
#~ parser.add_argument('datfile',action="store",type=str, help='datfile to plot')
#~ parser.add_argument('xcol',action="store",type=int, help='x column index')
#~ parser.add_argument('ycol',action="store",type=int, help='y column index')
#~ parser.add_argument('--cnv',action="store",type=bool, help='plot cnv interpolations')
args=parser.parse_args()
if 'Phys' in args.channel:
ch = args.channel.split('Phys')[0]
print "converted value =",dll.inv(ch,args.value)
else:
print "converted value =",dll.cnv(args.channel,args.value)
#~ dat = np.loadtxt( args.datfile, usecols = (args.xcol,args.ycol))
#~ xdat = dat[:,0]
#~ ydat = dat[:,1]
#~ stackdat = np.transpose(np.vstack( (xdat,xdat) ))
#~ itpd = interpdat( args.datfile, args.xcol, args.ycol, stackdat)
#~ plt.plot( xdat, ydat, 'o', itpd[0], itpd[1], '-')
#~ plt.legend(['data','cubic'], loc='best')
#~ plt.show()
#
#Class for calculating quantities
#
class calc:
def __init__(self, wfms ):
self.wfms = wfms
self.calcwfms = {}
self.ch_list = channel_list
def basicConversion( self, datfile, colX, colY, ch):
"""A basic channel can be converted via a single dat file"""
dat = self.wfms[ch]
dat = [out[0] for out in dat]
dat = np.concatenate( dat, axis=0)
return interpdat( datfile, colX, colY, dat)
def cnvInversion( self, ch):
"""A basic channel can be converted by using its inverse conversion function"""
dat = self.wfms[ch]
dat = [out[0] for out in dat]
dat = np.concatenate( dat, axis=0)
return (dat[:,0], dll.inv( ch, dat[:,1]))
def interpch( self, datfile, x, y, ch):
return interpdat(datfile, x, y, np.transpose(np.vstack(self.calcwfms[ch])) )
def prereq( self, ch ):
if ch not in self.calcwfms.keys():
print "\tcalculating prerequisite: %s" % ch
self.calculate(ch)
else:
print "\treusing prerequisite: %s" % ch
def calculate(self, ch):
if ch in self.calcwfms.keys():
print"\talready in dictionary"
return self.calcwfms[ch]
### Calculate trap depth and frequencies
elif ch == 'odtfcpow':
"""The table for the conversion from voltage to cpow is calculated
using the odt.py module, inside the seq directory. Type python odt.py
The table is saved in physics/odtfcpow.dat"""
#self.calcwfms[ch] = self.basicConversion(physpath+'odtfcpow.dat', 0, 1, 'odtpow')
self.calcwfms[ch] = self.cnvInversion( 'odtpow')
return self.calcwfms[ch]
elif ch == 'odtdepth(1uK)':
self.prereq('odtfcpow')
self.calcwfms[ch] = self.interpch(physpath+'odt.dat', 0, 1, 'odtfcpow')
return self.calcwfms[ch]
elif ch == 'odtdepth(Er)':
self.prereq('odtdepth(1uK)')
self.calcwfms[ch] = scaleFactor( self.calcwfms['odtdepth(1uK)'], 1/1.4)
return self.calcwfms[ch]
elif ch == 'odtdepth(100uK)':
self.prereq('odtfcpow')
self.calcwfms[ch] = scaleFactor(self.interpch(physpath+'odt.dat', 0, 1, 'odtfcpow'), 1/100.)
return self.calcwfms[ch]
elif ch == 'odtdepth(Er)':
self.prereq('odtfcpow')
self.calcwfms[ch] = scaleFactor(self.interpch(physpath+'odt.dat', 0, 1, 'odtfcpow'), 1/1.4)
return self.calcwfms[ch]
elif ch == 'odtfreqAx(100Hz)':
self.prereq('odtfcpow')
self.calcwfms[ch] = scaleFactor(self.interpch(physpath+'odt.dat', 0, 2, 'odtfcpow'), 1/100.)
return self.calcwfms[ch]
elif ch == 'odtfreqRd(100Hz)':
self.prereq('odtfcpow')
self.calcwfms[ch] = scaleFactor(self.interpch(physpath+'odt.dat', 0, 3, 'odtfcpow'), 1/100.)
return self.calcwfms[ch]
elif ch == 'odtfreqRdZ(100Hz)':
self.prereq('odtfcpow')
self.calcwfms[ch] = scaleFactor(self.interpch(physpath+'odt.dat', 0, 4, 'odtfcpow'), 1/100.)
return self.calcwfms[ch]
### Calculate Bfield
elif ch == 'bfield(Amp)':
#self.calcwfms[ch] = self.basicConversion(physpath+'bfield.dat', 0, 1, 'bfield')
self.calcwfms[ch] = self.cnvInversion('bfield')
return self.calcwfms[ch]
elif ch == 'bfield(G)':
self.prereq('bfield(Amp)')
self.calcwfms[ch] = scaleFactor( self.calcwfms['bfield(Amp)'], 6.8 )
return self.calcwfms[ch]
elif ch == 'bfield(100G)':
self.prereq('bfield(G)')
self.calcwfms[ch] = scaleFactor( self.calcwfms['bfield(G)'], 1/100.)
return self.calcwfms[ch]