-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_theta.py
833 lines (706 loc) · 27 KB
/
convert_theta.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
import numpy as N
import pylab
import math
import unittest
from matplotlib.patches import Ellipse
import lattice_calculator
import readncnr2 as readncnr
import scriptutil as SU
import re
import simple_combine
import sys
#sys.path.append(r'c:\tripleaxisproject2\polarization')
sys.path.append(r'c:\mytripleaxisproject\polarization')
import polcorrect_lib
from matplotlib.ticker import NullFormatter, MultipleLocator
from matplotlib.ticker import FormatStrFormatter
from matplotlib.ticker import MaxNLocator
import scipy.sandbox.delaunay as D
#import numpy.core.ma as ma
import matplotlib.numerix.ma as ma
from scipy.signal.signaltools import convolve2d
import readicp
eps=1e-3
pi=N.pi
def autovectorized(f):
"""Function decorator to do vectorization only as necessary.
vectorized functions fail for scalar inputs."""
def wrapper(input):
if N.isscalar(input)==False:
return N.vectorize(f)(input)
return f(input)
return wrapper
@autovectorized
def myradians(x):
return math.radians(x)
def readfiles(mydirectory,myfilebase,myend):
myfilebaseglob=myfilebase+'*.'+myend
print myfilebaseglob
flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
Qx=N.array([])
Qy=N.array([])
Qz=N.array([])
Counts=N.array([])
for currfile in flist:
print currfile
mydata=mydatareader.readbuffer(currfile)
Qx=N.concatenate((Qx,N.array(mydata.data['qx'])))
Qy=N.concatenate((Qy,N.array(mydata.data['qy'])))
Qz=N.concatenate((Qz,N.array(mydata.data['qz'])))
Counts=N.concatenate((Counts,N.array(mydata.data['counts'])))
def plot_nodes(tri):
for nodes in tri.triangle_nodes:
D.fill(x[nodes],y[nodes],'b')
pylab.show()
def plot_data(xa,ya,za,fig,nfig,colorflag=False):
cmap = pylab.cm.jet
cmap.set_bad('w', 1.0)
myfilter=N.array([[0.1,0.2,0.1],[0.2,0.8,0.2],[0.1,0.2,0.1]],'d') /2.0
zout=convolve2d(za,myfilter,mode='same')
zima = ma.masked_where(N.isnan(zout),zout)
ax=fig.add_subplot(3,2,nfig)
pc=ax.pcolormesh(xa,ya,zima,shading='interp',cmap=cmap) # working good!
# pc=ax.imshow(zima,interpolation='bilinear',cmap=cmap)
pc.set_clim(0.0,660.0)
if colorflag:
g=pylab.colorbar(pc,ticks=N.arange(0,675,100))
print g
#g.ticks=None
#gax.yaxis.set_major_locator(MultipleLocator(40))
#g.ticks(N.array([0,20,40,60,80]))
return ax,g
def prep_data(filename):
# Data=pylab.load(r'c:\resolution_stuff\1p4K.iexy')
Data=pylab.load(filename)
xt=Data[:,2]
yt=Data[:,3]
zorigt=Data[:,0]
x=xt[:,zorigt>0.0]
y=yt[:,zorigt>0.0]
z=zorigt[:,zorigt>0.0]
# zorig=ma.array(zorigt)
print 'reached'
threshold=0.0;
# print zorigt < threshold
# print N.isnan(zorigt)
# z = ma.masked_where(zorigt < threshold , zorigt)
print 'where masked ', z.shape
#should be commented out--just for testing
## x = pylab.randn(Nu)/aspect
## y = pylab.randn(Nu)
## z = pylab.rand(Nu)
## print x.shape
## print y.shape
# Grid
xi, yi = N.mgrid[-5:5:100j,-5:5:100j]
xi,yi=N.mgrid[x.min():x.max():.05,y.min():y.max():.05]
# triangulate data
tri = D.Triangulation(x,y)
print 'before interpolator'
# interpolate data
interp = tri.nn_interpolator(z)
print 'interpolator reached'
zi = interp(xi,yi)
# or, all in one line
# zi = Triangulation(x,y).nn_interpolator(z)(xi,yi)
# return x,y,z
return xi,yi,zi
def prep_data2(xt,yt,zorigt):
# Data=pylab.load(r'c:\resolution_stuff\1p4K.iexy')
#Data=pylab.load(filename)
#xt=Data[:,2]
#yt=Data[:,3]
#zorigt=Data[:,0]
x=xt[:,zorigt>0.0]
y=yt[:,zorigt>0.0]
z=zorigt[:,zorigt>0.0]
# zorig=ma.array(zorigt)
print 'reached'
threshold=0.0;
# print zorigt < threshold
# print N.isnan(zorigt)
# z = ma.masked_where(zorigt < threshold , zorigt)
print 'where masked ', z.shape
#should be commented out--just for testing
## x = pylab.randn(Nu)/aspect
## y = pylab.randn(Nu)
## z = pylab.rand(Nu)
## print x.shape
## print y.shape
# Grid
xi, yi = N.mgrid[-5:5:100j,-5:5:100j]
xi,yi=N.mgrid[x.min():x.max():.001,y.min():y.max():.001]
# triangulate data
tri = D.Triangulation(x,y)
print 'before interpolator'
# interpolate data
interp = tri.nn_interpolator(z)
print 'interpolator reached'
zi = interp(xi,yi)
# or, all in one line
# zi = Triangulation(x,y).nn_interpolator(z)(xi,yi)
# return x,y,z
return xi,yi,zi
def readmeshfiles(mydirectory,myfilebase,myend):
myfilebaseglob=myfilebase+'*.'+myend
print myfilebaseglob
flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
#SU.printr(flist)
mydatareader=readicp.datareader()
Qx=N.array([])
Qy=N.array([])
Qz=N.array([])
Counts=N.array([])
for currfile in flist:
print currfile
mydata=mydatareader.readbuffer(currfile)
Qx=N.concatenate((Qx,N.array(mydata.data['Qx'])))
Qy=N.concatenate((Qy,N.array(mydata.data['Qy'])))
Qz=N.concatenate((Qz,N.array(mydata.data['Qz'])))
Counts=N.concatenate((Counts,N.array(mydata.data['Counts'])))
xa,ya,za=prep_data2(Qx,Qy,Counts);
return xa,ya,za
def strangezone(fig):
Nu = 10000
aspect = 1.0
mydirectory=r'c:\bifeo3xtal\dec7_2007'
myfilebase='cmesh'
myend='bt9'
xc,yc,zc=readmeshfiles(mydirectory,'cmesh',myend) #Rm temp
xd,yd,zd=readmeshfiles(mydirectory,'dmesh',myend) #0
xe,ye,ze=readmeshfiles(mydirectory,'emesh',myend) #-1.3
xf,yf,zf=readmeshfiles(mydirectory,'fmesh',myend) #0
xg,yg,zg=readmeshfiles(mydirectory,'gmesh',myend) #1.3
xh,yh,zh=readmeshfiles(mydirectory,'hmesh',myend) #0
xi,yi,zi=readmeshfiles(mydirectory,'imesh',myend) #-1.3
xj,yj,zj=readmeshfiles(mydirectory,'jmesh',myend) #0
print 'matplotlib'
if 1:
#fig=pylab.figure(figsize=(8,8))
ylim=(.485,.515)
xlim=(.485,.515)
#ylabel='E (meV)'
#xlabel=r'Q$ \ \ (\AA^{-1}$)'
ylabel='(1 1 0)'
xlabel='(1 -1 -2)'
if 1:
ax,g=plot_data(xd,yd,zd,fig,4,colorflag=True)
#ax.text(.98,.20,'E=0 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.xaxis.set_major_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
#g.ax.ticks=N.arange(0,100,20)
if 0:
ax,g=plot_data(xe,ye,ze,fig,2,colorflag=True)
ax.text(.98,.20,'E=-1.3 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
if 0:
ax,g=plot_data(xf,yf,zf,fig,3,colorflag=True)
ax.text(.98,.20,'0 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.set_ylabel(ylabel)
ax.xaxis.set_major_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
if 0:
ax,g=plot_data(xg,yg,zg,fig,4,colorflag=True)
ax.text(.98,.20,'1.3 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.yaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
if 0:
ax,g=plot_data(xh,yh,zh,fig,5,colorflag=True)
ax.text(.98,.20,'0 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.xaxis.set_minor_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
fmt = FormatStrFormatter('%0.3g') # or whatever
ax.xaxis.set_major_formatter(fmt)
ax.xaxis.set_major_locator(MaxNLocator(5))
if 0:
ax,g=plot_data(xi,yi,zi,fig,6,colorflag=True)
ax.text(.98,.20,'-1.3 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.set_xlabel(xlabel)
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_minor_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
fmt = FormatStrFormatter('%0.3g') # or whatever
ax.xaxis.set_major_formatter(fmt)
ax.xaxis.set_major_locator(MaxNLocator(5))
if 0:
ax,g=plot_data(xf,yf,zf,fig,6,colorflag=True)
ax.text(.98,.20,'0 KV',fontsize=14,horizontalalignment='right',verticalalignment='top',transform=ax.transAxes,color='white')
ax.set_xlabel(xlabel)
ax.yaxis.set_major_formatter(NullFormatter())
ax.set_ylim(ylim); ax.set_xlim(xlim)
#fmt = FormatStrFormatter('%1.4g') # or whatever
#ax.yaxis.set_major_formatter(fmt)
if 1:
print 'gca ', fig.gca()
for im in fig.gca().get_images():
print im
im.set_clim(0.0,660.0)
#pylab.show()
if 0:
print 'saving'
pylab.savefig(r'c:\sqltest\demo.pdf',dpi=150)
print 'saved'
if 0:
pylab.show()
def cartoon():
if 1:
#h k 0
ax=pylab.subplot(3,4,1)
#1 1 0
x1=N.array([1])
y1=N.array([1])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
#-1 -1 0
x1=N.array([-1])
y1=N.array([-1])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
#-1 2 0
x1=N.array([-1])
y1=N.array([2])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
#1 -2 0
x1=N.array([1])
y1=N.array([-2])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
#2 -1 0
x1=N.array([2])
y1=N.array([-1])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
#-2 1 0
x1=N.array([-2])
y1=N.array([1])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
pylab.xlabel('[1 0 0]')
pylab.ylabel('[0 1 0]')
#draw vertical line
#x1=[0,0]
#y1=[-2.5,2.5]
#pylab.plot(x1,y1,linewidth=3.0)
#draw horizontal line
#x1=[-2.5,2.5]
#y1=[0,0]
#pylab.plot(x1,y1,linewidth=3.0,color='blue')
#draw line 1 1 0
x1=[1,-1]
y1=[1,-1]
pylab.plot(x1,y1,linewidth=3.0,color='blue')
#draw line 1 2 0
x1=[1,-1]
y1=[-2,2]
pylab.plot(x1,y1,linewidth=3.0,color='blue')
#draw line 1 1 0
x1=[-2,2]
y1=[1,-1]
pylab.plot(x1,y1,linewidth=3.0,color='blue')
s=r'$\delta 2\bar{\delta} 0$'
pylab.text(1.2,-2,s,fontsize=10)
s=r'$2\delta \bar{\delta} 0$'
pylab.text(1.8,-0.7,s,fontsize=10)
s=r'$\delta \delta 0$'
pylab.text(1,1.2,s,fontsize=10)
s=r'$\bar{\delta} \bar{\delta} 0$'
pylab.text(-1,-1.6,s,fontsize=10)
s=r'$2\bar{\delta} \delta 0$'
pylab.text(-2,1.2,s,fontsize=10)
s=r'$\bar{\delta} 2\delta 0$'
pylab.text(-.7,2.0,s,fontsize=10)
pylab.axis([-3.5,3.5,-3.5,3.5])
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(NullFormatter())
if 1:
#h h l
ax=pylab.subplot(3,4,2)
# 1 1 0
x1=N.array([4])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
s=r'$\delta \delta 0$'
pylab.text(4.8,0.0,s,fontsize=10)
# -1 -1 0
x1=N.array([-4])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='blue',markeredgecolor='blue')
s=r'$\bar{\delta} \bar{\delta} 0$'
pylab.text(-6.8,0.0,s,fontsize=10)
# -1 2 0
x1=N.array([2])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=5,markerfacecolor='white')
s=r'$\bar{\delta} 2\delta 0$'
pylab.text(0.5,0.4,s,fontsize=10)
# 2 -1 0
#x1=N.array([2])
#y1=N.array([0])
#pylab.plot(x1,y1,'bo',markersize=10)
s=r'$2\delta \bar{\delta} 0$'
pylab.text(0.5,-1.4,s,fontsize=10)
# -2 1 0
x1=N.array([-2])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=5,markerfacecolor='white')
s=r'$2\bar{\delta} \delta 0$'
pylab.text(-3.5,0.4,s,fontsize=10)
# 1 -2 0
#x1=N.array([2])
#y1=N.array([0])
#pylab.plot(x1,y1,'bo',markersize=10)
s=r'$\delta 2\bar{\delta} 0$'
pylab.text(-3.5,-1.4,s,fontsize=10)
pylab.axis([-8.0,8.0,-3.5,3.5])
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(NullFormatter())
pylab.xlabel('[1 1 0]')
pylab.ylabel('[0 0 1]')
#ax=pylab.subplot(4,2,2)
if 1:
#h k h-k
ax=pylab.subplot(3,2,2)
# 1 1 0
x1=N.array([4])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=20,markerfacecolor='blue',markeredgecolor='blue')
s=r'$\delta \delta 0$'
pylab.text(4.8,0.0,s,fontsize=20)
# -1 -1 0
x1=N.array([-4])
y1=N.array([0])
pylab.plot(x1,y1,'bo',markersize=20,markerfacecolor='blue',markeredgecolor='blue')
s=r'$\bar{\delta} \bar{\delta} 0$'
pylab.text(-6.8,0.0,s,fontsize=20)
# -1 2 0
x1=N.array([2])
y1=N.array([4])
pylab.plot(x1,y1,'bo',markersize=5,markerfacecolor='white')
s=r'$\bar{\delta} 2\delta 0$'
pylab.text(0.5,4.4,s,fontsize=20)
# -2 1 0
x1=N.array([-2])
y1=N.array([4])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='white')
s=r'$2\bar{\delta} \delta 0$'
pylab.text(-3.0,4.4,s,fontsize=20)
# 2 -1 0
x1=N.array([2])
y1=N.array([-4])
pylab.plot(x1,y1,'bo',markersize=10,markerfacecolor='gray')
s=r'$2\delta \bar{\delta} 0$'
pylab.text(0.5,-6.8,s,fontsize=20)
# 1 -2 0
x1=N.array([-2])
y1=N.array([-4])
pylab.plot(x1,y1,'bo',markersize=5,markerfacecolor='gray')
s=r'$\delta 2\bar{\delta} 0$'
pylab.text(-3.0,-6.8,s,fontsize=20)
pylab.axis([-10.5,10.5,-10.5,10.5])
ax.yaxis.set_major_formatter(NullFormatter())
ax.xaxis.set_major_formatter(NullFormatter())
pylab.xlabel('[1 1 0]')
pylab.ylabel('[-1 1 -2]')
if 0:
pylab.subplot(3,2,3)
pylab.subplot(3,2,4)
pylab.subplot(3,2,5)
pylab.subplot(3,2,6)
pylab.subplots_adjust(wspace=0.5,hspace=0.6)
return
if __name__=="__main__":
if 1:
fig=pylab.figure(figsize=(8,8))
a=N.array([5.5436],'d')
b=N.array([5.5436],'d')
c=N.array([13.8844],'d')
alpha=N.array([90],'d')
beta=N.array([90],'d')
gamma=N.array([120],'d')
# orient1=N.array([[0,1,1]],'d')
orient1=N.array([[0,0,1]],'d')
orient2=N.array([[1,1,0]],'d')
mylattice=lattice_calculator.lattice(a=a,b=b,c=c,alpha=alpha,beta=beta,gamma=gamma,\
orient1=orient1,orient2=orient2)
EXP={}
EXP['ana']={}
EXP['ana']['tau']='pg(002)'
EXP['mono']={}
EXP['mono']['tau']='pg(002)';
EXP['ana']['mosaic']=25
EXP['mono']['mosaic']=25
EXP['sample']={}
EXP['sample']['mosaic']=25
EXP['sample']['vmosaic']=25
EXP['hcol']=N.array([40, 40, 40, 80],'d')
EXP['vcol']=N.array([120, 120, 120, 120],'d')
EXP['infix']=-1 #positive for fixed incident energy
EXP['efixed']=14.7
EXP['method']=0
setup=[EXP]
mydirectory=r'c:\BiFeO3xtal\Oct9_2007'
myfilebase='bfo_spinflip_he3flip51585'
myfilebase2='bfo_spinflip51579'
myfilebase3='bfo_spinflip51583'
myend='bt7'
data={}
#pm
myfilebaseglob=myfilebase+'*.'+myend
print myfilebaseglob
flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
myfilestr=flist[0]
Counts=N.array([],'float64')
monlist=[]
timestamp={}
mydatareader=readncnr.datareader()
mydata=mydatareader.readbuffer(myfilestr)
S1=N.array(mydata.data['a3'][1:])
S2=N.array(mydata.data['a4'][1:])
A2=N.array(mydata.data['a5'][1:])*2
M2=N.array(mydata.data['a2'][1:])
Counts_pm=N.concatenate((Counts,N.array(mydata.data['detector'][1:])))
H_pm,K_pm,L_pm,E_pm,Q_pm,Ei_pm,Ef_pm=mylattice.SpecWhere(myradians(M2),myradians(S1),myradians(S2),myradians(A2),setup)
monlist.append(mydata.data['monitor'][0])
Counts_pm=Counts_pm[:-1]
H_pm=H_pm[:-1]
K_pm=K_pm[:-1]
L_pm=L_pm[:-1]
E_pm=E_pm[:-1]
Q_pm=Q_pm[:-1]
Ei_pm=Ei_pm[:-1]
Ef_pm=Ef_pm[:-1]
timestamp['pm']=N.array(mydata.data['timestamp'][1:])[:-1]
#print H_pm
#begin mp
myfilebaseglob=myfilebase2+'*.'+myend
print myfilebaseglob
flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
myfilebaseglob=myfilebase3+'*.'+myend
flist2 = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
myfilestr=flist[0]
Counts=N.array([],'float64')
mydatareader=readncnr.datareader()
mydata1=mydatareader.readbuffer(myfilestr)
S1=N.array(mydata1.data['a3'])[1:]
S2=N.array(mydata1.data['a4'])[1:]
A2=N.array(mydata1.data['a5'])[1:]*2
M2=N.array(mydata1.data['a2'])[1:]
Counts_mp=N.array(mydata1.data['detector'])[1:]
timestamp_mp=N.array(mydata1.data['timestamp'])[1:]
#H_mp,K_mp,L_mp,E_mp,Q_mp,Ei_mp,Ef_mp=mylattice.SpecWhere(myradians(M2),myradians(S1),myradians(S2),myradians(A2),setup)
monlist.append(mydata1.data['monitor'][0])
#print M2.shape
#print Counts_mp.shape
#remove potential bad datapoint that bt7 generated in dd mode
myfilestr=flist2[0]
mydatareader=readncnr.datareader()
mydata2=mydatareader.readbuffer(myfilestr)
S1=N.concatenate((S1,N.array(mydata2.data['a3'])[1:]))
S2=N.concatenate((S2,N.array(mydata2.data['a4'])[1:]))
A2=N.concatenate((A2,N.array(mydata2.data['a5'])[1:]*2))
M2=N.concatenate((M2,N.array(mydata2.data['a2'])[1:]))
timestamp_mp=N.concatenate((timestamp_mp,N.array(mydata2.data['timestamp'])[1:]))
timestamp['mp']=timestamp_mp
mylattice=lattice_calculator.lattice(a=a,b=b,c=c,alpha=alpha,beta=beta,gamma=gamma,\
orient1=orient1,orient2=orient2)
Counts_mp=N.concatenate((Counts_mp,N.array(mydata2.data['detector'])[1:]))
#print 'where'
H_mp,K_mp,L_mp,E_mp,Q_mp,Ei_mp,Ef_mp=mylattice.SpecWhere(myradians(M2),myradians(S1),myradians(S2),myradians(A2),setup)
ylist=[Counts_pm,Counts_mp]
yerrlist=[N.sqrt(Counts_pm),N.sqrt(Counts_mp)]
I,Ierr=simple_combine.monitor_normalize(ylist,yerrlist,monlist)
counts={}
errs={}
counts['pm']=I[0]
counts['mp']=I[1]
errs['pm']=Ierr[0]
errs['mp']=Ierr[1]
cell=mydirectory+'\WilliamOct2007horizCells.txt'
print cell
pbflags=polcorrect_lib.PBflags()
pbflags.MonitorCorrect=0
pbflags.PolMonitorCorrect=1
pbflags.MonoSelect=1
pbflags.Debug=0
pbflags.SimFlux=0
pbflags.SimDeviate=0
pbflags.NoNegativeCS=0
pbflags.HalfPolarized=0
pbflags.CountsEnable=[0,0,1,1]
pbflags.CountsAdd1=[0,0,0,0]
pbflags.CountsAdd2=[0,0,0,0]
pbflags.Sconstrain=[1,1,0,0]
pbflags.Spp=[0,0,0,0]
pbflags.Smm=[0,0,0,0]
pbflags.Spm=[0,0,0,0]
pbflags.Smp=[0,0,0,0]
mypolcor=polcorrect_lib.polarization_correct(counts,errs,timestamp,cell,Ei_mp,Ef_mp)
corrected_counts=mypolcor.correct(pbflags)
#print timestamp['mp'].shape
#print timestamp['pm'].shape
#print S1.shape
#print S2.shape
#print A2.shape
#print M2.shape
#print Counts_mp.shape
#print H_mp.shape
#print Counts_mp.shape
#print I[0].shape
#print I[1].shape
if 1:
outputfile=r'c:\bifeo3xtal\hhl_pm.txt'
f=open(outputfile,'wt')
f.write('H K L I Ierr\n')
for i in range(H_pm.size):
s='%f %f %f %f %f'%(H_pm[i],K_pm[i],L_pm[i],corrected_counts['Spm'][i],corrected_counts['Epm'][i])
print s
f.write(s+'\n')
f.close()
if 1:
outputfile=r'c:\bifeo3xtal\hhl_mp.txt'
f=open(outputfile,'wt')
f.write('H K L I Ierr\n')
for i in range(H_mp.size):
s='%f %f %f %f %f'%(H_mp[i],K_mp[i],L_mp[i],corrected_counts['Smp'][i],corrected_counts['Emp'][i])
print s
f.write(s+'\n')
f.close()
# Next zone
myend='out'
myend='bt7'
mydirectory=r'c:\bifeo3xtal\jan8_2008\9175\data'
myfilebase='fieldscansplusminusreset53630'
myfilebase2='fieldscanminusplusreset53631'
myfilebaseglob=myfilebase+'*.'+myend
flist = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
myfilebaseglob=myfilebase2+'*.'+myend
flist2 = SU.ffind(mydirectory, shellglobs=(myfilebaseglob,))
myfilestr=flist[0]
mydatareader=readncnr.datareader()
mydata_pm=mydatareader.readbuffer(myfilestr)
q_pm=N.array(mydata_pm.data['qx'])
qh_pm=N.array(mydata_pm.data['qx'])
qk_pm=N.array(mydata_pm.data['qy'])
ql_pm=N.array(mydata_pm.data['qz'])
a=N.array([3.97296],'d')
b=N.array([2.79045],'d')
c=N.array([13.86],'d')
alpha=N.array([90],'d')
beta=N.array([90],'d')
gamma=N.array([90],'d')
orient1=N.array([[1,0,0]],'d')
orient2=N.array([[0,1,0]],'d')
mylattice=lattice_calculator.lattice(a=a,b=b,c=c,alpha=alpha,beta=beta,gamma=gamma,\
orient1=orient1,orient2=orient2)
Q_pm=mylattice.modvec(qh_pm,qk_pm,ql_pm,'latticestar')
#counts_pm=N.array(mydata_pm.data['detector_corrected'])
#errs_pm=N.array(mydata_pm.data['detector_errs_corrected'])
counts_pm=N.array(mydata_pm.data['detector'])
errs_pm=N.sqrt(counts_pm)
ht_pm=-qh_pm+qk_pm
kt_pm=qh_pm+qk_pm
lt_pm=-2*qh_pm
qh_pm=ht_pm
qk_pm=kt_pm
ql_pm=lt_pm
q_pm=qh_pm
myfilestr=flist2[0]
mydatareader=readncnr.datareader()
mydata_mp=mydatareader.readbuffer(myfilestr)
q_mp=N.array(mydata_mp.data['qx'])
qh_mp=N.array(mydata_mp.data['qx'])
qk_mp=N.array(mydata_mp.data['qy'])
ql_mp=N.array(mydata_mp.data['qz'])
mylattice=lattice_calculator.lattice(a=a,b=b,c=c,alpha=alpha,beta=beta,gamma=gamma,\
orient1=orient1,orient2=orient2)
Q_mp=mylattice.modvec(qh_mp,qk_mp,ql_mp,'latticestar')
#counts_mp=N.array(mydata_mp.data['detector_corrected'])
#errs_mp=N.array(mydata_mp.data['detector_errs_corrected'])
counts_mp=N.array(mydata_mp.data['detector'])
errs_mp=N.sqrt(counts_mp)
ht_mp=-qh_mp+qk_mp
kt_mp=qh_mp+qk_mp
lt_mp=-2*qh_mp
qh_mp=ht_mp
qk_mp=kt_mp
ql_mp=lt_mp
q_mp=qh_mp
cartoon()
timestamp={}
errs={}
counts={}
timestamp['mp']=N.array(mydata_mp.data['timestamp'])
timestamp['pm']=N.array(mydata_pm.data['timestamp'])
counts['pm']=counts_pm
counts['mp']=counts_mp
errs['pm']=errs_pm
errs['mp']=errs_mp
Ei_mp=14.7*N.ones(qh_pm.shape,'float64')
Ef_mp=14.7*N.ones(qh_pm.shape,'float64')
cell=r'C:\mytripleaxisproject\polarization\cells.txt'
mypolcor=polcorrect_lib.polarization_correct(counts,errs,timestamp,cell,Ei_mp,Ef_mp)
corrected_counts2=mypolcor.correct(pbflags)
if 1:
outputfile=r'c:\bifeo3xtal\hkhminusk_pm.txt'
f=open(outputfile,'wt')
f.write('Q H K L I Ierr\n')
for i in range(qh_pm.size):
#s='%f %f %f %f %f'%(qh_pm[i],qk_pm[i],ql_pm[i],counts_pm[i],errs_pm[i])
s='%f %f %f %f %f %f'%(Q_pm[i],qh_pm[i],qk_pm[i],ql_pm[i],corrected_counts2['Spm'][i],corrected_counts2['Epm'][i])
f.write(s+'\n')
print s
f.close()
if 1:
outputfile=r'c:\bifeo3xtal\hkhminusk_mp.txt'
f=open(outputfile,'wt')
f.write('Q H K L I Ierr\n')
for i in range(qh_mp.size):
#s='%f %f %f %f %f'%(qh_mp[i],qk_mp[i],ql_mp[i],counts_mp[i],errs_mp[i])
s='%f %f %f %f %f %f'%(Q_mp[i],qh_mp[i],qk_mp[i],ql_mp[i],corrected_counts2['Smp'][i],corrected_counts2['Emp'][i])
print s
f.write(s+'\n')
print s
f.close()
#exit()
#print qh_mp.shape
if 1:
pylab.subplot(3,2,6)
#pylab.errorbar(q_mp,counts_mp,fmt='bo',yerr=errs_mp,linestyle='None')
#pylab.errorbar(q_pm,counts_pm,fmt='ro',yerr=errs_pm,linestyle='None')
pylab.errorbar(q_mp,corrected_counts2['Smp'],fmt='bo',yerr=corrected_counts2['Emp'],linestyle='None')
pylab.errorbar(q_pm,corrected_counts2['Spm'],fmt='ro',yerr=corrected_counts2['Epm'],linestyle='None')
if 1:
pylab.subplot(3,2,5)
pylab.errorbar(H_mp,corrected_counts['Smp'],fmt='bo',yerr=corrected_counts['Emp'],linestyle='None')
pylab.errorbar(H_pm,corrected_counts['Spm'],fmt='ro',yerr=corrected_counts['Epm'],linestyle='None')
if 0:
pylab.errorbar(H_mp,data['mp'],fmt='bo',yerr=errs['mp'],linestyle='None')
pylab.errorbar(H_pm,data['pm'],fmt='ro',yerr=errs['pm'],linestyle='None')
pylab.show()
strangezone(fig)
pylab.subplots_adjust(wspace=0.5,hspace=0.6)
pylab.show()
exit()
if 0:
for i in range(S1.size):
s='%f %f %f %f'%(S1[i],S2[i],A2[i],M2[i])
print s
exit()
if 0:
H,K,L,E,Q,Ei,Ef=mylattice.SpecWhere(myradians([M2[0]]),myradians([-163.193]),myradians([29.833]),myradians([A2[0]]),setup)
s='%f %f %f %f %f %f %f'%(S1[0],S2[0],H[0],K[0],L[0],E[0],Q[0])
print s
if 0:
H,K,L,E,Q,Ei,Ef=mylattice.SpecWhere(myradians(M2),myradians(S1),myradians(S2),myradians(A2),setup)
for i in range(1,S1.size):
s='%f %f %f %f %f %f %f'%(S1[i],S2[i],H[i],K[i],L[i],E[i],Q[i])
print s
if 0:
pylab.plot(H,L,'bo')
pylab.xlabel('[1,1,0]')
pylab.ylabel('[0,0,1]')
#pylab.axis([-1,1,-4,4])
pylab.show()