-
Notifications
You must be signed in to change notification settings - Fork 6
/
relaxation v2.ipf
3558 lines (3080 loc) · 134 KB
/
relaxation v2.ipf
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
#pragma rtGlobals=1 // Use modern global access m--ethod.
#include "SER File Loader"
#include "Annular Average2"
#include "DP Annular Average UI v1.3"
#include "Auto Find DP Center2"
#include "Average and SDOM"
#include "GFX"
//#include "Stem_Var_filter_bin8"
// The function "correlatefunc_k" is to calculate time autocorrelatlion g2(t) at a reciprocal space vector k from diffraction patttern time series.
// data: diffraction pattern time series.
// allowance: small change in k. Find all points from diffraction patterns in the range (k-allowance, k+allowance).
// (xcenter, ycenter): diffraction pattern center position.
// xblockstart, xblockend, yblockstart, yblockend: the location of beam stopper in the diffraction pattern.
// The function "relaxationfunc" is to fit g2(t) to 1+B*exp(-2*(t/tau)^beta).
// by Li He, updated on 01-22-15.
//annular_average(data, xcenter, ycenter, xblockstart, xblockend, yblockstart, yblockend, strip_width). // Calculate annular average. Titan CCD.
//correlatefunc_k_map(data,k,bin,xcenter,ycenter,xblockstart,xblockend,yblockstart,yblockend) // Calculate g2, correlation function.
//resampleg2(g2, name) // Re-sample g2 to be evenly distributed in log time scale.
Function correlatefunc_allPixels(im_stack, x1, x2, y1, y2, name) // Calculate g2 from STEM image series to detect, e.g., BSD relaxation time.
// x1, y1, x2, y2 are selected regions.
wave im_stack
variable x1, y1, x2, y2
string name
variable tp = DimSize(im_stack, 2), samplesize=(x2-x1)*(y2-y1)
make/o/n=(tp) add_td=0
make/o/n=(tp, samplesize) g2t_tpt_map=0
make/o/n=(samplesize) I_ave, xmap, ymap
variable x, y, i, j, ave, pcount=0
string g2t_tpt_mapname="g2tmap_tpt_"+name
string g2t_tpt_name="g2t_tpt_"+name
string I_avename="I_ave_"+name
string xmapname="x_"+name
string ymapname="y_"+name
for(x=x1; x<x2; x+=1)
for(y=y1; y<y2; y+=1)
Imagetransform/beam={(x), (y)} getbeam im_stack
wave W_beam = $"W_beam"
ave=mean(W_beam)
add_td=0
for (j=0;j<tp;j+=1)
for (i=0;i<(tp-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_tpt_map[][pcount]=(tp-p)*add_td[p]/sum(W_beam,0,tp-p-1)/sum(W_beam,p,tp-1)
I_ave[pcount]=ave
xmap[pcount]=x
ymap[pcount]=y
pcount=pcount+1
endfor
endfor
SetScale/P x 0, 0.948,"", g2t_tpt_map // STEM image series, 0.84 s per frame, total 0.948 s per frame.
redimension/n=(-1, pcount) g2t_tpt_map
redimension/n=(pcount) I_ave, xmap, ymap
imagetransform sumallrows g2t_tpt_map
duplicate/o W_sumRows g2t
g2t=g2t/pcount
SetScale/P x 0,0.948,"", g2t
duplicate/o g2t_tpt_map, $g2t_tpt_mapname
duplicate/o g2t, $g2t_tpt_name
duplicate/o I_ave, $I_avename
duplicate/o xmap, $xmapname
duplicate/o ymap, $ymapname
killwaves g2t_tpt_map
killwaves g2t, I_ave, add_td, xmap, ymap
killwaves W_beam, W_sumrows
print pcount
end
Function multi_tauBNL(data, k, bin, xcenter, ycenter, xa, ya, yb, xc, yc, xd, xe, ye) // Multi-tau, the first segment is 1/16 total data length.
// BNL K2 data
wave data
variable k, bin, xcenter, ycenter, xa, ya, yb, xc, yc, xd, xe, ye
//variable r=k/0.008052248 // Bin 8. Camera length 380mm.
variable r=k/0.01006531 // Bin 10. Camera length 380mm.
variable tp = DimSize(data, 2), neighbour=round((bin-1)/2)
variable samplesize=round(2*pi*r)
variable kbc=(yc-yb)/(xc-xa), kde=(ye-yc)/(xe-xd)
make/o/n=(tp) add_td=0
make/o/n=(tp,samplesize) g2t_tpt_map=0
make/o/n=(samplesize) x_map, y_map, I_ave
make/o/n=(samplesize) theta, xp, yp
theta[]=p*2*pi/samplesize
xp=round(xcenter+r*cos(theta))
yp=round(ycenter+r*sin(theta))
variable i, j, sumi, sumip
variable pcount=0
string name="_"+nameofwave(data)+"_"+num2str(k)+"_bin"+num2str(bin)
string g2t_tpt_mapname="g2tmap_tpt"+name
string g2t_tpt_name="g2t_tpt"+name
string x_mapname="x_map"+name
string y_mapname="y_map"+name
string I_avename="I_ave"+name
// Find the circular points on diffraction patterns with the reciprocal space vector k.
for(k=0; k<samplesize; k+=1)
// Remove beam stop shadow
if (xp[k]>xc && xp[k]<xd && yp[k]>ya && yp[k]<yc)
pcount=pcount
elseif (xp[k]>xa && xp[k]<xc && yp[k]>ya && yp[k]<yb)
pcount=pcount
elseif (xp[k]>xa && xp[k]<xc && yp[k]>yb && yp[k]<kbc*(xp[k]-xa)+yb)
pcount=pcount
elseif (xp[k]>xd && xp[k]<xe && yp[k]>ya && yp[k]<ye)
pcount=pcount
elseif (xp[k]>xd && xp[k]<xe && yp[k]>ye && yp[k]<kde*(xp[k]-xd)+yc)
pcount=pcount
elseif(xp[k]>xa && xp[k]<xe && yp[k]>ya && yp[k]<yb)
pcount=pcount
else
make/o/n=(tp) bin_average=0
for(i=0-neighbour; i<neighbour+1; i+=1)
for(j=0-neighbour; j<neighbour+1; j+=1)
Imagetransform/beam={(xp[k]+i), (yp[k]+j)} getbeam data
wave W_beam = $"W_beam"
bin_average=bin_average+W_beam
endfor
endfor
W_beam=bin_average/bin^2
add_td=0
for (j=0;j<tp/16;j+=1)
for (i=0;i<(tp/16-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_tpt_map[0, tp/16-1][pcount]=(tp/16-p)*add_td[p]/sum(W_beam,0,tp/16-p-1)/sum(W_beam,p,tp/16-1)
add_td=0
sumi=0
sumip=0
for (j=tp/16; j<tp/8; j+=1)
for (i=0; i<(tp/8-j); i+=2)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
sumi=sumi+W_beam[i]
sumip=sumip+W_beam[i+j]
endfor
endfor
g2t_tpt_map[tp/16, tp/8-1][pcount]=(tp/8-p)/2*add_td[p]/sumi/sumip
add_td=0
sumi=0
sumip=0
for (j=tp/8; j<tp/4; j+=1)
for (i=0; i<(tp/4-j); i+=4)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
sumi=sumi+W_beam[i]
sumip=sumip+W_beam[i+j]
endfor
endfor
g2t_tpt_map[tp/8, tp/4-1][pcount]=(tp/4-p)/4*add_td[p]/sumi/sumip
add_td=0
sumi=0
sumip=0
for (j=tp/4; j<tp/2; j+=1)
for (i=0; i<(tp/2-j); i+=8)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
sumi=sumi+W_beam[i]
sumip=sumip+W_beam[i+j]
endfor
endfor
g2t_tpt_map[tp/4, tp/2-1][pcount]=(tp/2-p)/8*add_td[p]/sumi/sumip
add_td=0
sumi=0
sumip=0
for (j=tp/2; j<tp; j+=1)
for (i=0; i<(tp-j); i+=16)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
sumi=sumi+W_beam[i]
sumip=sumip+W_beam[i+j]
endfor
endfor
g2t_tpt_map[tp/2, tp-1][pcount]=(tp-p)/16*add_td[p]/sumi/sumip
x_map[pcount]=xp[k]
y_map[pcount]=yp[k]
I_ave[pcount]=mean(W_beam)
pcount=pcount+1
endif
endfor
redimension/n=(-1, pcount) g2t_tpt_map
redimension/n=(pcount) x_map, y_map, I_ave
SetScale/P x 0, 0.0025,"", g2t_tpt_map //K2, 400 frames/s
imagetransform sumallrows g2t_tpt_map
duplicate/o W_sumRows g2t
g2t=g2t/pcount
SetScale/P x 0,0.0025,"", g2t
duplicate/o g2t_tpt_map, $g2t_tpt_mapname
duplicate/o g2t, $g2t_tpt_name
duplicate/o x_map, $x_mapname
duplicate/o y_map, $y_mapname
duplicate/o I_ave, $I_avename
killwaves g2t_tpt_map, g2t, x_map, y_map, I_ave, add_td, bin_average, W_beam, W_sumrows, xp, yp, theta
print pcount
end
Function correlatefunc_imageSeries(im_stack, xgrain, ygrain, x1, x2, y1, y2, name) // Calculate g2 from STEM image series to detect, e.g., BSD relaxation time. xgrain, ygrain is selected pixels array.
// x1, y1, x2, y2 are selected regions.
wave im_stack, xgrain, ygrain
variable x1, y1, x2, y2
string name
variable tp = DimSize(im_stack, 2)
variable samplesize=dimsize(xgrain, 0)
make/o/n=(tp) add_td=0
make/o/n=(tp,samplesize) g2t_tpt_map=0
make/o/n=(samplesize) I_ave, xmap, ymap
variable i, j, k, ave, pcount=0
string g2t_tpt_mapname="g2tmap_tpt_"+name
string g2t_tpt_name="g2t_tpt_"+name
string I_avename="I_ave_"+name
string xmapname="x_"+name
string ymapname="y_"+name
for(k=0; k<samplesize; k+=1)
if(xgrain[k]>x1&&xgrain[k]<x2&&ygrain[k]>y1&&ygrain[k]<y2)
Imagetransform/beam={(xgrain[k]), (ygrain[k])} getbeam im_stack
wave W_beam = $"W_beam"
ave=mean(W_beam)
add_td=0
for (j=0;j<tp;j+=1)
for (i=0;i<(tp-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_tpt_map[][pcount]=(tp-p)*add_td[p]/sum(W_beam,0,tp-p-1)/sum(W_beam,p,tp-1)
I_ave[pcount]=ave
xmap[pcount]=xgrain[k]
ymap[pcount]=ygrain[k]
pcount=pcount+1
endif
endfor
SetScale/P x 0, 0.948,"", g2t_tpt_map // STEM image series, 0.84 s per frame, total 0.948 s per frame.
redimension/n=(-1, pcount) g2t_tpt_map
redimension/n=(pcount) I_ave, xmap, ymap
imagetransform sumallrows g2t_tpt_map
duplicate/o W_sumRows g2t
g2t=g2t/pcount
SetScale/P x 0,0.948,"", g2t
duplicate/o g2t_tpt_map, $g2t_tpt_mapname
duplicate/o g2t, $g2t_tpt_name
duplicate/o I_ave, $I_avename
duplicate/o xmap, $xmapname
duplicate/o ymap, $ymapname
killwaves g2t_tpt_map
killwaves g2t, I_ave, add_td, xmap, ymap
killwaves W_beam, W_sumrows
print pcount
end
Function intensity_dose(av_series, indexes, name)
wave av_series, indexes
string name
variable N=numpnts(indexes), i
make/o/n=(N) 'sum_0.4_0.49', 'norm_0.4_0.49', 'sum_0.59_0.67', 'norm_0.59_0.67', 'sum_0.69_0.77', 'norm_0.69_0.77'
make/o/n=(N) time_s, total_dose
for(i=0; i<N; i+=1)
duplicate/o av_series av_tmp
redimension/n=(-1, indexes[i]) av_tmp
imagetransform sumallrows av_tmp
wave W_sumRows=$"W_sumRows"
SetScale/P x 0,0.006967,"", W_sumRows
duplicate/o W_sumRows av_index
av_index=W_sumRows/indexes[i]
'sum_0.4_0.49'[i]=sum(av_index, 0.40, 0.49)
'sum_0.59_0.67'[i]=sum(av_index, 0.59, 0.67)
'sum_0.69_0.77'[i]=sum(av_index, 0.69, 0.77)
string av_index_name=name+"_"+num2str(indexes[i])
duplicate/o av_index $av_index_name
endfor
sort indexes, indexes, 'sum_0.4_0.49', 'sum_0.59_0.67', 'sum_0.69_0.77'
'norm_0.4_0.49'='sum_0.4_0.49'/'sum_0.4_0.49'[0]
'norm_0.59_0.67'='sum_0.59_0.67'/'sum_0.59_0.67'[0]
'norm_0.69_0.77'='sum_0.69_0.77'/'sum_0.69_0.77'[0]
time_s[]=0.2363*indexes[p]
total_dose[]=6.6e-12/1.6e-19*time_s[p]/pi*4/1.6^2
killwaves av_tmp, av_index, W_sumRows
end
Function taufromMap(g2t_map, name)
wave g2t_map
string name
variable N=dimsize(g2t_map, 1)
variable V_flag, V_LevelX, count=0, total=0, i //V_maxloc
string tauname="tau_"+name
make/o/n=(N) tau
duplicate/o g2t_map g2t
redimension/n=(-1,0) g2t
for(i=0; i<N; i+=1)
V_LevelX=nan
g2t[]=g2t_map[p][i]
duplicate/o g2t g2t_smth
Smooth 50, g2t_smth
//wavestats/q g2t
findlevel/edge=2/q g2t_smth, 1+(g2t[0]-1)*exp(-2)
if(V_flag==0 && V_LevelX>0.2363*3 && V_LevelX<200)
count=count+1
//if(V_LevelX<1)
//string fitname=name+"_"+num2istr(i)
//string parametername="parameter_"+name+"_"+num2istr(i)
//fitg2_noGraph(g2t, 15, fitname)
//wave parameter=$parametername
//tau[i]=parameter[0]
//else
tau[i]=V_LevelX
//endif
total=total+V_LevelX
else
tau[i]=nan
endif
endfor
print count
print total/count
duplicate/o tau $tauname
killwaves tau, g2t, g2t_smth//, parameter
end
Function g2fromMap(g2t_map, name)
wave g2t_map
string name
variable n=dimsize(g2t_map, 1)
string g2tname="g2t_"+name
imagetransform sumallrows g2t_map
duplicate/o W_sumRows g2t
g2t[]=g2t[p]/n
SetScale/P x 0,0.2363,"", g2t
duplicate/o g2t $g2tname
killwaves g2t
end
Function I_points(data, x, y, name)
wave data
variable x, y
string name
variable zp = DimSize(data, 2)
string Iname="I_"+name+"_"+num2istr(x)+"_"+num2istr(y)
redimension/s data
Imagetransform/beam={(x), (y)} getbeam data
wave W_beam = $"W_beam"
SetScale/P x 0, 0.2276,"", W_beam
duplicate/o W_beam $Iname
killwaves W_beam
end
function resampleg2(g2, name, samplepts)
wave g2
string name
variable samplepts
string g2_rsname="g2t_rs_"+name
make/o/n=(samplepts) g2_rs, t_rs
//make/o/n=(100) g2_rs, t_rs
variable datalength=dimsize(g2, 0)
t_rs[]=alog(log(0.948)+p/(samplepts-1)*(log(0.948*datalength)-log(0.948))) // BSD image series, 0.84 s per frame, totally 0.948 s per frame.
//t_rs=alog(log(1.528)+p/(samplepts-1)*(log(1.528*50)-log(1.528))) // Cluster size map, interpixel distance 1.528 nm.
//t_rs=alog(log(0.248587083)+p/19*(log(0.248587083*1000)-log(0.248587083)))
//t_rs=alog(log(0.248587083)+p/99*(log(0.248587083*1000)-log(0.248587083))) // 0.18s/frame, 1000 frames, bin8, 200^2 pixels.
//t_rs=alog(log(0.0025)+p/(samplepts-1)*(log(0.0025*48000)-log(0.0025))) // K2 camera, 0.0025fps, 2 min.
//t_rs=alog(log(0.267647)+p/99*(log(0.267647*500)-log(0.267647))) // 0.2s/frame, 1000 frames, bin8, 200^2 pixels. g2 half t length.
//t_rs=alog(log(0.26547)+p/99*(log(0.26547*1000)-log(0.26547))) // 0.2s, 350^2 pixels, search mode.
//t_rs=alog(log(2)+p/99*(log(2*50)-log(2))) // Cluster size map, interpixel distance 2 nm.
g2_rs[]=g2[t_rs[p]/0.948]
//g2_rs[]=g2[t_rs[p]/1.528]
//g2_rs[]=g2[t_rs[p]/0.248587083]
//g2_rs[]=g2[t_rs[p]/0.0025]
//g2_rs[]=g2[t_rs[p]/0.26547]
//g2_rs[]=g2[t_rs[p]/2]
duplicate/o g2_rs, $g2_rsname
killwaves g2_rs
end
Function filterlongtau(g2t_map, name)
wave g2t_map
string name
variable N=dimsize(g2t_map, 1), count=0, i, V_min
string g2tname="g2t_"+name+"_cross 1"
string g2t_rsname="g2t_rs_"+name
duplicate/o g2t_map g2t
redimension/n=(-1,0) g2t
duplicate/o g2t, g2t_temp
g2t=0
for (i=0;i<N;i+=1)
g2t_temp[]=g2t_map[p][i]
wavestats/Q/Z/R=[0, 1000] g2t_temp // ERC.
//wavestats/Q/Z/R=[0, 900] g2t_temp // 0.2s per frames, 1000 frames.
//wavestats/Q/Z/R=[0, 1800] g2t_temp // K2, 0.005s per frame, 10s data
//wavestats/Q/Z/R=[0, 2500] g2t_temp // 0.25min data
//wavestats/Q/Z/R=[0, 5000] g2t_temp // 0.5min data
//wavestats/Q/Z/R=[0, 10000] g2t_temp // 1min data
//wavestats/Q/Z/R=[0, 20000] g2t_temp // 2min data
//wavestats/Q/Z/R=[0, 39000] g2t_temp // 4min data
if (V_min<1)
g2t[]=g2t[p]+g2t_temp[p]
count=count+1
endif
endfor
g2t=g2t/count
//SetScale/P x 0,3.07,"", g2t
//SetScale/P x 0,2.1414,"", g2t
make/o/n=(100) g2t_rs, t_rs
//t_rs=alog(log(0.267647)+p/99*(log(0.267647*1000)-log(0.267647))) // 0.2s/frame, 1000 frames, bin8, 200^2 pixels.
//t_rs=alog(log(0.26547)+p/99*(log(0.26547*1000)-log(0.26547))) // 0.2s/frame, 1000 frames, bin4, 350^2 pixels.
//t_rs=alog(log(0.005)+p/99*(log(0.005*12000)-log(0.005))) // BNL K2 camera, 400 f/s. Combine two frames together. 0.005 s.
t_rs=alog(log(0.2363)+p/99*(log(0.2363*1000)-log(0.2363))) // ERC, 0.1s per frame, 350^2 pixels.
//g2t_rs[]=g2t[t_rs[p]/0.267647]
//g2t_rs[]=g2t[t_rs[p]/0.26547]
//g2t_rs[]=g2t[t_rs[p]/0.005]
g2t_rs[]=g2t[t_rs[p]/0.2363]
//t_rs=alog(log(0.0584)+p/99*(log(0.0584*2100)-log(0.0584))) // BNL Orius camera, 0.05 s.
//g2t_rs[]=g2t[t_rs[p]/0.0584]
duplicate/o g2t, $g2tname
duplicate/o g2t_rs, $g2t_rsname
killwaves g2t, g2t_rs, g2t_temp
print count
end
Function tau_k_map(g2t_map, name, samplepts) //Fitting to extract tau from every pixels. "samplepts" refers to number of points in g2_rs.
wave g2t_map
string name
variable samplepts
variable i//, j
variable M=dimsize(g2t_map,0), N=dimsize(g2t_map, 1)
//string fitname, g2FitName, fitXname//, parameterName, g2NormName, , fitNormname,
string tau_mapname="tau_map_"+name
string tauerr_mapname="tauerr_map_"+name
string beta_mapname="beta_map_"+name
string betaerror_mapname="betaerr_map_"+name
string A_mapname="A_map_"+name
string Aerror_mapname="Aerr_map_"+name
//string g2tNormmapName="g2_norm_map_"+name
string rsname="rs_map"+name
string fitmapName="fit_map_"+name
//string fitXmapName="fitX_map_"+name
string t_rsName="t_rs_"+name
//string fitNormmapName="fit_norm_map_"+name
string rangeName="fitRange_"+name
make/o/n=(N) t_map, tauerr_map, beta_map, betaerror_map, A_map, Aerror_map, range
make/o/n=(M) g2t_temp
make/o/n=(samplepts) g2t_rs, t_rs
//SetScale/P x 0, 0.948,"", g2t_temp //STEM image series, 0.84 s per frame, total 0.948 s per frame.
//SetScale/P x 0, 0.0025,"", g2t_temp
//SetScale/P x 0, 0.2276,"", g2t_temp
SetScale/P x 0, 0.27716,"", g2t_temp
//duplicate/o g2t_map fit_map//, g2tNorm_map, fitNorm_map
//g2tNorm_map=0
make/o/n=(200, N) fit_map//, fitX_map
fit_map=0
//fitX_map=0
make/o/n=(samplepts, N) rs_map=0
//fitNorm_map=0
for (i=0; i<N; i+=1)
g2t_temp[]=g2t_map[p][i]
resampleg2(g2t_temp, "temp", samplepts)
wave g2t_rs_temp=$"g2t_rs_temp"
g2t_rs=g2t_rs_temp
rs_map[][i]=g2t_rs[p]
findlevel /edge=2/p/q g2t_rs, 1
//variable V_levelX
Make/D/N=3/O W_coef
W_coef[0] = {g2t_rs[0]-1, t_rs[V_levelX],1}
FuncFit/NTHR=0/q relaxationfunc3 W_coef g2t_rs[0, round(V_levelX)] /X=t_rs/D
wave fit_g2t_rs=$"fit_g2t_rs"
//wave fitX_g2t_rs=$"fitX_g2t_rs"
wave W_sigma=$"W_sigma"
A_map[i]=W_coef[0]
Aerror_map[i]=W_sigma[0]
t_map[i]=W_coef[1]
tauerr_map[i]=W_sigma[1]
beta_map[i]=W_coef[2]
betaerror_map[i]=W_sigma[2]
fit_map[][i]=fit_g2t_rs[p]
//fitX_map[][i]=fitX_g2t_rs[p]
range[i]=round(V_levelX)
endfor
//j=0
//do
//j=j+1
//while (g2t_temp[j]>g2t_temp[j+1]*0.993)
//range[i]=j
//if (j<10||g2t_temp[j]>1)
//t_map[i]=nan
//terror_map[i]=nan
//beta_map[i]=nan
//betaerror_map[i]=nan
//A_map[i]=nan
//Aerror_map[i]=nan
//g2tNorm_map[][i]=nan
//fit_map[][i]=nan
//fitNorm_map[][i]=nan
//else
//fitname=num2istr(i)
//g2NormName="g2_norm"+fitname
//g2FitName="fit_"+fitname
//fitNormName="fit_norm"+fitname
//parameterName="parameter_"+fitname
//fitg2_noGraph(g2t_temp, range, fitname)
//wave par=$parameterName
//t_map[i]=par[0]
//terror_map[i]=par[1]
//beta_map[i]=par[2]
//betaerror_map[i]=par[3]
//A_map[i]=par[4]
//Aerror_map[i]=par[5]
//wave g2tNorm=$g2NormName
//g2tNorm_map[][i]=g2tNorm[p]
//wave g2fit=$g2FitName
//fit_map[][i]=g2fit[p]
//wave fitNorm=$fitNormName
//fitNorm_map[][i]=fitNorm[p]
//endif
//killwaves par, g2tNorm, g2fit, fitNorm, $parameterName, $g2NormName, $g2FitName, $fitNormName
//endfor
duplicate/o t_map $tau_mapname
duplicate/o tauerr_map $tauerr_mapname
duplicate/o beta_map $beta_mapname
duplicate/o betaerror_map $betaerror_mapname
duplicate/o A_map $A_mapname
duplicate/o Aerror_map $Aerror_mapname
//duplicate/o g2tNorm_map $g2tNormmapName
duplicate/o fit_map $fitmapName
//duplicate/o fitX_map $fitXmapName
duplicate/o t_rs $t_rsName
//duplicate/o fitNorm_map $fitNormmapName
duplicate/o range $rangeName
killwaves g2t_temp, t_map, beta_map, betaerror_map, A_map, Aerror_map, fit_map, tauerr_map, W_coef, W_sigma, g2t_rs_temp, g2t_rs, t_rs, fit_g2t_rs, t_rs, range//, fitX_map, fitX_g2, par, g2tNorm, g2fit, fitNorm, g2tNorm_map, fit_map, fitNorm_map,range
end
Function fitg2_noGraph(g2t, endpoint, name)
wave g2t
variable endpoint
string name
variable A, dA, a1, b1, da1, db1, tau1, dtau1, b_1, db_1, tau, dtau, ptau
string fitname="fit_"+name
//string fit1name="fit1_"+name
string parametername="parameter_"+name
string normname="g2_norm"+name
string fitnormname="fit_norm"+name
duplicate/o g2t temp
redimension/n=(endpoint+1) temp
Make/D/N=3/O W_coef
W_coef[0] = {1,10,1}
FuncFit/Q/NTHR=0 relaxationfunc3 W_coef temp
A=W_coef[0]
tau1=W_coef[1]
b_1=W_coef[2]
wave W_sigma=$"W_sigma"
dA=W_sigma[0]
dtau1=W_sigma[1]
db_1=W_sigma[2]
//print A, dA
//duplicate/o $"fit_temp" $fit1name
duplicate/o temp, y1
y1[]=ln(-ln((temp[p]-1)/A)/2)
make/o/n=(endpoint+1) x1
//x1[1,endpoint]=ln(3.07*p)
//x1[1,endpoint]=ln(1.574*p)
//x1[1,endpoint]=ln(0.2276*p)
x1[1,endpoint]=ln(0.2363*p)
//x1[1,endpoint]=ln(2.1414*p)
//Display y1 vs x1
CurveFit/Q/M=2/W=0 line, y1[0,endpoint]/X=x1[0,endpoint]/D
a1=W_coef[0]
b1=W_coef[1]
da1=W_sigma[0]
db1=W_sigma[1]
tau=exp(-a1/b1)
dtau=tau/b1^2*(a1*db1-da1*b1)
duplicate/o temp fit
//fit[]=1+A*exp(-2*(3.07*p/tau)^b1)
//fit[]=1+A*exp(-2*(1.574*p/tau)^b1)
fit[]=1+A*exp(-2*(0.2276*p/tau)^b1)
//fit[]=1+A*exp(-2*(2.1414*p/tau)^b1)
//display temp
//ModifyGraph log(bottom)=1
//appendtograph fit_temp
//AppendToGraph fit
//print tau, dtau
//print b1, db1
duplicate/o g2t temp, temp_norm
temp_norm[]=(temp[p]-1)/A
duplicate/o fit fit_norm
fit_norm[]=(fit[p]-1)/A
//display temp_norm
//ModifyGraph log(bottom)=1
//appendtograph fit_norm
//ptau=round(tau/3.07)
//ptau=round(tau/1.574)
ptau=round(tau/0.2276)
//ptau=round(tau/2.1414)
//print temp_norm[ptau]
//if (temp_norm[ptau]>exp(-2)*1.01)
//print "suspicisous fitting"
//else
//print "good fitting"
//endif
duplicate/o fit $fitname
duplicate/o temp_norm $normname
duplicate/o fit_norm $fitnormname
make/o/n=(10) parameter
parameter[0]=tau
parameter[1]=dtau
parameter[2]=b1
parameter[3]=db1
parameter[4]=A
parameter[5]=dA
parameter[6]=tau1
parameter[7]=dtau1
parameter[8]=b_1
parameter[9]=db_1
duplicate/o parameter $parametername
killwaves temp, x1, y1, W_coef, W_sigma, fit, fit_temp, temp_norm, fit_norm, parameter
end
Function displayG2t(g2t_map, name)
wave g2t_map
string name
variable i
variable N=dimsize(g2t_map, 1)
duplicate/o g2t_map g2t_0
redimension/n=(-1,0) g2t_0
g2t_0[]=g2t_map[p][0]
string g2t_name="g2t_"+name+"_"+num2istr(0)
duplicate/o g2t_0 $g2t_name
Display $g2t_name
ModifyGraph log(bottom)=1
for (i=1; i<N; i+=1)
duplicate/o g2t_0 g2t_temp
g2t_temp[]=g2t_map[p][i]
g2t_name="g2t_"+name+"_"+num2istr(i)
duplicate/o g2t_temp $g2t_name
AppendToGraph $g2t_name
endfor
killwaves g2t_temp
end
Function tau_map(g2t_map, A0, B0, tau0,fitstart,fitend) // under construction.
wave g2t_map
variable A0, B0, tau0,fitstart,fitend
variable pixelsize=dimsize(g2t_map, 1), tp=dimsize(g2t_map,0)
variable i
string Aname="A_"+nameofwave(data) // name is too long.
string Bname="B_"+nameofwave(data)
string tauname="tau_"+nameofwave(data)
make/o/n=(pixelsize) tau_temp=0, A_temp=0, B_temp=0
make/o/n=(tp) g2t_temp=0
Make/o/D/N=3/O W_coef
for (i=0; i<pixelsize; i+=1)
g2t_temp[]=g2t_map[p][i]
W_coef[0] = {A0, B0, tau0}
Funcfit/NTHR=0/Q relaxationfunc W_coef, g2t_temp[fitstart,fitend]
tau_temp[i]=W_coef[2]
A_temp[i]=W_coef[0]
B_temp[i]=W_coef[1]
endfor
tau_temp=tau_temp/3
duplicate/o tau_temp $tauname
duplicate/o A_temp $Aname
duplicate/o B_temp $Bname
killwaves tau_temp, A_temp, B_temp, g2t_temp
end
Function correlatefunc_k_map_BNLOrius(data, k, bin, xcenter, ycenter, xa, ya, xb, xc, yc, yd, xe, ye) // <I(t')>^2 from I(t') only. binning pixels of numbers bin^2.
// BNL Orius data
wave data
variable k, bin, xcenter, ycenter, xa, ya, xb, xc, yc, yd, xe, ye
// Hardware bin4, software bin2. Camera length 380mm.
variable r=round(k/0.00352388/2), tp = DimSize(data, 2), neighbour=round((bin-1)/2)
variable xmin, xmax, y1, y2, temp, pixelsize=1000
variable kbc=(yc-ya)/(xc-xb), kde=(ye-yd)/(xe-xc)
make/o/n=(tp) add_td=0
make/o/n=(tp,pixelsize) g2t_map=0
make/o/n=(pixelsize) x_map, y_map, I_ave
variable x, i, j
variable pcount=0
string name="_"+nameofwave(data)+"_"+num2str(k)+"_bin"+num2str(bin)
string g2t_mapname="g2t_map"+name
string g2tname="g2t"+name
//string g2t_rsname="g2t_rs"+name
string x_mapname="x_map"+name
string y_mapname="y_map"+name
string I_avename="I_ave"+name
// Find the circular points on diffraction patterns with the reciprocal space vector k.
xmin=xcenter-r+1
xmax=xcenter+r
for(x=xmin; x<xmax; x+=1)
temp=round(sqrt(r^2-(xcenter-x)^2))
y1=ycenter+temp
y2=ycenter-temp
// Remove beam stop shadow.
if (x>xe && x<xa && y1>ye && y1<ya)
pcount=pcount
elseif (x>xb && x<xe && y1>yd && y1<ya)
pcount=pcount
elseif (x>xc && x<xb && y1>yd && y1<yc)
pcount=pcount
elseif (x>xc && x<xb && y1>yc && y1<kbc*(x-xc)+yc)
pcount=pcount
elseif (x>xc && x<xe && y1>kde*(x-xc)+yd && y1<yd)
pcount=pcount
else
make/o/n=(tp) bin_average=0
for(i=0-neighbour; i<neighbour+1; i+=1)
for(j=0-neighbour; j<neighbour+1; j+=1)
Imagetransform/beam={(x+i), (y1+j)} getbeam data
wave W_beam = $"W_beam"
bin_average=bin_average+W_beam
endfor
endfor
W_beam=bin_average/bin^2
//ave=mean(W_beam)
add_td=0
for (j=0;j<tp;j+=1)
for (i=0;i<(tp-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_map[][pcount]=(tp-p)*add_td[p]/(sum(W_beam,0,tp-p-1))^2
x_map[pcount]=x
y_map[pcount]=y1
I_ave[pcount]=mean(W_beam)
pcount=pcount+1
endif
if (x>xe && x<xa && y2>ye && y2<ya)
pcount=pcount
elseif (x>xb && x<xe && y2>yd && y2<ya)
pcount=pcount
elseif (x>xc && x<xb && y2>yd && y2<yc)
pcount=pcount
elseif (x>xc && x<xb && y2>yc && y2<kbc*(x-xc)+yc)
pcount=pcount
elseif (x>xc && x<xe && y2>kde*(x-xc)+yd && y2<yd)
pcount=pcount
else
make/o/n=(tp) bin_average=0
for(i=0-neighbour; i<neighbour+1; i+=1)
for(j=0-neighbour; j<neighbour+1; j+=1)
Imagetransform/beam={(x+i), (y2+j)} getbeam data
wave W_beam = $"W_beam"
bin_average=bin_average+W_beam
endfor
endfor
W_beam=bin_average/bin^2
//ave=mean(W_beam)
add_td=0
for (j=0;j<tp;j+=1)
for (i=0;i<(tp-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_map[][pcount]=(tp-p)*add_td[p]/(sum(W_beam,0,tp-p-1))^2
x_map[pcount]=x
y_map[pcount]=y2
I_ave[pcount]=mean(W_beam)
pcount=pcount+1
endif
endfor
redimension/n=(-1, pcount) g2t_map
redimension/n=(pcount) x_map, y_map, I_ave
SetScale/P x 0, 0.0584,"", g2t_map //Orius, hardware bin4, 400*410 pixels, 0.05s
//SetScale/P x 0,0.34,"", g2t_map time-series spectrum imaging, 0.1s per frame
//SetScale/P x 0,1.07,"", g2t_map //CCD serach, 1s per frame
//SetScale/P x 0,3.07,"", g2t_map
//SetScale/P x 0,0.171,"", g2t_map
//SetScale/P x 0,2.075,"", g2t_map
//SetScale/P x 0,1.574,"", g2t_map //CCD search, 1.5 s per frame
//SetScale/P x 0, 0.2276,"", g2t_map //CCD search, ERC, 0.1 s per frame, Nov. 2013
//SetScale/P x 0, 0.2363,"", g2t_map //CCD search, ERC, 0.1 s per frame, March 2013
//SetScale/P x 0, 2.1414,"", g2t_map //CCD search, ERC, 2 s per frame
imagetransform sumallrows g2t_map
duplicate/o W_sumRows g2t
g2t=g2t/pcount
SetScale/P x 0,0.0584,"", g2t
//SetScale/P x 0,0.34,"", g2t
//SetScale/P x 0,1.07,"", g2t
//SetScale/P x 0,3.07,"", g2t //CCD search, 3 s per frame.
//SetScale/P x 0,0.171,"", g2t //CCD search, 0.1 s per frame
//SetScale/P x 0,2.075,"", g2t //CCD search, 2 s per frame.
//SetScale/P x 0,1.574,"", g2t //CCD search, 1.5 s per frame.
//SetScale/P x 0,0.2276,"", g2t
//SetScale/P x 0,0.2363,"", g2t
//SetScale/P x 0, 2.1414,"", g2t
//make/o/n=(100) g2t_rs, t_rs
//t_rs=alog(log(0.0584)+p/99*(log(0.0584*2100)-log(0.0584)))
//g2t_rs[]=g2t[t_rs[p]/0.0584]
duplicate/o g2t_map, $g2t_mapname
duplicate/o g2t, $g2tname
//duplicate/o g2t_rs, $g2t_rsname
duplicate/o x_map, $x_mapname
duplicate/o y_map, $y_mapname
duplicate/o I_ave, $I_avename
killwaves g2t_map, g2t, x_map, y_map, I_ave, add_td, bin_average
print pcount
end
Function correlatefunc_k_map_BNL(data, k, bin, xcenter, ycenter, xa, ya, yb, xc, yc, xd, xe, ye) // <I(t')>^2 from I(t'), I(t')I(t'+t), and I all. Binning pixels of numbers bin^2.
// BNL K2 data
wave data
variable k, bin, xcenter, ycenter, xa, ya, yb, xc, yc, xd, xe, ye
variable r=k/0.008052248 // Bin 8. Camera length 380mm.
//variable r=k/0.01006531 // Bin 10. Camera length 380mm.
variable tp = DimSize(data, 2), neighbour=round((bin-1)/2)
variable samplesize=round(2*pi*r)
variable kbc=(yc-yb)/(xc-xa), kde=(ye-yc)/(xe-xd)
make/o/n=(tp) add_td=0
make/o/n=(tp,samplesize) g2t_tp_map=0, g2t_tpt_map=0, g2t_ta_map=0
make/o/n=(samplesize) x_map, y_map, I_ave
make/o/n=(samplesize) theta, xp, yp
theta[]=p*2*pi/samplesize
xp=round(xcenter+r*cos(theta))
yp=round(ycenter+r*sin(theta))
variable i, j, ave
variable pcount=0
string name="_"+nameofwave(data)+"_"+num2str(k)+"_bin"+num2str(bin)
string g2t_tp_mapname="g2tmap_tp"+name
string g2t_tpt_mapname="g2tmap_tpt"+name
string g2t_ta_mapname="g2tmap_ta"+name
string g2t_tp_name="g2t_tp"+name
string g2t_tpt_name="g2t_tpt"+name
string g2t_ta_name="g2t_ta"+name
string x_mapname="x_map"+name
string y_mapname="y_map"+name
string I_avename="I_ave"+name
// Find the circular points on diffraction patterns with the reciprocal space vector k.
for(k=0; k<samplesize; k+=1)
// Remove beam stop shadow
if (xp[k]>xc && xp[k]<xd && yp[k]>ya && yp[k]<yc)
pcount=pcount
elseif (xp[k]>xa && xp[k]<xc && yp[k]>ya && yp[k]<yb)
pcount=pcount
elseif (xp[k]>xa && xp[k]<xc && yp[k]>yb && yp[k]<kbc*(xp[k]-xa)+yb)
pcount=pcount
elseif (xp[k]>xd && xp[k]<xe && yp[k]>ya && yp[k]<ye)
pcount=pcount
elseif (xp[k]>xd && xp[k]<xe && yp[k]>ye && yp[k]<kde*(xp[k]-xd)+yc)
pcount=pcount
elseif(xp[k]>xa && xp[k]<xe && yp[k]>ya && yp[k]<yb)
pcount=pcount
else
make/o/n=(tp) bin_average=0
for(i=0-neighbour; i<neighbour+1; i+=1)
for(j=0-neighbour; j<neighbour+1; j+=1)
Imagetransform/beam={(xp[k]+i), (yp[k]+j)} getbeam data
wave W_beam = $"W_beam"
bin_average=bin_average+W_beam
endfor
endfor
W_beam=bin_average/bin^2
ave=mean(W_beam)
add_td=0
for (j=0;j<tp;j+=1)
for (i=0;i<(tp-j);i+=1)
add_td[j]=add_td[j]+W_beam[i]*W_beam[i+j]
endfor
endfor
g2t_tp_map[][pcount]=(tp-p)*add_td[p]/(sum(W_beam,0,tp-p-1))^2
g2t_tpt_map[][pcount]=(tp-p)*add_td[p]/sum(W_beam,0,tp-p-1)/sum(W_beam,p,tp-1)
g2t_ta_map[][pcount]=add_td[p]/(tp-p)/ave^2
x_map[pcount]=xp[k]
y_map[pcount]=yp[k]
I_ave[pcount]=ave
pcount=pcount+1
endif
endfor
redimension/n=(-1, pcount) g2t_tp_map, g2t_tpt_map, g2t_ta_map
redimension/n=(pcount) x_map, y_map, I_ave
SetScale/P x 0, 0.005,"", g2t_tp_map, g2t_tpt_map, g2t_ta_map //K2, 400 frames/s, adding 2 frames together
imagetransform sumallrows g2t_tp_map
duplicate/o W_sumRows g2t
g2t=g2t/pcount
SetScale/P x 0,0.005,"", g2t
duplicate/o g2t_tp_map, $g2t_tp_mapname
duplicate/o g2t, $g2t_tp_name
imagetransform sumallrows g2t_tpt_map
duplicate/o W_sumRows g2t