-
Notifications
You must be signed in to change notification settings - Fork 0
/
results_gen.py
2835 lines (2585 loc) · 122 KB
/
results_gen.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 scale_handler
import ensdf_handler
import keepin_handler
import prk_handler
import misc_funcs
import linear_least_squares as lls
import spectra_handler
import matplotlib.pyplot as plt
import time
import numpy as np
import sys
class RESULTS:
"""
This class handles generation of results by saving specific settings
and options directly into itself.
"""
def __init__(self,
times,
fissions,
efficiency,
normalize_value,
volume,
mass_normalize,
ensdf_fname='./ensdf_data/eval_net.xlsx',
ensdf_sheet='Sheet1',
ORIGEN_out = './scale_outputs/godiva_irrad_post_pulse.out',
TRITON_out = './scale_outputs/godiva_3d_depl.out'):
"""
Initialize. Runs necessary datasets depending on what is
requested.
Parameters
----------
times : array-like
Time values to evaluate at
fissions : float
Number of fission events within the sample
efficiency : float
Efficiency of the detector for delayed neutrons
normalize_value : float
Value ORIGEN multiplies its concentrations by
volume : float
Volume of the sample
mass_normalize : float
Mass normalization ORIGEN uses for activity
ensdf_fname : str
Path to IAEA .xlsx data
ensdf_sheet : str
Name of sheet with data in .xlsx file
ORIGEN_out : str
Path to ORIGEN output file
TRITON_out : str
Path to TRITON output file
Returns
-------
None
"""
self.times = times
self.fissions = fissions
self.efficiency = efficiency
self.normalize_value = normalize_value
self.volume = volume
self.mass_normalize = mass_normalize
self.ensdf_fname = ensdf_fname
self.ensdf_sheet = ensdf_sheet
self.triout = TRITON_out
self.oriout = ORIGEN_out
return
def delnu_gen(self,
scale_output,
activity='ensdf',
timestep=0,
show_iso='all',
custom_time=None,
errs=True):
"""
Generate delayed neutron data based on input specifications.
Parameters
----------
scale_output : str
Path to SCALE TRITON or ORIGEN output file
activity : str
Which method to use for decay constants ('ensdf', 'origen', 'debug')
timestep : int
Step at which to evaluate ORIGEN concentrations and activities
show_iso : str
Which isotope to show ('all' shows all isotopes) (ex/ xe135)
custom_time : vector
A different set of times to feed in for a separate calculation
Returns
-------
delnu_counts : array-like
Detected delay neutron counts from sample at each time
"""
ensdf_gen = ensdf_handler.ENSDF(self.ensdf_fname,
self.ensdf_sheet)
ensdf_dict = ensdf_gen.parse_file()
SCALE_gen = scale_handler.SCALE(scale_output, fissions,
efficiency, normalize_value, volume,
mass_normalize)
if type(custom_time) != type(None):
time_use = custom_time
else:
time_use = self.times
delnu_counts, delnu_errs = SCALE_gen.simulate_ensdf_SCALE(time_use, ensdf_dict,
timestep, show_iso,
activity, errs=errs)
n_per_f = misc_funcs.delnu_per_fiss(time_use,
delnu_counts,
self.fissions,
self.efficiency)
return np.array(delnu_counts), np.array(delnu_errs)
def compare_delnu_perc_diff(self,
counts_1,
counts_2,
savename='delnu_compare',
split=20):
"""
Compares the delayed neutron results from one decay data
and another decay data.
Saves plots.
Parameters
----------
split : float
Approximate time to split plot (None means no split)
counts_1 : array-like
Counts at each time value
counts_2 : array-like
Counts at each time value
savename : str
Name of file to save as
Returns
-------
None
"""
split_index = 0
for ind, t in enumerate(self.times):
if t < split:
split_index += 1
else:
break
if split:
perc_diff = list()
for ind in range(split_index):
perc_diff.append((counts_1[ind]-counts_2[ind])/counts_1[ind] * 100)
plt.plot(self.times[:int(split_index)], perc_diff)
plt.ylabel('Delayed Neutron Count % Diff')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-0-{split}.png')
plt.close()
perc_diff = list()
for ind in range(int(split_index), len(counts_1)):
perc_diff.append((counts_1[ind]-counts_2[ind])/counts_1[ind] * 100)
plt.plot(self.times[int(split_index):], perc_diff)
plt.ylabel('Delayed Neutron Count % Diff')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-{split}-end.png')
plt.close()
perc_diff = list()
for ind in range(len(counts_1)):
perc_diff.append((counts_1[ind]-counts_2[ind])/counts_1[ind] * 100)
plt.plot(self.times, perc_diff)
plt.ylabel('Delayed Neutron Count % Diff')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-full.png')
plt.close()
return
def subtime_delnu_perc_diff(self,
time_1,
counts_1,
time_2,
counts_2,
savename='delnu_compare',
split=20):
"""
Compares the delayed neutron results from one decay data
and another decay data with different times.
Saves plots.
Parameters
----------
time_1 : vector
Time vector
counts_1 : array-like
Counts at each time value
time_2 : vector
Time vector
counts_2 : array-like
Counts at each time value
savename : str
Name of file to save as
split : float
Approximate time to split plot (None means no split)
Returns
-------
None
"""
split_index = 0
use_time = list()
use_counts_1 = list()
use_counts_2 = list()
for ind1, t1 in enumerate(time_1):
if round(t1, 5) in np.round(time_2, 5):
use_counts_1.append(counts_1[ind1])
use_time.append(t1)
if t1 < split:
split_index += 1
for ind2, t2 in enumerate(time_2):
if round(t2, 5) in np.round(time_1, 5):
use_counts_2.append(counts_2[ind2])
if split:
perc_diff = list()
for ind in range(int(split_index)):
perc_diff.append((use_counts_1[ind]-use_counts_2[ind])/use_counts_1[ind] * 100)
plt.plot(use_time[:int(split_index)], perc_diff, marker='.')
plt.ylabel('Delayed Neutron Count Difference [%]')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-0-{split}.png')
plt.close()
perc_diff = list()
for ind in range(int(split_index), len(use_counts_1)):
perc_diff.append((use_counts_1[ind]-use_counts_2[ind])/use_counts_1[ind] * 100)
plt.plot(use_time[int(split_index):], perc_diff, marker='.')
plt.ylabel('Delayed Neutron Count Difference [%]')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-{split}-end.png')
plt.close()
perc_diff = list()
for ind in range(len(use_counts_1)):
perc_diff.append((use_counts_1[ind]-use_counts_2[ind])/use_counts_1[ind] * 100)
plt.plot(use_time, perc_diff, marker='.')
plt.ylabel('Delayed Neutron Count Difference [%]')
plt.xlabel('Time [s]')
plt.tight_layout()
plt.savefig(f'{savename}-full-pcnt.png')
plt.close()
perc_diff = list()
for ind in range(len(use_counts_1)):
perc_diff.append(abs(use_counts_1[ind]-use_counts_2[ind]))#/use_counts_1[ind] * 100)
plt.plot(use_time, perc_diff, marker='.')
plt.ylabel('Absolute Delayed Neutron Count Difference [#/s]')
plt.xlabel('Time [s]')
plt.yscale('log')
plt.tight_layout()
plt.savefig(f'{savename}-full-abs.png')
plt.close()
return
def ILLS_fit(self,
counts,
numgroups,
decay_dims,
nodes,
count_errs,
halflife_base=None,
percent_variance=0.3,
times=None,
ref_counts=None,
ref_times=None):
"""
Use the iterative linear least squares method to create
groups to fit the given data.
Parameters
----------
counts : vector
Delayed neutrons detected at a given time
numgroups : int
Number of groups to use
decay_dims : int
Number of dimensions to use for decays (1 or 2)
nodes : int
Number of nodes to use (should be odd)
halflife_base : vector
None if not known, otherwise vector containing the expected
group half lives
percent_variance : float
If using 2d lambda_values and orig values are given,
this term represents how far away from the given value
to search
times : vector
Used if there is a custom time set that needs to be used
ref_counts : vector
Used for refining the abundance results
ref_times : vector
Used for refining the abundance results
Returns
-------
abund : vector
Abundance values for each group
lami : vector
Decay constant values for each group
soln_vec : vector
a_i*lambda_i, lambda_i for each group
"""
if nodes % 2 == 0:
print(f'Nodes value {nodes} is not odd')
raise Exception
if decay_dims == 2:
run_type = '2d'
max_iters = nodes ** numgroups
elif decay_dims == 1:
n = nodes + numgroups - 1
k = numgroups
max_iters = math.factorial(n) / (math.factorial(k) * math.factorial(n-k))
run_type = '1d'
elif decay_dims == 0:
max_half = 60
print(f'Using randomly generated decay constants: 0 - {max_half}s')
max_iters = 5E4
print(f'Running {max_iters} iterations')
run_type = '0d'
else:
print('Bad shape {np.shape(np.shape(lambda_values))[0]}')
raise Exception
if run_type == '2d' and type(halflife_base) != type(None):
min_halflives = halflife_base * (1-percent_variance)
max_halflives = halflife_base * (1+percent_variance)
halflife_values = np.zeros((numgroups, nodes))
half_errs = list()
for group in range(numgroups):
halflife_values[group, :] = np.linspace(min_halflives[group], max_halflives[group], nodes)
half_errs.append((max_halflives[group]-min_halflives[group])/(nodes-1))
elif run_type == '2d':
print(f'WARNING: Using default min and max values')
halflife_values = np.zeros((numgroups, nodes))
min_halflives = [0.01, 0.2, 1.0, 5.0, 10, 40 ]
max_halflives = [0.20, 1.0, 5.0, 10 , 40, 100]
half_errs = list()
print(f'WARNING: Currently set for {len(min_halflives)} groups')
for group in range(numgroups):
halflife_values[group, :] = np.linspace(min_halflives[group], max_halflives[group], nodes)
half_errs.append((max_halflives[group]-min_halflives[group])/(nodes-1))
elif run_type == '1d':
print(f'Using default min and max values')
minhalf = 0.1
maxhalf = 60
dhalf = (maxhalf-minhalf)/(num_nodes-1)
halflife_values = np.arange(minhalf, maxhalf+dhalf*0.1, dhalf)
elif run_type == '0d':
halflife_values = max_half
half_errs = np.sqrt(1 / max_iters) * np.ones(numgroups)
else:
print(f'Error in selecting run')
raise Exception
lam_errs = list()
try:
lambda_values = np.log(2) / halflife_values
lambda_values.sort()
except np.AxisError:
pass
if type(times) != type(None):
use_time = times
else:
use_time = self.times
lin_solver = lls.LLS(use_time,
counts,
self.fissions,
self.efficiency,
numgroups)
abund, lami, covariance_mat, residual = lin_solver.lami_solver(lambda_values,
max_iters,
counts,
count_errs,
fissions_error)
if type(abund) == type(None):
print('ILLS did not converge to a solution')
raise Exception
## a_errs = list()
## for ind in range(numgroups):
## a_errs.append(residual / (len(self.times) - numgroups) * covariance_mat[ind][ind])
half_life_final_vals = np.log(2)/lami
for ind, each in enumerate(half_life_final_vals):
errval = np.log(2)/each**2 * half_errs[ind]
lam_errs.append(errval)
soln_vec = list()
for each in range(len(abund)):
soln_vec.append(abund[each] * lami[each])
soln_vec.append(lami[each])
#print('Using TEST values '*5)
#lam_errs = 0 * np.array(lam_errs)
if group_abundance_err:
a_errs = lin_solver.MC_abun_err(lami, lam_errs,
counts, count_errs,
tot_iters=abund_iters,
fiserr=fissions_error)
else:
print(f'Abundance errors approximated')
print(f'\nGroup n/F: {np.sum(abund)}')
print(f'Decay Constants: {lami}')
print(f'Decay Uncertainties: {lam_errs}')
print(f'Half Lives: {half_life_final_vals}')
print(f'Half Life Uncertainties: {half_errs}')
print(f'Group Yields: {abund.T}\n')
print(f'Group Yield Uncertainties: {a_errs}')
print('Formatted Half Lives')
for ind, half in enumerate(np.log(2) / lami):
if ind != len(lami) - 1:
print(f'{np.round(half, 3)} $\pm$ {np.round(half_errs[ind], 3)} & ', end='')
else:
print(f'{np.round(half, 3)} $\pm$ {np.round(half_errs[ind], 3)}')
print('\n')
print('Formatted Abundancies')
for ind, abun in enumerate(abund.T*100):
if ind != len(abund) - 1:
print(f'{np.round(abun, 3)} $\pm$ {np.round(a_errs[ind]*100, 3)} & ', end='')
else:
print(f'{np.round(abun, 3)} $\pm$ {np.round(a_errs[ind]*100, 3)}')
print('\n')
print(f'Next iteration half lives:')
print('np.array([', end='')
for ind, half in enumerate(np.log(2) / lami):
if ind != len(lami) - 1:
print(f'{np.round(half, 5)}', end=', ')
else:
print(f'{np.round(half, 5)}', end='])\n')
if type(ref_counts) != type(None) and type(ref_times) != type(None):
print(f'Refining abundances')
abund_new, lami, covariance_mat, residual = lin_solver.abund_refine(lami,
ref_times,
ref_counts)
print(f'Refined yields: {abund_new.T[0]}\n')
print(f'Refined n/f: {sum(abund_new)}')
keepin_response = keepin_handler.KEEPIN()
#delnu_counts, errors = keepin_response.simulate_lin_solve(use_time,
# soln_vec,
# self.fissions,
# self.efficiency,
# a_errs,
# lam_errs)
#response = list()
#for cnt in delnu_counts:
# response.append(cnt[0])
#n_per_f = misc_funcs.delnu_per_fiss(use_time,
# response,
# self.fissions,
# self.efficiency)
#for index in range(len(delnu_counts)):
# avg_pcnt_diff = np.mean(abs(delnu_counts[index] - counts[index]) / delnu_counts[index]) * 100
#print(f'Average % difference: {avg_pcnt_diff}')
return abund, lami, soln_vec, a_errs, lam_errs
def group_results(pathname,
fit_groups,
decay_nodes,
results_generator,
counts,
count_errs,
decay_dims,
imdir,
halflife_base,
percent_variation,
times,
fissions,
efficiency,
use_errorbars):
"""
Generate group results for given settings
Parameters
----------
pathname : str
Path to where to put outputs
fit_groups : int
Number of groups to use in fit
decay_nodes : int
Number of nodes to use for generating decay constants
results_generator : RESULTS class
Results class
counts : vector
Count data to use to generate results
count_errs : vector
Associated count errors
decay_dims : int
Number of dimensions to use to generate decay matrix or vector
imdir : str
Name of default directory to use
halflife_base : vector
Default values of half lives used for group fit
percent_variation : List
List of percent variation to apply to base (0.1 -> 10%)
times : vector
Times to generate group counts at
fissions : float
Number of fission events in sample
efficiency : float
Efficiency of the neutron detector
use_errorbars : bool
Whether to plot errors or not
Returns
-------
None
"""
name = pathname.replace('/', '')
current_path = imdir+pathname
misc_funcs.dir_handle(current_path)
for pcnt in percent_variation:
print('-'*40)
numgroups = fit_groups
nodes = decay_nodes
print(f'{name} {numgroups} group fit, {nodes} nodes with {pcnt*100}% variance')
abund, lami, soln_vec, a_errs, lam_errs = results_generator.ILLS_fit(counts,
numgroups,
decay_dims,
nodes,
count_errs,
halflife_base=halflife_base,
percent_variance=pcnt,
times=times)
keepin_response = keepin_handler.KEEPIN()
group_counts, group_errs = keepin_response.simulate_lin_solve(times, soln_vec, fissions, efficiency,
a_errs, lam_errs)
if use_errorbars:
misc_funcs.multplt(times, group_counts, label=f'{numgroups} group fit', alpha=alpha,
errors=group_errs)
misc_funcs.multplt(times, counts, label=f'Data', alpha=alpha,
errors=count_errs)
else:
misc_funcs.multplt(times, group_counts, label=f'{numgroups} group fit', alpha=alpha)
misc_funcs.multplt(times, counts, label=f'{name}', alpha=alpha)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.legend()
plt.tight_layout()
plt.savefig(current_path+f'{name}_{numgroups}_group_fit.png')
plt.close()
if len(times) == len(results_generator.times) and np.all(np.isclose(times, results_generator.times)):
results_generator.compare_delnu_perc_diff(counts,
group_counts,
savename=current_path+'perc_diff',
split=5)
else:
results_generator.subtime_delnu_perc_diff(times,
counts,
times,
group_counts,
savename=current_path+'perc_diff',
split=5)
prcnt_diff = list()
for index in range(len(counts)):
prcnt_diff.append((abs(counts[index] - group_counts[index]) /
counts[index]) * 100)
avg_pcnt_diff = np.mean(prcnt_diff)
print(f'Average % difference: {avg_pcnt_diff}')
if not np.all(np.isclose(np.log(2)/lami, halflife_base)):
print(f'New fit for {pcnt*100}% variation')
print('-'*50)
group_results(pathname,
fit_groups,
decay_nodes,
results_generator,
counts,
count_errs,
decay_dims,
imdir,
np.log(2)/lami,
percent_variation,
times,
fissions,
efficiency,
use_errorbars)
else:
print('Converged for given criteria')
return
def prefab_group_delnu(times,
lam_vec,
lam_err,
abun_vec,
abun_err,
fissions,
efficiency):
"""
Useful for when the group data is already known and can be directly modeled
Parameters
----------
times : vector
Time values to generate counts at
lam_vec : vector
Decay constants for each group
lam_err : vector
Errors for each decay constant for each group
abun_vec : vector
Group yield (abundance) for each group
abun_err : vector
Group yield error for each group
fissions : float
Number of fission events in target sample
efficiency : float
Efficiency of the neutron detector
Returns
-------
delnu : vector
Number of counts at each time step
errors : vector
Uncertainty in counts at each time step
"""
delnu = list()
errors = list()
err_solve = False
if type(lam_err) != type(None) and type(abun_err) != type(None):
err_solve = True
for t in times:
detect = 0
err = 0
for ind in range(len(lam_vec)):
lami = lam_vec[ind]
ai = abun_vec[ind]
if irradiation == 'infinite':
a_val = ai
elif irradiation == 'pulse':
a_val = lami * ai
detect += (a_val * np.exp(-lami * t))
if err_solve:
ai_err = abun_err[ind]
lami_err = lam_err[ind]
if irradiation == 'pulse':
err += ((lami * np.exp(-lami * t) * ai_err)**2 +
(ai*(1-lami*t)*np.exp(-lami*t)*lami_err)**2)
elif irradiation == 'infinite':
err += ((np.exp(-lami * t) * ai_err)**2 +
(ai*t*np.exp(-lami*t)*lami_err)**2)
detect = fissions * efficiency * detect
delnu.append(detect)
if err_solve:
err = np.sqrt(err) * fissions * efficiency
errors.append(err)
else:
errors.append(0)
return delnu, errors
if __name__ == '__main__':
from settings import *
misc_funcs.dir_handle(imdir)
# Set time to be universal
time_construct = scale_handler.SCALE(ORIGEN_out,
fissions,
efficiency,
normalize_value)
times, _ = time_construct.origen_delnu_parser('all')
# Set energy mesh to be universal
ORIGEN_result = scale_handler.SCALE(ORIGEN_out,
fissions,
efficiency,
normalize_value,
volume,
mass_normalize)
_, energy_data, _, _ = ORIGEN_result.origen_spectra_parser()
energy_mesh = energy_data.copy()
energy_bin_kev = np.round(np.mean(np.diff(energy_mesh)), 3) * 1E3
# Run definitions
results_generator = RESULTS(times,
fissions,
efficiency,
normalize_value,
volume,
mass_normalize,
ensdf_fname=ensdf_fname,
ensdf_sheet=ensdf_sheet,
ORIGEN_out=ORIGEN_out,
TRITON_out=TRITON_out)
# Determine minimum delayed neutron generation required
# Concentrations-DecayConstants
# ORIGEN-ORIGEN, ORIGEN-ENSDF, TRITON-ORIGEN, TRITON-ENSDF
# Pure ORIGEN
# Keepin, Brady/England
pathname = 'delnu-plain/'
current_path = imdir+pathname
misc_funcs.dir_handle(current_path)
# Pure ORIGEN
if ori_pure_ensdf_comp or \
ori_pure_group_fit or \
view_pn_ori_pure or \
iaea_ori_pure or \
collect_data or \
ori_ensdf_counts_cmp:
print('-'*40)
print('ORIGEN Pure')
scale_builder = scale_handler.SCALE(ORIGEN_out,
fissions,
efficiency,
normalize_value,
volume,
mass_normalize)
t_ori, pure_delnu_ori = scale_builder.origen_delnu_parser(target)
n_per_f = misc_funcs.delnu_per_fiss(t_ori, pure_delnu_ori, fissions, efficiency)
plt.plot(t_ori, pure_delnu_ori)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+f'pure_delnu_ori_{target}.png')
plt.close()
# ORIGEN-ENSDF
if run_compare_decay or \
run_keep_brad_scale or \
ori_ensdf_group_fit or \
ori_pure_ensdf_comp or \
run_ori_tri_compare or \
ori_ensdf_keep_err or \
iaea_ori_pure or \
collect_data or \
ori_ensdf_counts_cmp:
origen_ensdf_dn, origen_ensdf_errs = results_generator.delnu_gen(ORIGEN_out,
activity='ensdf',
timestep=0,
show_iso=target)
plt.plot(times, origen_ensdf_dn)
origen_ensdf_errs = np.asarray(origen_ensdf_errs)
if use_errorbars:
plt.fill_between(times, origen_ensdf_dn+origen_ensdf_errs, origen_ensdf_dn-origen_ensdf_errs, alpha=alpha/2)
else:
pass
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+f'origen_ensdf_dn_{target}.png')
plt.close()
# ORIGEN-ORIGEN
if run_compare_decay or \
ori_pure_ensdf_comp or \
view_pn_ori_pure or \
collect_data:
origen_origen_dn, origen_origen_errs = results_generator.delnu_gen(ORIGEN_out,
activity='origen',
timestep=0,
show_iso=target,
errs=False)
plt.plot(times, origen_origen_dn)
if use_errorbars:
plt.fill_between(times, origen_origen_dn+origen_origen_errs, origen_origen_dn-origen_origen_errs, alpha=alpha/2)
else:
pass
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+f'origen_origen_dn_{target}.png')
plt.close()
# TRITON-ENSDF
if False:#run_ori_tri_compare or \
#tri_ensdf_group_fit or \
#collect_data:
triton_ensdf_dn, triton_ensdf_errs = results_generator.delnu_gen(TRITON_out,
activity='ensdf',
timestep=0,
show_iso=target)
plt.plot(times, triton_ensdf_dn)
if use_errorbars:
plt.fill_between(times, triton_ensdf_dn+triton_ensdf_errs, triton_ensdf_dn-triton_ensdf_errs, alpha=alpha/2)
else:
pass
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+f'triton_ensdf_dn_{target}.png')
plt.close()
# TRITON-ORIGEN
if False:
triton_origen_dn, triton_origen_errs = results_generator.delnu_gen(TRITON_out,
activity='origen',
timestep=0,
show_iso=target)
plt.plot(times, triton_origen_dn)
if use_errorbars:
#plt.errorbar(times, triton_origen_dn, yerr=triton_origen_errs, elinewidth=1)
plt.fill_between(times, triton_origen_dn+triton_origen_errs, triton_origen_dn-triton_origen_errs, alpha=alpha/2)
else:
pass
#plt.plot(times, triton_origen_dn)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+f'triton_origen_dn_{target}.png')
plt.close()
# Keepin
if run_keep_brad_scale or \
test_group_fit or \
ori_ensdf_keep_err or \
keepin_pure or \
collect_data or \
keepin_pure_ori_fit:
#name = '6keepin235fast'
#keepin_response = keepin_handler.KEEPIN(name)
#keepin_delnu, keepin_errs = keepin_response.simulate_instant(times, fissions, efficiency)
#keepin_delnu = np.array(keepin_delnu)
#keepin_errs = np.array(keepin_errs)
keepin_delnu, keepin_errs = prefab_group_delnu(times,
keepin_lamvec,
keepin_lamerr,
keepin_abuvec,
keepin_abuerr,
fissions,
efficiency)
plt.plot(times, keepin_delnu)
keepin_delnu = np.asarray(keepin_delnu)
keepin_errs = np.asarray(keepin_errs)
if use_errorbars:
#plt.errorbar(times, keepin_delnu, yerr=keepin_errs, elinewidth=1)
plt.fill_between(times, keepin_delnu+keepin_errs, keepin_delnu-keepin_errs, alpha=alpha/2)
else:
pass
#plt.plot(times, keepin_delnu)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+'keepin_delnu.png')
plt.close()
# Brady/England
if run_keep_brad_scale or \
collect_data or \
keepin_pure_ori_fit:
#name = '6brengland235fast'
#brady_england_response = keepin_handler.KEEPIN(name)
#brady_england_delnu, be_errs = brady_england_response.simulate_instant(times, fissions, efficiency)
brady_england_delnu, be_errs = prefab_group_delnu(times,
be_lamvec,
be_lamerr,
be_abuvec,
be_abuerr,
fissions,
efficiency)
plt.plot(times, brady_england_delnu)
brady_england_delnu = np.array(brady_england_delnu)
be_errs = np.array(be_errs)
if use_errorbars:
#plt.errorbar(times, brady_england_delnu, yerr=be_errs, elinewidth=1)
plt.fill_between(times, brady_england_delnu+be_errs, brady_england_delnu-be_errs, alpha=alpha/2)
else:
pass
#plt.plot(times, brady_england_delnu)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.savefig(current_path+'brady_england_delnu.png')
plt.close()
# Spectral matrix generation
if alt_spc_lstsq_oriaea or \
iaea_ori_2d_spectra or \
spectra_lstsq_oriaea or \
spec_compare_oriaea or \
spectra_puori_fit:
ORIGEN_result = scale_handler.SCALE(ORIGEN_out,
fissions,
efficiency,
normalize_value,
volume,
mass_normalize)
ensdf_gen = ensdf_handler.ENSDF(ensdf_fname, ensdf_sheet)
ensdf_dict = ensdf_gen.parse_file()
ORIGEN_dict = ORIGEN_result.ensdf_matcher(ensdf_dict,
0,
target)
spectrum_dealer = spectra_handler.SPECTRA(energy_mesh, times)
#spectral_matrix, valid_list = spectrum_dealer.spectral_matrix_constructor(ORIGEN_dict, ensdf_handler)
spectral_matrix, valid_list, count_matrix = spectrum_dealer.spectral_matrix_constructor(ORIGEN_dict, ensdf_handler, alt_norm=True)
# Analysis
if run_compare_decay:
# Decay compare IAEA ORIGEN with delayed neutrons
pathname = 'decay-compare/'
current_path = imdir+pathname
misc_funcs.dir_handle(current_path)
results_generator.compare_delnu_perc_diff(origen_ensdf_dn,
origen_origen_dn,
savename=current_path+'perc_diff',
split=2)
misc_funcs.multplt(times, origen_origen_dn, label='origen-origen', alpha=alpha)
misc_funcs.multplt(times, origen_ensdf_dn, label='origen-iaea', alpha=alpha)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.legend()
plt.savefig(current_path+'delnu_tot_compare.png')
plt.close()
if run_ori_tri_compare:
# Compare ORIGEN and TRITON concentration results
pathname = 'ori-tri-conc/'
current_path = imdir+pathname
misc_funcs.dir_handle(current_path)
results_generator.compare_delnu_perc_diff(origen_ensdf_dn,
triton_ensdf_dn,
savename=current_path+'perc_diff',
split=2)
misc_funcs.multplt(times, triton_ensdf_dn, label='triton-iaea', alpha=alpha)
misc_funcs.multplt(times, origen_ensdf_dn, label='origen-iaea', alpha=alpha)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.legend()
plt.savefig(current_path+'delnu_tot_compare.png')
plt.close()
if run_keep_brad_scale:
# Plot SCALE delnu (ORIGEN-IAEA) with groups and data
pathname = 'ori-iaea-data/'
current_path = imdir+pathname
misc_funcs.dir_handle(current_path)
plt.plot(times, keepin_delnu, label='Keepin')
plt.plot(keepin_response.true_data_time, keepin_response.true_data_resp,
label='Keepin True', linestyle='', marker='.')
misc_funcs.multplt(times, keepin_delnu, label='Brady-England', alpha=alpha)
misc_funcs.multplt(times, origen_ensdf_dn, label='origen-iaea', alpha=alpha)
plt.yscale('log')
plt.ylabel('Delayed Neutron Count Rate [#/s]')
plt.xlabel('Time [s]')
plt.legend()
plt.savefig(current_path+'delnu_tot_compare.png')
plt.close()
if test_group_fit:
# 6-group fit to Keepin 6-group data
pathname = f'test-{fit_groups}-fit/'
group_results(pathname,
fit_groups,
decay_nodes,
results_generator,
keepin_delnu,
keepin_errs,
decay_dims,
imdir,
halflife_base,
percent_variation,
times,
fissions,
efficiency,