-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths_range_m2q_R20_08089.py
700 lines (455 loc) · 21.4 KB
/
s_range_m2q_R20_08089.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
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# standard imports
import numpy as np
import matplotlib.pyplot as plt
# custom imports
import apt_fileio
import plotting_stuff
import initElements_P3
import peak_param_determination as ppd
from histogram_functions import bin_dat
# Read in data
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\180821_GaN_A71\R20_07094-v03.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01.epos" # Mg doped
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07148-v01_vbmq_corr.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07248-v01.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07249-v01.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\R20_07250-v01.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\190421_AlGaN50p7_A83\R20_07209-v01.epos"
#
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\181210_D315_A74\R20_07167-v03.epos"
#fn = r"\\cfs2w.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\181210_D315_A74\R20_07148-v02.epos"
#fn = r"\\cfs2w.campus.nist.gov\647\NIST_Projects\EUV_APT_IMS\BWC\GaN epos files\181204_InGaNQW_A73\R20_07144-v02.epos"
fn = r"C:\Users\bwc\Documents\NetBeansProjects\R20_08089\recons\recon-v01\default\R20_08089-v01.epos"
fn = fn[:-5]+'_vbm_corr.epos'
epos = apt_fileio.read_epos_numpy(fn)
#epos = epos[epos.size//2:-1]
# Plot m2q vs event index and show the current ROI selection
roi_event_idxs = np.arange(300000,epos.size)
#roi_event_idxs = np.arange(epos.size)
ax = plotting_stuff.plot_m2q_vs_time(epos['m2q'],epos,fig_idx=1)
ax.plot(roi_event_idxs[0]*np.ones(2),[0,1200],'--k')
ax.plot(roi_event_idxs[-1]*np.ones(2),[0,1200],'--k')
ax.set_title('roi selected to start analysis')
epos = epos[roi_event_idxs]
# Compute some extra information from epos information
LASER_REP_RATE = 25000.0
wall_time = np.cumsum(epos['pslep'])/LASER_REP_RATE
pulse_idx = np.arange(0,epos.size)
isSingle = np.nonzero(epos['ipp'] == 1)
# Define peaks to range
ed = initElements_P3.initElements()
# N Ga Mg Da
# Define possible peaks
pk_data = np.array( [ (1, 0, 0, ed['N'].isotopes[14][0]/2),
(1, 0, 0, ed['N'].isotopes[14][0]/1),
(1, 0, 0, ed['N'].isotopes[15][0]/1),
(1, 0, 0, ed['N'].isotopes[15][0]+ed['H'].isotopes[1][0]),
(0, 1, 0, ed['Ga'].isotopes[69][0]/3),
(0, 1, 0, ed['Ga'].isotopes[71][0]/3),
(2, 0, 0, ed['N'].isotopes[14][0]*2),
(2, 0, 0, ed['N'].isotopes[14][0]+ed['N'].isotopes[15][0]),
(2, 0, 0, ed['N'].isotopes[14][0]+ed['N'].isotopes[15][0]+ed['H'].isotopes[1][0]),
(0, 1, 0, ed['Ga'].isotopes[69][0]/2),
(0, 1, 0, ed['Ga'].isotopes[71][0]/2),
(1, 1, 0, (ed['N'].isotopes[14][0] + ed['Ga'].isotopes[69][0])/2),
(3, 0, 0, ed['N'].isotopes[14][0]*3),
(1, 1, 0, (ed['N'].isotopes[14][0] + ed['Ga'].isotopes[71][0])/2),
(3, 1, 0, (ed['Ga'].isotopes[69][0]+3*ed['N'].isotopes[14][0])/2),
(3, 1, 0, (ed['Ga'].isotopes[71][0]+3*ed['N'].isotopes[14][0])/2),
(0, 1, 0, ed['Ga'].isotopes[69][0]),
(0, 1, 0, ed['Ga'].isotopes[71][0]),
(0, 1, 0, ed['Ga'].isotopes[71][0]+ed['H'].isotopes[1][0]),
(0, 0, 1, ed['In'].isotopes[113][0]/2),
(0, 0, 1, ed['In'].isotopes[115][0]/2)
],
dtype=[('N','i4'),('Ga','i4'),('In','i4'),('m2q','f4')] )
## N Ga Al Da
## Define possible peaks
#
#pk_data = np.array( [ (1, 0, 0, ed['N'].isotopes[14][0]/2),
# (0, 0, 1, ed['Al'].isotopes[27][0]/3),
# (0, 0, 1, ed['Al'].isotopes[27][0]/2),
# (1, 0, 0, ed['N'].isotopes[14][0]/1),
# (1, 0, 0, ed['N'].isotopes[15][0]/1),
# (1, 0, 0, ed['N'].isotopes[15][0]+ed['H'].isotopes[1][0]),
# (1, 0, 1, (ed['N'].isotopes[14][0]+ed['Al'].isotopes[27][0])/2),
# (0, 1, 0, ed['Ga'].isotopes[69][0]/3),
# (0, 1, 0, ed['Ga'].isotopes[71][0]/3),
# (0, 0, 1, ed['Al'].isotopes[27][0]/1),
# (2, 0, 0, ed['N'].isotopes[14][0]*2),
# (2, 0, 0, ed['N'].isotopes[14][0]+ed['N'].isotopes[15][0]),
# (2, 0, 0, ed['N'].isotopes[14][0]+ed['N'].isotopes[15][0]+ed['H'].isotopes[1][0]),
# (0, 1, 0, ed['Ga'].isotopes[69][0]/2),
# (0, 1, 0, ed['Ga'].isotopes[71][0]/2),
# (1, 1, 0, (ed['N'].isotopes[14][0] + ed['Ga'].isotopes[69][0])/2),
# (3, 0, 0, ed['N'].isotopes[14][0]*3),
# (1, 1, 0, (ed['N'].isotopes[14][0] + ed['Ga'].isotopes[71][0])/2),
# (3, 1, 0, (ed['Ga'].isotopes[69][0]+3*ed['N'].isotopes[14][0])/2),
# (3, 1, 0, (ed['Ga'].isotopes[71][0]+3*ed['N'].isotopes[14][0])/2),
# (0, 1, 0, ed['Ga'].isotopes[69][0]),
# (0, 1, 0, ed['Ga'].isotopes[71][0]),
# (0, 1, 0, ed['Ga'].isotopes[71][0]+ed['H'].isotopes[1][0])
# ],
# dtype=[('N','i4'),('Ga','i4'),('Al','i4'),('m2q','f4')] )
# Define which peaks to use for CSR calcs
Ga1p_m2qs = [ed['Ga'].isotopes[69][0], ed['Ga'].isotopes[71][0]]
Ga2p_m2qs = [ed['Ga'].isotopes[69][0]/2, ed['Ga'].isotopes[71][0]/2]
Ga1p_idxs = [np.argmin(np.abs(m2q-pk_data['m2q'])) for m2q in Ga1p_m2qs]
Ga2p_idxs = [np.argmin(np.abs(m2q-pk_data['m2q'])) for m2q in Ga2p_m2qs]
# Range the peaks
pk_params = ppd.get_peak_ranges(epos,pk_data['m2q'],peak_height_fraction=0.1)
# Determine the global background
glob_bg_param = ppd.get_glob_bg(epos['m2q'])
# Count the peaks, local bg, and global bg
cts = ppd.do_counting(epos,pk_params,glob_bg_param)
# Test for peak S/N and throw out craptastic peaks
B = np.max(np.c_[cts['local_bg'][:,None],cts['global_bg'][:,None]],1)[:,None]
T = cts['total'][:,None]
S = T-B
std_S = np.sqrt(T+B)
# Make up a threshold for peak detection... for the most part this won't matter
# since weak peaks don't contribute to stoichiometry much... except for Mg!
is_peak = S>2*np.sqrt(2*B)
for idx, ct in enumerate(cts):
if not is_peak[idx]:
for i in np.arange(len(ct)):
ct[i] = 0
# Calculate compositions
compositions = ppd.do_composition(pk_data,cts)
ppd.pretty_print_compositions(compositions,pk_data)
print('Total Ranged Ions: '+str(np.sum(cts['total'])))
print('Total Ranged Local Background Ions: '+str(np.sum(cts['local_bg'])))
print('Total Ranged Global Background Ions: '+str(np.sum(cts['global_bg'])))
print('Total Ions: '+str(epos.size))
print('Overall CSR (no bg) : '+str(np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])))
print('Overall CSR (local bg) : '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['local_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['local_bg'][Ga1p_idxs]))))
print('Overall CSR (global bg): '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['global_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['global_bg'][Ga1p_idxs]))))
# Plot all the things
xs, ys = bin_dat(epos['m2q'],user_roi=[0.5, 120],isBinAligned=True)
#ys_sm = ppd.do_smooth_with_gaussian(ys,10)
ys_sm = ppd.moving_average(ys,10)
glob_bg = ppd.physics_bg(xs,glob_bg_param)
fig = plt.figure(num=100)
fig.clear()
ax = fig.gca()
ax.plot(xs,ys_sm,label='hist')
ax.plot(xs,glob_bg,label='global bg')
ax.set(xlabel='m/z (Da)', ylabel='counts')
ax.grid()
fig.tight_layout()
fig.canvas.manager.window.raise_()
ax.set_yscale('log')
ax.legend()
for idx,pk_param in enumerate(pk_params):
if is_peak[idx]:
ax.plot(np.array([1,1])*pk_param['pre_rng'] ,np.array([0.5,(pk_param['amp']+pk_param['off'])]),'k--')
ax.plot(np.array([1,1])*pk_param['post_rng'] ,np.array([0.5,(pk_param['amp']+pk_param['off'])]),'k--')
ax.plot(np.array([1,1])*pk_param['pre_bg_rng'] ,np.array([0.5,(pk_param['amp']+pk_param['off'])]),'m--')
ax.plot(np.array([1,1])*pk_param['post_bg_rng'] ,np.array([0.5,(pk_param['amp']+pk_param['off'])]),'m--')
ax.plot(np.array([pk_param['pre_bg_rng'],pk_param['post_bg_rng']]) ,np.ones(2)*pk_param['loc_bg'],'g--')
else:
ax.plot(np.array([1,1])*pk_param['x0_mean_shift'] ,np.array([0.5,(pk_param['amp']+pk_param['off'])]),'r--')
plt.pause(0.1)
#### END BASIC ANALYSIS ####
import sys
sys.exit()
#### START EXPLORATORY ANALYSIS ####
epos = apt_fileio.read_epos_numpy(fn)
the_rois = [[300,391],
[415,510],
[530,622],
[654,750],
[767,865],
[890,1060],
[1100,1305],
[1330,1630],
[1670,2050],
[2090,2320],
[2365,2550]]
labs = ["1x200","2x200","3x200","1x1000","1x2000","1x1000+1x200","1x2000 r","1x1000 r",
"3x200 r","2x200 r","1x200 r"]
full_bg_est = epos['m2q'][(epos['m2q']>125) & (epos['m2q']<150)].size
fig = plt.figure(num=100)
fig.clear()
ax = fig.gca()
counter = 0
for the_roi in the_rois:
print('######################################################')
print(str(the_roi))
sub_epos = epos[(1000*the_roi[0]):(1000*the_roi[1])]
sub_bg_est = sub_epos['m2q'][(sub_epos['m2q']>125) & (sub_epos['m2q']<150)].size
# Count the peaks, local bg, and global bg
cts = ppd.do_counting(sub_epos,pk_params,glob_bg_param*(sub_bg_est/full_bg_est))
# Calculate compositions
compositions = ppd.do_composition(pk_data,cts)
ppd.pretty_print_compositions(compositions,pk_data)
print('Total Ranged Ions: '+str(np.sum(cts['total'])))
print('Total Ranged Local Background Ions: '+str(np.sum(cts['local_bg'])))
print('Total Ranged Global Background Ions: '+str(np.sum(cts['global_bg'])))
print('Total Ions: '+str(epos.size))
print('Overall CSR (no bg) : '+str(np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])))
print('Overall CSR (local bg) : '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['local_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['local_bg'][Ga1p_idxs]))))
print('Overall CSR (global bg): '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['global_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['global_bg'][Ga1p_idxs]))))
print('######################################################')
# Plot all the things
xs, ys = bin_dat(sub_epos['m2q'],user_roi=[0.5, 120],isBinAligned=True)
#ys_sm = ppd.do_smooth_with_gaussian(ys,10)
ys_sm = ppd.moving_average(ys,30)
ax.plot(xs,ys_sm*(10**counter),label=labs[counter])
# plt.pause(1)
counter +=1
ax.set(xlabel='m/z (Da)', ylabel='counts')
ax.grid()
fig.tight_layout()
fig.canvas.manager.window.raise_()
ax.set_yscale('log')
ax.legend(labs)
epos = apt_fileio.read_epos_numpy(fn)
the_rois = [[890,1060],
[1100,1305],
[1330,1630],
[1670,2050],
[2090,2320],
[2365,2550]]
labs = ["1x1000+1x200","1x2000 r","1x1000 r",
"3x200 r","2x200 r","1x200 r"]
full_bg_est = epos['m2q'][(epos['m2q']>125) & (epos['m2q']<150)].size
fig = plt.figure(num=100)
fig.clear()
ax = fig.gca()
counter = 0
for the_roi in the_rois:
print('######################################################')
print(str(the_roi))
sub_epos = epos[(1000*the_roi[0]):(1000*the_roi[1])]
sub_bg_est = sub_epos['m2q'][(sub_epos['m2q']>125) & (sub_epos['m2q']<150)].size
# Count the peaks, local bg, and global bg
cts = ppd.do_counting(sub_epos,pk_params,glob_bg_param*(sub_bg_est/full_bg_est))
# Calculate compositions
compositions = ppd.do_composition(pk_data,cts)
ppd.pretty_print_compositions(compositions,pk_data)
print('Total Ranged Ions: '+str(np.sum(cts['total'])))
print('Total Ranged Local Background Ions: '+str(np.sum(cts['local_bg'])))
print('Total Ranged Global Background Ions: '+str(np.sum(cts['global_bg'])))
print('Total Ions: '+str(epos.size))
print('Overall CSR (no bg) : '+str(np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])))
print('Overall CSR (local bg) : '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['local_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['local_bg'][Ga1p_idxs]))))
print('Overall CSR (global bg): '+str((np.sum(cts['total'][Ga2p_idxs])-np.sum(cts['global_bg'][Ga2p_idxs]))/(np.sum(cts['total'][Ga1p_idxs])-np.sum(cts['global_bg'][Ga1p_idxs]))))
print('######################################################')
# Plot all the things
xs, ys = bin_dat(sub_epos['m2q'],user_roi=[0.5, 120],isBinAligned=True)
#ys_sm = ppd.do_smooth_with_gaussian(ys,10)
ys_sm = ppd.moving_average(ys,30)
ys_sc = (ys_sm+0.1)/np.sum(ys_sm)
# ax.plot(xs,ys_sc*(10**-counter),label=labs[counter])
ax.plot(xs,ys_sc,label=labs[counter])
# plt.pause(1)
counter +=1
ax.set(xlabel='m/z (Da)', ylabel='counts')
ax.grid()
fig.tight_layout()
fig.canvas.manager.window.raise_()
ax.set_yscale('log')
ax.legend(labs)
Ga_idx =0
fig = plt.figure(num=1000)
fig.clear()
ax = fig.gca()
ax.plot(epos['v_dc'])
sub_epos = epos[140000:203000]
r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2)
sub_idxs = np.nonzero(r>15)
cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param)
csr = np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])
Ga_comp = ppd.do_composition(pk_data,cts)[0][0][Ga_idx]
Ga_comp_std = ppd.do_composition(pk_data,cts)[0][1][Ga_idx]
#r = np.sqrt(epos['x_det']**2+epos['y_det']**2)
#
#ax.plot(r,epos['v_dc'],',')
#
#dv = np.r_[0,np.diff(epos['v_dc'])]
#
#ax.plot(dv)
#for idx,pt in enumerate(dv):
# if pt!=0:
# ax.plot([idx,idx],[0,pt],'r')
#
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=8, init='k-means++', max_iter=300, n_init=10, random_state=0)
kmeans.fit(epos['v_dc'].reshape(-1, 1))
fig = plt.figure(num=1000)
fig.clear()
ax = fig.gca()
ax.plot(kmeans.labels_)
ax.plot(epos['v_dc']/np.max(epos['v_dc'])*np.max(kmeans.labels_))
# Slice and dice the data in wall_time
idxs_list = []
for label in np.unique(kmeans.labels_):
idxs_list.append(np.nonzero(kmeans.labels_ == label))
# Count and compositions
csr = []
Ga_comp = []
Ga_comp_std = []
keys = list(pk_data.dtype.fields.keys())
keys.remove('m2q')
Ga_idx = keys.index('Ga')
for loop_idx, idxs in enumerate(idxs_list):
sub_epos = epos[idxs]
r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2)
sub_idxs = np.nonzero(r>15)
cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param)
csr.append(np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs]))
Ga_comp.append(ppd.do_composition(pk_data,cts)[0][0][Ga_idx])
Ga_comp_std.append(ppd.do_composition(pk_data,cts)[0][1][Ga_idx])
for loop_idx, idxs in enumerate(idxs_list):
sub_epos = epos[idxs]
r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2)
sub_idxs = np.nonzero(r<15)
cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param)
csr.append(np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs]))
Ga_comp.append(ppd.do_composition(pk_data,cts)[0][0][Ga_idx])
Ga_comp_std.append(ppd.do_composition(pk_data,cts)[0][1][Ga_idx])
fig = plt.figure(num=101)
fig.clear()
ax = fig.gca()
#ax.plot(csr,Ga_comp,'.',label='time based')
ax.errorbar(csr,Ga_comp,yerr=Ga_comp_std,fmt='.',capsize=4)
ax.plot([np.min(csr),np.max(csr)],[0.25,0.25],'k--')
ax.set(xlabel='CSR', ylabel='Ga %', ylim=[0, 1], xlim=[2e-3,10])
#ax.grid()
#fig.tight_layout()
#fig.canvas.manager.window.raise_()
#ax.legend()
#fig = plt.figure(num=101)
#fig.clear()
#ax = fig.gca()
#ax.plot(np.arange(Ga_comp.size),csr,'.')
ax.set_xscale('log')
ax.grid()
fig.tight_layout()
# Slice and dice the data in wall_time
idxs_list = []
STEP = 10000
s_idx = 0
while s_idx<epos.size:
e_idx = np.min([epos.size,s_idx+STEP])
idxs_list.append([s_idx,e_idx])
s_idx = e_idx
# Count and compositions
csr = np.full(len(idxs_list),-1.0)
Ga_comp = np.full(len(idxs_list),-1.0)
Ga_comp_std = np.full(len(idxs_list),-1.0)
In_comp = np.full(len(idxs_list),-1.0)
In_comp_std = np.full(len(idxs_list),-1.0)
keys = list(pk_data.dtype.fields.keys())
keys.remove('m2q')
Ga_idx = keys.index('Ga')
In_idx = keys.index('In')
for loop_idx, idxs in enumerate(idxs_list):
sub_epos = epos[idxs[0]:idxs[1]]
r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2)
sub_idxs = np.nonzero(r>=0)
cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param)
Ga_comp[loop_idx] = ppd.do_composition(pk_data,cts)[0][0][Ga_idx]
Ga_comp_std[loop_idx] = ppd.do_composition(pk_data,cts)[0][1][Ga_idx]
In_comp[loop_idx] = ppd.do_composition(pk_data,cts)[0][0][In_idx]
In_comp_std[loop_idx] = ppd.do_composition(pk_data,cts)[0][1][In_idx]
fig = plt.figure(num=101)
fig.clear()
ax = fig.gca()
ax.errorbar((np.arange(Ga_comp.size)+0.5)*STEP,In_comp,yerr=In_comp_std,fmt='.',capsize=4)
# Slice and dice the data in wall_time
idxs_list = []
STEP = 10000
s_idx = 0
while s_idx<epos.size:
e_idx = np.min([epos.size,s_idx+STEP])
idxs_list.append([s_idx,e_idx])
s_idx = e_idx
# Count and compositions
csr = np.full(len(idxs_list),-1.0)
Ga_comp = np.full(len(idxs_list),-1.0)
Ga_comp_std = np.full(len(idxs_list),-1.0)
keys = list(pk_data.dtype.fields.keys())
keys.remove('m2q')
Ga_idx = keys.index('Ga')
#In_idx = keys.index('In')
for loop_idx, idxs in enumerate(idxs_list):
sub_epos = epos[idxs[0]:idxs[1]]
r = np.sqrt(sub_epos['x_det']**2+sub_epos['y_det']**2)
sub_idxs = np.nonzero(r>15)
cts = ppd.do_counting(sub_epos[sub_idxs],pk_params,glob_bg_param)
csr[loop_idx] = np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])
Ga_comp[loop_idx] = ppd.do_composition(pk_data,cts)[0][0][Ga_idx]
Ga_comp_std[loop_idx] = ppd.do_composition(pk_data,cts)[0][1][Ga_idx]
fig = plt.figure(num=101)
fig.clear()
ax = fig.gca()
#ax.plot(csr,Ga_comp,'.',label='time based')
ax.errorbar(csr,Ga_comp,yerr=Ga_comp_std,fmt='.',capsize=4)
ax.plot([np.min(csr),np.max(csr)],[0.5,0.5],'k--')
ax.set(xlabel='CSR', ylabel='Ga %', ylim=[0, 1], xlim=[0,2])
#ax.grid()
#fig.tight_layout()
#fig.canvas.manager.window.raise_()
#ax.legend()
fig = plt.figure(num=101)
fig.clear()
ax = fig.gca()
ax.plot(np.arange(Ga_comp.size),csr,'.')
#ax.plot(np.arange(Ga_comp.size),Ga_comp,'.')
# Slice and dice the data in detector space (polar)
idxs_list = []
STEP = 2
r = np.sqrt(np.square(epos['x_det'])+np.square(epos['y_det']))
for rq in np.arange(2,32,STEP):
idxs = np.where((r>rq) & (r<=(rq+STEP)))[0]
idxs_list.append(idxs)
# Count and compositions
csr = np.full(len(idxs_list),-1.0)
Ga_comp = np.full(len(idxs_list),-1.0)
Ga_comp_std = np.full(len(idxs_list),-1.0)
Ga_idx = keys.index('Ga')
for loop_idx, idxs in enumerate(idxs_list):
cts = ppd.do_counting(epos[idxs],pk_params,glob_bg_param)
csr[loop_idx] = np.sum(cts['total'][Ga2p_idxs])/np.sum(cts['total'][Ga1p_idxs])
Ga_comp[loop_idx] = ppd.do_composition(pk_data,cts)[0][0][Ga_idx]
Ga_comp_std[loop_idx] = ppd.do_composition(pk_data,cts)[0][1][Ga_idx]
ax.errorbar(csr,Ga_comp,yerr=Ga_comp_std,fmt='.',capsize=4,label='det based (radial)')
ax.plot([np.min(csr),np.max(csr)],[0.25,0.25],'k--')
ax.set(xlabel='CSR', ylabel='Ga %', ylim=[0, 1], xlim=[0,4])
#ax.plot([0,5],[0.5,0.5],'k--')
#
#
## Slice and dice the data in detector space (grid)
#idxs_list = []
#STEP = 10
#
#for x in np.arange(-30,30,STEP):
# for y in np.arange(-30,30,STEP):
# idxs = np.where((epos['x_det']>x) & (epos['x_det']<=(x+STEP)) & (epos['y_det']>y) & (epos['y_det']<=(y+STEP)))[0]
# idxs_list.append(idxs)
#
## Count and compositions
#csr = np.full(len(idxs_list),-1.0)
#Ga_comp = np.full(len(idxs_list),-1.0)
#
#for loop_idx, idxs in enumerate(idxs_list):
# cts = ppd.do_counting(epos[idxs],pk_params,glob_bg_param)
# csr[loop_idx] = (cts['total'][9]+cts['total'][10])/(cts['total'][14]+cts['total'][15])
# Ga_comp[loop_idx] = ppd.do_composition(pk_data,cts)[0][1]
#
#
#ax.plot(csr,Ga_comp,'.',label='det based (grid)')
ax.plot([0,5],[0.5,0.5],'k--')
ax.set(xlabel='CSR', ylabel='Ga %', ylim=[0, 1], xlim=[0, 5])
#ax.set_xscale('log')
ax.grid()
fig.tight_layout()
fig.canvas.manager.window.raise_()
ax.legend()