forked from mohamedlahdour/ERSN-OpenMC-Py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTallyDataProcessing.py
3796 lines (3494 loc) · 195 KB
/
TallyDataProcessing.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 os
import sys
import os.path
import PyQt5
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5 import uic
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QMessageBox
import datetime
import shutil
import subprocess
from pathlib import Path
from PyQt5.QtGui import QFont, QTextCharFormat, QBrush
from src.PyEdit import TextEdit, NumberBar, tab, lineHighlightColor
import numpy as np
from matplotlib import pyplot as plt, cm
from matplotlib import colors
import pandas as pd
import glob
import h5py
from PyQt5.QtWidgets import (QPlainTextEdit, QWidget, QVBoxLayout, QApplication, QFileDialog, QMessageBox, QLabel, QCompleter,
QHBoxLayout, QTextEdit, QToolBar, QComboBox, QAction, QLineEdit, QDialog, QPushButton, QSizePolicy,
QToolButton, QMenu, QMainWindow, QInputDialog, QColorDialog, QStatusBar, QSystemTrayIcon)
from PyQt5.QtGui import (QIcon, QPainter, QTextFormat, QColor, QTextCursor, QKeySequence, QClipboard, QTextDocument,
QPixmap, QStandardItemModel, QStandardItem, QCursor, QFontDatabase)
from PyQt5.QtCore import (Qt, QVariant, QRect, QDir, QFile, QFileInfo, QTextStream, QSettings, QTranslator, QLocale,
QProcess, QPoint, QSize, QCoreApplication, QStringListModel, QLibraryInfo)
from PyQt5 import QtPrintSupport
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from PyQt5.QtGui import QTextOption
iconsize = QSize(24, 24)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('max_colwidth', 30)
try:
import openmc
except:
pass
class TallyDataProcessing(QtWidgets.QMainWindow):
from src.func import resize_ui, showDialog
#def __init__(self, shellwin, parent=None):
def __init__(self, parent=None):
super(TallyDataProcessing, self).__init__(parent)
uic.loadUi("src/ui/TallyDataProcessing.ui", self)
try:
from openmc import __version__
self.openmc_version = int(__version__.split('-')[0].replace('.', ''))
except:
self.openmc_version = 0
self.groupBox_15.hide()
self.FILTER_TYPES = ['UniverseFilter', 'MaterialFilter', 'CellFilter', 'CellFromFilter', 'CellbornFilter',
'CellInstanceFilter', 'CollisionFilter', 'SurfaceFilter', 'MeshFilter', 'MeshSurfaceFilter',
'EnergyFilter', 'EnergyoutFilter', 'MuFilter', 'PolarFilter', 'AzimuthalFilter',
'DistribcellFilter', 'DelayedGroupFilter', 'EnergyFunctionFilter', 'LegendreFilter',
'SpatialLegendreFilter', 'SphericalHarmonicsFilter', 'ZernikeFilter', 'ZernikeRadialFilter',
'ParticleFilter', 'TimeFilter']
self.sp_file = 'None'
self.Display = False
self.Tallies = {}
self.Mesh_xy_RB.hide()
self.Mesh_xz_RB.hide()
self.Mesh_yz_RB.hide()
self.spinBox.hide()
self.spinBox_2.hide()
self.buttons = [self.xLog_CB, self.yLog_CB, self.Add_error_bars_CB, self.xGrid_CB, self.yGrid_CB, self.MinorGrid_CB, self.label_2, self.label_3]
self.buttons_Stack = [self.label_5, self.label_6, self.label_7, self.row_SB, self.col_SB]
for elm in self.buttons:
elm.setEnabled(False)
for elm in self.buttons_Stack:
elm.setEnabled(False)
self.Graph_Layout_CB.setEnabled(False)
self.Graph_type_CB.setEnabled(False)
#self.set_Graph_stack()
# add new editor for output window
self.editor = TextEdit()
self.editor.setWordWrapMode(QTextOption.NoWrap)
self.numbers = NumberBar(self.editor)
layoutH8 = QHBoxLayout()
layoutH8.addWidget(self.numbers)
layoutH8.addWidget(self.editor)
self.gridLayout_18.addLayout(layoutH8, 0, 0)
# add editor to second tab
self.editor1 = TextEdit()
self.editor1.setWordWrapMode(QTextOption.NoWrap)
self.numbers1 = NumberBar(self.editor1)
layoutH9 = QHBoxLayout()
layoutH9.addWidget(self.numbers1)
layoutH9.addWidget(self.editor1)
self.gridLayout_5.addLayout(layoutH9, 0, 0)
self.grid = False
self.which_axis = 'none'
self.which_grid = 'both'
self.resize_ui()
self.Norm_Bins_comboBox = CheckableComboBox()
self.Norm_Bins_comboBox.addItem('Check item')
self.gridLayout_Norm.addWidget(self.Norm_Bins_comboBox)
self.Norm_Bins_comboBox.model().item(0).setEnabled(False)
# +++++++++++++++++++++++
self.Tally_name_LE.setPlaceholderText("Name")
self.root = QFileInfo.path(QFileInfo(QCoreApplication.arguments()[0]))
self.openPath = ""
self.dirpath = QDir.homePath() + "/Documents/tmp/"
self.filename = ""
#self.MaxRecentFiles = 15
self.recentFileActs = []
self.settings = QSettings("PyEdit", "PyEdit")
#self.createActions()
# +++++++++++++++++++++++
if not self.score_plot_PB.isEnabled():
self.score_plot_PB.setToolTip('If filter bins or selected nuclides or selected score change, press select button first')
self.scores_display_PB.setToolTip('Press this button before ploting!')
self._initButtons()
sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
#sys.stderr = EmittingStream(textWritten=self.normalOutputWritten)
# lines to be removed
#self.sp_file = str(Path.home()) + '/My_Projects/Project-ERSN-OpenMC/Gui_orig/examples/tallies/statepoint.310.h5'
cwd = os.getcwd()
self.sp_file = str(cwd) + '/examples/tallies/statepoint.310.h5'
if not os.path.isfile(self.sp_file):
self.sp_file = None
else:
self.lineEdit.setText(self.sp_file)
self.Get_data_from_SP_file()
def _initButtons(self):
self.browse_PB.clicked.connect(self.Get_SP_File)
self.get_tally_info_PB.clicked.connect(self.Display_Tallies_Inf)
self.Tally_id_comboBox.currentIndexChanged.connect(self.SelectTally)
self.tally_display_PB.clicked.connect(self.Display_tally)
self.Filters_comboBox.currentIndexChanged.connect(self.SelectFilter)
self.filters_display_PB.clicked.connect(self.Display_filters)
self.nuclides_display_PB.clicked.connect(self.Clear_nuclides)
self.Nuclides_comboBox.currentIndexChanged.connect(self.SelectNuclides)
self.Scores_comboBox.currentIndexChanged.connect(self.SelectScores)
self.scores_display_PB.clicked.connect(self.Display_scores)
self.Mesh_xy_RB.toggled.connect(self.Mesh_settings)
self.Mesh_xz_RB.toggled.connect(self.Mesh_settings)
self.Mesh_yz_RB.toggled.connect(self.Mesh_settings)
self.Graph_type_CB.currentIndexChanged.connect(self.set_Scales)
self.Plot_by_CB.currentIndexChanged.connect(self.set_Scales)
self.xGrid_CB.stateChanged.connect(self.plot_grid_settings)
self.yGrid_CB.stateChanged.connect(self.plot_grid_settings)
self.MinorGrid_CB.stateChanged.connect(self.plot_grid_settings)
self.Graph_Layout_CB.currentIndexChanged.connect(self.set_Graph_stack)
self.Plot_by_CB.currentIndexChanged.connect(self.set_Graph_stack)
self.score_plot_PB.clicked.connect(self.Plot)
self.Close_Plots_PB.clicked.connect(lambda:plt.close('all'))
self.ResetPlotSettings_PB.clicked.connect(self.Reset_Plot_Settings)
self.Nuclides_List_LE.textChanged.connect(lambda:self.score_plot_PB.setEnabled(False))
self.Scores_List_LE.textChanged.connect(lambda:self.score_plot_PB.setEnabled(False))
self.lineEdit.textChanged.connect(self.Reset_Tally_CB)
self.Define_Buttons()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++ CODE TO PROCESS SIMULATION SP FILE +++++++++++++++++++++++++++++++++++++++++++
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def Get_SP_File(self):
self.Tally_id_comboBox.clear()
self.Tally_id_comboBox.addItem("Select the tally's ID")
self.editor.clear()
self.Plot_by_CB.clear()
self.Filters_comboBox.clear()
self.Nuclides_comboBox.clear()
self.Scores_comboBox.clear()
self.tabWidget_2.setCurrentIndex(0)
self.sp_file = QtWidgets.QFileDialog.getOpenFileName(self,"Select The StatePoint File","~","statepoint*.h5")[0]
self.lineEdit.setText(self.sp_file)
self.Get_data_from_SP_file()
self.lineLabel3.clear()
def Get_data_from_SP_file(self):
global sp
self.Heating_LE.clear()
self.Factor_LE.clear()
try:
for i in range(len(self.Bins_comboBox)):
self.Bins_comboBox[i].hide()
except:
pass
try:
if os.path.isfile(self.sp_file):
sp = openmc.StatePoint(self.sp_file)
self.names = {}
self.Nuclides = {}
self.Scores = {}
self.Estimator = {}
self.Tallies['tallies_ids'] = []
self.Tallies['names'] = []
self.meshes = {}
_f = h5py.File(self.sp_file, 'r')
self.tallies_group = _f['tallies']
self.n_tallies = self.tallies_group.attrs['n_tallies']
self.tally_ids = self.tallies_group.attrs['ids']
self.filters_group = _f['tallies/filters']
for tally_id in self.tally_ids:
tally = sp.get_tally(id=tally_id) # Ok
name = tally.name
self.Tallies['tallies_ids'].append(tally_id)
self.Tallies['names'].append(name)
for score in tally.scores:
if score == 'heating':
heat = tally.mean.ravel()[0]
self.Heating_LE.setText(str(heat))
# Read all meshes
mesh_group = _f['tallies/meshes']
# Iterate over all meshes
for group in mesh_group.values():
mesh = openmc.MeshBase.from_hdf5(group)
self.meshes[mesh.id] = mesh
self.Tally_id_comboBox.clear()
self.Tally_id_comboBox.addItem("Select the tally's ID")
self.Tallies_in_SP = list(sp.tallies.keys())
if sp.run_mode == 'eigenvalue':
self.H = None
self.Tally_id_comboBox.addItem('Keff result')
self.batches = [i+1 for i in range(sp.n_batches)]
self.Keff_List = sp.k_generation.tolist()
self.keff = sp.keff.nominal_value
self.dkeff = sp.keff.std_dev
try:
self.H = sp.entropy.tolist()
except:
pass
for key in self.Tallies_in_SP:
self.names[key] = []
self.Nuclides[key] = []
self.Scores[key] = []
self.Estimator[key] = []
text = str(sp.tallies[key]).split('\n')
for line in text:
if 'Name' in line:
name = line.split('=')[1].lstrip()
self.names[key].append(name)
if 'Nuclides' in line:
nuclide = line.split('=')[1].lstrip().split(' ')
self.Nuclides[key] = nuclide
if 'Scores' in line:
score1 = line.split('=')[1].lstrip().replace("'", "")
score = score1[score1.find('[') + 1: score1.find(']')].split(', ')
self.Scores[key] = [item for item in score]
if 'Estimator' in line:
estimator = line.split('=')[1].lstrip()
self.Estimator[key].append(estimator)
self.Tally_id_comboBox.addItem(str(key))
else:
pass
except:
pass
self.lineLabel1.setText('Statepoint file : ' + self.sp_file)
self.lineLabel2.setText('containing : ' + str(self.n_tallies) + ' tallies')
def Display_Tallies_Inf(self):
self.Display = False
self.Normalization = False
print(self.tallies_group)
if self.lineEdit.text():
self.sp_file = self.lineEdit.text()
if not os.path.isfile(self.sp_file):
self.showDialog('Warning', 'Load valid sp file!')
return
self.editor1.clear()
self.tabWidget_2.setCurrentIndex(1)
if True:
if os.path.isfile(self.sp_file):
sp = openmc.StatePoint(self.sp_file)
# print tallies summary
self.editor1.insertPlainText('*'*57 + ' TALLIES SUMMARY ' + '*'*58 + '\n')
for key in sp.tallies.keys():
self.editor1.insertPlainText(str(sp.tallies[key])+ '\n')
self.editor1.insertPlainText('*'*134 + '\n')
if sp.run_mode == 'eigenvalue':
# print Keff results
n = sp.n_batches
keff_glob = sp.global_tallies
INDEX = [str(idx,encoding='utf-8').ljust(25) for idx in keff_glob['name']]
df = pd.DataFrame(keff_glob, index=INDEX, columns = ['name', 'mean', 'std_dev'])
for item in df['name']:
elem = str(item,encoding='utf-8').ljust(25)
df = df.replace({'name': item}, {'name': elem})
df.loc['Combined keff'] = ['Combined keff', self.keff, self.dkeff]
df.iloc[4], df.iloc[3] = df.iloc[3], df.iloc[4]
self.Print_Formated_df_Keff(df, self.editor1, '', 0)
# print Keff vs batches
self.batches = [i+1 for i in range(n)]
self.Keff_List = sp.k_generation.tolist()
df1 = pd.DataFrame({'batch': self.batches, 'Keff': self.Keff_List})
self.Print_Formated_df_Keff(df1, self.editor1, ' K EFFECTIVE VS BATCH ', 1)
try:
self.H = sp.entropy.tolist()
df1 = pd.DataFrame({'batch': self.batches, 'Entropy': self.H})
self.Print_Formated_df_Keff(df1, self.editor1, ' SHANNON ENTROPY ', 1)
except:
pass
# print tallies results
_f = h5py.File(self.sp_file, 'r')
self.tally_ids = self.tallies_group.attrs['ids']
self.editor1.insertPlainText('*'*57 + ' TALLIES RESULTS ' + '*'*58 + '\n')
for tally_id in self.tally_ids:
self.tally_id = tally_id
self.tally = sp.get_tally(id=tally_id)
df = self.tally.get_pandas_dataframe(float_format = '{:.2e}') #'{:.6f}')
self.Print_Formated_df(df.copy(), tally_id, self.editor1)
else:
msg = 'Select your StatePoint file first !'
self.showDialog('Warning', msg)
return
else:
self.showDialog('Warning', 'Verify if OpenMC is installed !')
return
self.Tally_id_comboBox.setCurrentIndex(0)
def Reset_Tally_CB(self):
self.Tally_id_comboBox.setCurrentIndex(0)
self.Tally_id_comboBox.clear()
self.Tally_id_comboBox.addItem("Select the tally's ID")
self.Plot_by_CB.clear()
self.Filters_comboBox.clear()
self.Nuclides_comboBox.clear()
self.Scores_comboBox.clear()
try:
if os.path.isfile(self.lineEdit.text()):
self.sp_file = self.lineEdit.text()
sp = openmc.StatePoint(self.sp_file)
if sp.run_mode == 'eigenvalue':
self.Tally_id_comboBox.addItem('Keff result')
self.Tally_id_comboBox.addItems([str(tally) for tally in list(sp.tallies.keys())])
else:
pass
except:
return
def Check_if_SP_file_exists(self):
self.sp_file == self.lineEdit.text()
if not os.path.isfile(self.sp_file):
self.showDialog('Warning', 'Invalid path to stateppoint file!')
self.Tally_id_comboBox.clear()
self.Tally_id_comboBox.addItem("Select the tally's ID")
else:
pass
def SelectTally(self):
global power_items, Norm_Other
tally_id = ''
name = ''
if self.lineEdit.text():
self.sp_file = self.lineEdit.text()
if not os.path.isfile(str(self.sp_file)):
self.lineLabel1.setText("Current statepoint file : No valid statepoint file", 0)
return
self.score_plot_PB.setText('plot data')
self.filters = []
self.Bins = {}
self.Tally_name_LE.clear()
self.Curve_title.clear()
self.Nuclides_List_LE.clear()
self.Scores_List_LE.clear()
self.Plot_by_CB.clear()
self.Filters_comboBox.clear()
self.Nuclides_comboBox.clear()
self.Scores_comboBox.clear()
self.Vol_List_LE.clear()
for elm in self.buttons:
elm.setEnabled(False)
self.Graph_Layout_CB.setCurrentIndex(0)
self.Graph_type_CB.setCurrentIndex(0)
self.Graph_Layout_CB.setEnabled(False)
self.score_plot_PB.setEnabled(False)
self.xGrid_CB.setChecked(False)
self.yGrid_CB.setChecked(False)
self.MinorGrid_CB.setChecked(False)
if self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' not in self.Tally_id_comboBox.currentText():
tally_id = int(self.Tally_id_comboBox.currentText())
self.Filters_comboBox.clear()
self.Scores_comboBox.clear()
self.Nuclides_comboBox.clear()
idx = self.Tallies['tallies_ids'].index(tally_id)
name = self.Tallies['names'][idx]
self.Tally_name_LE.setText(name)
self.Filters_comboBox.addItem('Select filter')
self.Tallies[tally_id] = {}
self.Tallies[tally_id]['id'] = [tally_id]
self.Tallies[tally_id]['filter_ids'] = []
self.Tallies[tally_id]['filter_types'] = []
self.Tallies[tally_id]['filter_names'] = []
self.tally = sp.get_tally(id=tally_id)
group = self.tallies_group[f'tally {tally_id}']
self.df = self.tally.get_pandas_dataframe()
self.df_Keys = self.df.keys()[:-2].tolist()
self.n_filters = group['n_filters'][()]
# hide comboBoxes in gridLayout_20
for i in range(self.gridLayout_20.layout().count()):
widget = self.gridLayout_20.layout().itemAt(i).widget()
widget.hide()
# Read all filters
if self.n_filters > 0: # filters are defined
self.Bins_comboBox = [''] * self.n_filters
for i in range(self.n_filters):
self.Bins_comboBox[i] = CheckableComboBox()
row = int(i / 3) + 1
col = i + 4 - row * 3
self.gridLayout_20.addWidget(self.Bins_comboBox[i], row , col)
self.filter_ids = group['filters'][()].tolist()
self.Tallies[tally_id]['filter_ids'] = self.filter_ids
for filter_id in self.filter_ids:
self.Tallies[tally_id][filter_id] = {}
self.Tallies[tally_id][filter_id]['Checked_bins_indices'] = []
self.Tallies[tally_id][filter_id]['Checked_bins'] = []
self.Tallies[tally_id][filter_id]['scores'] = []
filter_group = self.filters_group[f'filter {filter_id}']
new_filter = openmc.Filter.from_hdf5(filter_group, meshes=self.meshes)
filter_name = str(new_filter).split('\n')[0]
filter_type = filter_group['type'][()].decode()
self.Tallies[tally_id]['filter_types'] += [filter_type]
self.Tallies[tally_id]['filter_names'] += [filter_name]
self.Filter_names = self.Tallies[tally_id]['filter_names']
filters = [filter + ' , id= ' + str(id) for filter, id in zip(self.Tallies[tally_id]['filter_names'], self.filter_ids)]
self.Filters_comboBox.addItems(filters)
self.Filters_comboBox.setCurrentIndex(1)
for i in range(len(self.Bins_comboBox)):
self.Bins_comboBox[i].currentIndexChanged.connect(self.SelectBins)
self.Bins_comboBox[i].currentIndexChanged.connect(lambda:self.score_plot_PB.setEnabled(False))
self.filters = self.Tallies[tally_id]['filter_types']
else: # no filter defined
self.Tallies[tally_id]['scores'] = []
# fill scores combobox
self.scores = sorted(self.tally.scores)
self.Tallies[tally_id]['scores'] = self.scores
self.Scores_comboBox.clear()
self.Scores_comboBox.addItem('Select score')
if len(self.scores) > 1:
self.Scores_comboBox.addItem('All scores')
self.Scores_comboBox.addItems(self.scores)
# fill nuclides combobox
self.nuclides = self.tally.nuclides
self.Tallies[tally_id]['nuclides'] = self.nuclides
self.Nuclides_comboBox.clear()
self.Nuclides_comboBox.addItem('Select nuclide')
if len(self.nuclides) > 1:
self.Nuclides_comboBox.addItems(['All nuclides'])
self.Nuclides_comboBox.addItems(self.nuclides)
self.Nuclides_comboBox.setCurrentIndex(1)
if len(self.scores) == 1:
self.Scores_List_LE.setText(self.scores[0])
self.nuclides_display_PB.setEnabled(True)
self.scores_display_PB.setEnabled(True)
self.label.setText('plot by')
self.Plot_by_CB.clear()
elif self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' in self.Tally_id_comboBox.currentText():
self.Checked_batches = []
self.Checked_batches_bins = []
self.Tally_name_LE.setText('Keff vs batches')
self.Filters_comboBox.clear()
self.Filters_comboBox.addItem('Select filter')
self.Filters_comboBox.addItem('Batches Filter')
for i in reversed(range(self.gridLayout_20.count())):
self.gridLayout_20.itemAt(i).widget().setParent(None)
self.Bins_comboBox = ['']
self.Bins_comboBox[0] = CheckableComboBox()
self.gridLayout_20.addWidget(self.Bins_comboBox[0], 0, 0)
self.Filters_comboBox.setCurrentIndex(1)
self.SelectFilter()
self.nuclides_display_PB.setEnabled(False)
self.scores_display_PB.setEnabled(False)
self.score_plot_PB.setEnabled(True)
self.Graph_type_CB.setEnabled(True)
self.Plot_by_CB.setEnabled(True)
self.score_plot_PB.setText('plot Keff')
for bt in self.buttons:
bt.setEnabled(True)
for i in [3, 4]:
self.Graph_type_CB.model().item(i).setEnabled(True)
for i in [1, 2, 5, 6]:
self.Graph_type_CB.model().item(i).setEnabled(False)
self.Bins_comboBox[0].currentIndexChanged.connect(self.SelectBins)
self.Graph_type_CB.setCurrentIndex(3)
self.Curve_title.setText(self.Tally_name_LE.text())
self.Curve_xLabel.setText('batches')
self.Curve_yLabel.setText('Keff')
self.label.setText('plot')
self.Plot_by_CB.clear()
self.Plot_by_CB.addItem('select item')
if self.H:
self.Plot_by_CB.addItems(['Keff', 'Keff & Shannon entropy', 'Shannon entropy'])
else:
self.Plot_by_CB.addItem('Keff')
self.Plot_by_CB.setCurrentIndex(1)
else:
self.Tally_name_LE.clear()
self.Curve_title.clear()
self.Filters_comboBox.clear()
try:
for i in range(len(self.Bins_comboBox)):
self.Bins_comboBox[i].hide()
except:
pass
self.Plot_by_CB.setCurrentIndex(0)
self.Graph_Layout_CB.setCurrentIndex(0)
self.Graph_type_CB.setCurrentIndex(0)
self.Graph_type_CB.setEnabled(False)
power_items = [self.label_21, self.label_22, self.label_16, self.label_17, self.label_18, self.Nu_LE,
self.Heating_LE, self.Keff_LE, self.Q_LE, self.Norm_to_Power_CB, self.Norm_to_Heating_CB,
self.Power_LE, self.Factor_LE]
Norm_Other = [self.label_37, self.label_19, self.label_23, self.Norm_to_BW_CB, self.Norm_to_Vol_CB, self.Norm_to_UnitLethargy_CB,
self.Norm_Bins_comboBox, self.Vol_List_LE]
CBoxes = [self.Norm_to_BW_CB, self.Norm_to_Vol_CB, self.Norm_to_UnitLethargy_CB, self.Norm_to_Power_CB, self.Norm_to_Heating_CB]
for item in power_items:
item.setEnabled(False)
for item in Norm_Other:
item.setEnabled(False)
for CB in CBoxes:
CB.setChecked(False)
self.Norm_Bins_comboBox.clear()
if tally_id != '':
self.lineLabel2.setText('Selected tally id : ' + str(tally_id))
self.lineLabel3.setText(' Tally name : ' + name)
#except:
#pass
def Display_tally(self):
self.Display = False
self.sp_file == self.lineEdit.text()
self.Normalization = False
self.tabWidget_2.setCurrentIndex(0)
cursor = self.editor.textCursor()
cursor.movePosition(cursor.End)
if True:
if os.path.isfile(self.sp_file):
sp = openmc.StatePoint(self.sp_file)
self.tabWidget_2.setCurrentIndex(0)
if self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' not in self.Tally_id_comboBox.currentText():
df = self.tally.get_pandas_dataframe(float_format = '{:.2e}') #'{:.6f}')
tally_id = int(self.Tally_id_comboBox.currentText())
"""cursor.insertText('*'*12*len(df.keys()) + ' TALLY SUMMARY ' + '*'*12*len(df.keys()) + '\n' +
str(self.tally) + '\n\n' +
'*'*12*len(df.keys()) + ' TALLY RESULTS ' + '*'*12*len(df.keys()) + '\n\n')
self.editor.setTextCursor(cursor)"""
self.Print_Formated_df(df.copy(), tally_id, self.editor)
elif self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' in self.Tally_id_comboBox.currentText():
# print Keff results
n = sp.n_batches
keff_glob = sp.global_tallies
INDEX = [str(idx,encoding='utf-8').ljust(25) for idx in keff_glob['name']]
df = pd.DataFrame(keff_glob, index=INDEX, columns = ['name', 'mean', 'std_dev'])
for item in df['name']:
elem = str(item,encoding='utf-8').ljust(25)
df = df.replace({'name': item}, {'name': elem})
df.loc['Combined keff'] = ['Combined keff', self.keff, self.dkeff]
df.iloc[4], df.iloc[3] = df.iloc[3], df.iloc[4]
self.Print_Formated_df_Keff(df, self.editor, '', 0)
# print Keff vs batches
df1 = pd.DataFrame({'batch': [i+1 for i in range(n)], 'Keff': sp.k_generation.tolist()})
self.Print_Formated_df_Keff(df1, self.editor, ' K EFFECTIVE VS BATCH ', 1)
try:
df1 = pd.DataFrame({'batch': [i+1 for i in range(n)], 'Entropy': sp.entropy.tolist()})
self.Print_Formated_df_Keff(df1, self.editor, ' SHANNON ENTROPY ', 1)
except:
pass
else:
self.showDialog('Warning', 'Select Tally first!')
else:
self.showDialog('Warning', 'Select a valid StatePoint file first!')
return
else:
return
def Print_Formated_df(self, df, tally_id, editor):
columns_header = []
LTOT = 0
for key in df.keys():
if type(key) is tuple: # and 'mesh' in key[0]:
KEY = key[0]
KEY1 = key[1]
else:
KEY = key
KEY1 = ''
if KEY1 in ['x', 'y', 'z']: #'mesh' in key:
pass
if 'mesh' in KEY:
FMT = '{:<20}'
elif KEY in ['surface', 'cell', 'cellfrom', 'cellborn', 'universe', 'material', 'collision']:
FMT = '{:<13d}'
elif KEY in ['distribcell']:
FMT = '{:<14d}'
elif KEY in ['delayedgroup']:
FMT = '{:<20d}'
elif KEY in ['energy low [eV]', 'energy high [eV]', 'energyout low [eV]', 'energyout high [eV]',
'polar low [rad]', 'polar high [rad]', 'azimuthal low [rad]',
'azimuthal high [rad]', 'time low [s]', 'time high [s]']:
FMT = '{:<20.3e}'
elif KEY in ['mu low', 'mu high', "mean", "std. dev."]:
FMT = '{:<16.3e}'
elif KEY in ['nuclide', 'particle', 'legendre', 'zernike']:
FMT = '{:<14}'
elif KEY in ['score', 'spatiallegendre', 'sphericalharmonics', 'zernikeradial']:
FMT = '{:<20}'
elif KEY in ['multiplier']:
FMT = '{:<16.6e}'
elif 'level' in KEY:
FMT = '{:<10d}'
df.loc[:, key] = df[key].map(FMT.format)
if True:
LJUST = int(FMT.split('<')[1].split('.')[0].replace('d', '').replace('}', ''))
else:
LJUST = 20
LTOT += LJUST
#for KEY in df.keys():
if type(KEY) is tuple:
if 'mesh' in KEY[0]:
column_name = str(KEY[0] + ', ' + KEY[1]).ljust(LJUST)
else:
column_name = KEY[0].ljust(LJUST)
else:
column_name = KEY.ljust(LJUST)
columns_header.append(column_name)
LTOT += 30
LTOT05 = int(LTOT / 1.5)
df.columns = columns_header
cursor = editor.textCursor()
cursor.movePosition(cursor.End)
cursor.insertText('*'*LTOT + '\n')
if self.Normalization:
cursor.insertText('\n' + ' '*int(LTOT05 * 0.66) + 'Tally ' + str(tally_id) + ' results to be plotted after normalization\n' + '\n')
else:
if self.Display:
cursor.insertText('\n' + ' '*int(LTOT05 * 0.7) + 'Tally ' + str(tally_id) + ' results to be plotted\n' + '\n')
else:
cursor.insertText('\n\n' + '*'*int(LTOT05 * 0.66) + ' TALLY SUMMARY ' + '*'*int(LTOT05 * 0.66) + '\n\n')
cursor.insertText(str(self.tally) + '\n\n')
cursor.insertText('*'*int(LTOT05 * 0.66) + ' TALLY RESULTS ' + '*'*int(LTOT05 * 0.66) + '\n\n\n')
cursor.insertText(' '*LTOT05 + 'Tally id : ' + str(tally_id) + '\n')
cursor.insertText('*'*LTOT + '\n')
cursor.insertText(df.to_csv(sep='\t', index=False))
cursor.insertText('*'*LTOT + '\n\n')
editor.setTextCursor(cursor)
def Print_Formated_df_Keff(self, df, editor, TITLE, j):
cursor = editor.textCursor()
cursor.movePosition(cursor.End)
if j == 0:
cursor.insertText('*'*60 + ' K EFFECTIVE ' + '*'*60 + '\n')
for key in df.keys():
if key in ['mean', 'std_dev']:
df.loc[:, key] = df[key].map('{:<20.6f}'.format)
elif j == 1:
cursor.insertText('*'*55 + TITLE + '*'*55 + '\n')
for key in df.keys():
if 'batch' in key:
df.loc[:, key] = df[key].map('{:d}'.format)
elif 'Keff' in key or 'Entropy' in key:
df.loc[:, key] = df[key].map('{:<20.6f}'.format)
columns_header = [column_name for column_name in df.keys()]
df.columns = columns_header
cursor.insertText(df.to_csv(sep='\t', index=False))
cursor.insertText('*'*134 + '\n')
editor.setTextCursor(cursor)
def SelectFilter(self):
for elm in self.buttons:
elm.setEnabled(False)
self.Graph_Layout_CB.setEnabled(False)
self.score_plot_PB.setEnabled(False)
self.Mesh_xy_RB.hide()
self.Mesh_xz_RB.hide()
self.Mesh_yz_RB.hide()
self.spinBox.hide()
self.spinBox_2.hide()
self.xlabel.setText('xlabel')
self.ylabel.setText('ylabel')
self.score_plot_PB.setText('plot data')
self.Curve_xLabel.clear()
self.Curve_yLabel.clear()
self.Curve_title.clear()
if self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' not in self.Tally_id_comboBox.currentText():
tally_id = int(self.Tally_id_comboBox.currentText())
self.tally = sp.get_tally(id=tally_id)
tally = self.tally
try:
for idx in range(self.n_filters):
self.Bins_comboBox[idx].clear()
except:
pass
if self.Filters_comboBox.currentIndex() > 0:
for idx in range(self.n_filters):
filter_name = self.Tallies[tally_id]['filter_names'][idx]
self.label_4.setText('Select bins')
filter_id = self.filter_ids[idx]
self.Tallies[tally_id][filter_id]['bins'] = [item for item in tally.filters[idx].bins]
Bins = self.Tallies[tally_id][filter_id]['bins']
if 'MeshFilter' in self.Filters_comboBox.currentText():
self.Mesh_xy_RB.show()
self.Mesh_xz_RB.show()
self.Mesh_yz_RB.show()
self.spinBox.show()
self.spinBox_2.show()
self.Mesh_xy_RB.setChecked(True)
self.Curve_xLabel.setText('x/cm')
self.Curve_yLabel.setText('y/cm')
self.Curve_title.setText(self.Tally_name_LE.text())
self.mesh_id = tally.filters[0].mesh.id
self.mesh_type = str(tally.filters[0].mesh).split('\n')[0]
self.mesh_name = tally.name
self.mesh_dimension = tally.filters[0].mesh.dimension
self.mesh_n_dim = tally.filters[0].mesh.n_dimension
print('Meshes : ', tally.filters[0].mesh)
print('*******************************************************************************************')
print('******************** Mesh summary ******************')
print('*******************************************************************************************\n')
if self.mesh_type == 'RectilinearMesh':
self.mesh_LL = (tally.filters[0].mesh.x_grid[0], tally.filters[0].mesh.y_grid[0], tally.filters[0].mesh.z_grid[0],)
self.mesh_UR = (tally.filters[0].mesh.x_grid[-1], tally.filters[0].mesh.y_grid[-1], tally.filters[0].mesh.z_grid[-1],)
print('id : ', self.mesh_id)
print('name : ', self.mesh_name)
print('type : ', self.mesh_type)
print('dimension : ', self.mesh_n_dim)
print('voxels : ', self.mesh_dimension)
print('lower_left : ', self.mesh_LL)
print('upper_right : ', self.mesh_UR, '\n')
print('Tally filters : ', tally.filters, '\n')
print('*******************************************************************************************\n')
else: #self.mesh_type == 'RegularMesh':
self.mesh_width = tally.filters[0].mesh.width
self.mesh_LL = tally.filters[0].mesh.lower_left
self.mesh_UR = tally.filters[0].mesh.upper_right
self.mesh_ids = tally.filters[0].bins
if len(tally.filters[0].mesh._grids) == 3:
self.x = tally.filters[0].mesh._grids[0][:-1] + tally.filters[0].mesh.width[0] * 0.5
self.y = tally.filters[0].mesh._grids[1][:-1] + tally.filters[0].mesh.width[1] * 0.5
self.z = tally.filters[0].mesh._grids[2][:-1] + tally.filters[0].mesh.width[2] * 0.5
self.Mesh_xz_RB.setEnabled(True)
self.Mesh_yz_RB.setEnabled(True)
else:
self.x = tally.filters[0].mesh._grids[0][:-1] + tally.filters[0].mesh.width[0] * 0.5
self.y = tally.filters[0].mesh._grids[1][:-1] + tally.filters[0].mesh.width[1] * 0.5
self.z = ['z axis integrated']
self.mesh_dimension = np.append(self.mesh_dimension, 1)
self.Mesh_xz_RB.setEnabled(False)
self.Mesh_yz_RB.setEnabled(False)
# ******************************************************************************
print('id : ', self.mesh_id)
print('name : ', self.mesh_name)
print('type : ', self.mesh_type)
print('dimension : ', self.mesh_n_dim)
print('voxels : ', self.mesh_dimension)
print('width : ', self.mesh_width)
print('lower_left : ', self.mesh_LL)
print('upper_right : ', self.mesh_UR, '\n')
print('x grid : ', self.x)
print('y grid : ', self.y)
print('z grid : ', self.z, '\n')
print('Tally filters : ', tally.filters, '\n')
print('*******************************************************************************************\n')
self.Tallies[tally_id][filter_id]['slice_x'] = self.x
self.Tallies[tally_id][filter_id]['slice_y'] = self.y
self.Tallies[tally_id][filter_id]['slice_z'] = self.z
self.id_step = self.mesh_dimension[0] * self.mesh_dimension[1]
ij_indices = [(self.mesh_ids[i][0], self.mesh_ids[i][1],) for i in range(self.id_step)]
if len(tally.filters[0].mesh._grids) == 3:
ik_indices = []
for k in range(self.mesh_dimension[2]):
ik_indices += [(self.mesh_ids[i][0], self.mesh_ids[i][2],) for i in
range(k * self.id_step, (k * self.id_step + self.mesh_dimension[0]))]
jk_indices = [(self.mesh_ids[i][1], self.mesh_ids[i][2],) for i in
range(0, len(self.mesh_ids), self.mesh_dimension[0])]
self.Tallies[tally_id][filter_id]['ik_indices'] = ik_indices
self.Tallies[tally_id][filter_id]['jk_indices'] = jk_indices
self.Tallies[tally_id][filter_id]['ij_indices'] = ij_indices
if self.Mesh_xy_RB.isChecked():
if len(tally.filters[0].mesh._grids) == 3:
self.z_id = [item[2] for item in [self.mesh_ids[i] for i in range(0, len(self.mesh_ids), self.id_step)]]
self.list_axis = ['slice at z = ' + str("{:.1E}".format(z_)) for z_ in self.z]
else:
self.z_id = [0]
self.list_axis = ['z axis integrated']
#self.Tallies[tally_id][filter_id]['basis'] = [(x, y,) for y in self.y for x in self.y]
#self.Tallies[tally_id][filter_id]['basis_ids'] = [(i, j,) for i,j in zip(self.mesh_ids[0], self.mesh_ids[1])]
elif self.Mesh_xz_RB.isChecked():
self.id_step1 = self.mesh_dimension[0] * self.mesh_dimension[2]
self.y_id = [item[2] for item in [self.mesh_ids[i] for i in range(0, len(self.mesh_ids), self.id_step)]]
self.list_axis = ['slice at y = ' + str("{:.1E}".format(y_)) for y_ in self.y]
#self.Tallies[tally_id][filter_id]['basis'] = [(x, z,) for z in self.z for x in self.x]
elif self.Mesh_yz_RB.isChecked():
self.id_step2 = self.mesh_dimension[1] * self.mesh_dimension[2]
self.x_id = [item[2] for item in [self.mesh_ids[i] for i in range(0, len(self.mesh_ids), self.id_step)]]
self.list_axis = ['slice at x = ' + str("{:.1E}".format(x_)) for x_ in self.x]
#self.Tallies[tally_id][filter_id]['basis'] = [(y, z,) for z in self.z for y in self.y]
bins = self.list_axis
else:
self.Mesh_xy_RB.hide()
self.Mesh_xz_RB.hide()
self.Mesh_yz_RB.hide()
self.spinBox.hide()
self.spinBox_2.hide()
self.Curve_title.clear()
self.xlabel.setText('xlabel')
self.ylabel.setText('ylabel')
if 'energy low [eV]' in self.df_Keys and filter_name == 'EnergyFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_energies_Low = first
self.Checked_energies_High = last
bins = [str(("{:.3E}".format(x), "{:.3E}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
elif 'energyout low [eV]' in self.df_Keys and filter_name == 'EnergyoutFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_energiesout_Low = first
self.Checked_energiesout_High = last
bins = [str(("{:.3E}".format(x), "{:.3E}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
elif 'mu low' in self.df_Keys and filter_name == 'MuFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_mu_Low = first
self.Checked_mu_High = last
bins = [str(("{:.3f}".format(x), "{:.3f}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
elif 'polar low [rad]' in self.df_Keys and filter_name == 'PolarFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_polar_Low = first
self.Checked_polar_High = last
bins = [str(("{:.3f}".format(x), "{:.3f}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
elif 'azimuthal low [rad]' in self.df_Keys and filter_name == 'AzimuthalFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_azimuthal_Low = first
self.Checked_azimuthal_High = last
bins = [str(("{:.3f}".format(x), "{:.3f}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
elif 'time low [s]' in self.df_Keys and filter_name == 'TimeFilter':
first = [item[0] for item in Bins]
last = [item[1] for item in Bins]
self.Checked_time_Low = first
self.Checked_time_High = last
bins = [str(("{:.3f}".format(x), "{:.3f}".format(y),)).replace("'", "") for x, y in
zip(first, last)]
else:
for KEY in self.df_Keys:
if 'distribcell' in KEY[0] and filter_name == 'DistribcellFilter':
bins = [str(item) for item in range(len(self.tally.mean))]
if KEY in ['cell', 'cellfrom', 'cellborn', 'surface', 'universe', 'material',
'collision', 'particle', 'legendre', 'spatiallegendre',
'sphericalharmonics', 'delayedgroup', 'zernike', 'zernikeradial']:
self.Curve_title.setText(self.Tally_name_LE.text())
bins = sorted([str(item) for item in Bins])
self.Tallies[tally_id][filter_id]['bins'] = bins
self.Bins_comboBox[idx].addItem('Select ' + self.Tallies[tally_id]['filter_names'][idx] + ' bins')
self.Bins_comboBox[idx].addItem('All bins')
self.Bins_comboBox[idx].model().item(0).setEnabled(False)
#self.Bins_comboBox[idx].setItemChecked(0, False)
self.Bins_comboBox[idx].addItems(bins)
if 'MeshFilter' in self.Filters_comboBox.currentText() and len(tally.filters[0].mesh._grids) == 2:
self.Bins_comboBox[self.Filters_comboBox.currentIndex() - 1].setCurrentIndex(2)
try:
if self.Tallies[tally_id][filter_id]['Checked_bins_indices']:
for j in self.Tallies[tally_id][filter_id]['Checked_bins_indices']:
self.Bins_comboBox[idx].setItemChecked(j, False) # (j, True)
else:
for i in range(len(bins) + 1):
self.Bins_comboBox[idx].setItemChecked(i, False)
except:
self.showDialog('Warning', 'Filter bins not checked!')
elif self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' in self.Tally_id_comboBox.currentText():
try:
self.Bins_comboBox[0].clear()
except:
pass
if self.Filters_comboBox.currentIndex() > 0:
self.Bins_comboBox[0].addItem('Select batches')
self.Bins_comboBox[0].model().item(0).setEnabled(False)
self.Bins_comboBox[0].addItem('All bins')
self.Bins_comboBox[0].addItems([str(i) for i in self.batches])
for bt in self.buttons:
bt.setEnabled(True)
self.score_plot_PB.setEnabled(True)
self.Curve_title.setText(self.Tally_name_LE.text())
self.Curve_xLabel.setText('batches')
self.Curve_yLabel.setText('Keff')
self.Graph_type_CB.setEnabled(True)
try:
if self.Checked_batches_bins:
for j in self.Checked_batches_bins:
self.Bins_comboBox[0].setItemChecked(j, False)
else:
for i in range(len(self.batches) + 1):
self.Bins_comboBox[0].setItemChecked(i, False)
except:
self.showDialog('Warning', '** Filter bins not checked!')
else:
self.Graph_type_CB.setEnabled(False)
try:
self.Bins_comboBox[0].clear()
except:
pass
def Display_filters(self):
self.tabWidget_2.setCurrentIndex(0)
cursor = self.editor.textCursor()
cursor.movePosition(cursor.End)
if os.path.isfile(self.sp_file):
if self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' not in self.Tally_id_comboBox.currentText():
tally_id = int(self.Tally_id_comboBox.currentText())
if self.Filters_comboBox.currentIndex() > 0:
for id in self.filter_ids:
Filter_Type = self.Tallies[tally_id]['filter_types'][self.filter_ids.index(id)]
filter_id = id
self.Filter_Bins_Select(tally_id, filter_id)
cursor.insertText('\n************************************************************' +
'\nTally Id : ' + str(tally_id) +
'\nFilter Id : ' + str(filter_id) +
'\nFilter type : ' + Filter_Type +
'\nChecked bins : ' + str(self.Tallies[tally_id][filter_id]['Checked_bins']).replace("'", "") +
'\nChecked bins indices: ' + str(self.checked_bins_indices) +
'\n************************************************************')
elif self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' in self.Tally_id_comboBox.currentText():
self.Filter_Bins_Select(0, 0)
cursor.insertText('\n************************************************************' +
'\nKeff vs batches' +
'\nChecked batches : ' + str(self.Checked_batches) +
'\nChecked batches bins: ' + str(self.Checked_batches_bins) +
'\n************************************************************')
self.Bins_comboBox[0].setCurrentIndex(0)
else:
self.showDialog('Warning', 'Select Tally first!')
else:
self.showDialog('Warning', 'Select your StatePoint file first !')
self.editor.setTextCursor(cursor)
def SelectBins(self):
if self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' not in self.Tally_id_comboBox.currentText():
tally_id = int(self.Tally_id_comboBox.currentText())
self.tally = sp.get_tally(id=tally_id)
_f = h5py.File(self.sp_file, 'r')
tallies_group = _f['tallies']
group = tallies_group[f'tally {tally_id}']
self.n_filters = group['n_filters'][()]
tally = self.tally
for idx in range(self.n_filters):
if self.Filters_comboBox.currentIndex() > 0:
filter_id = self.filter_ids[idx]
if 'MeshFilter' in self.Filters_comboBox.currentText():
if self.Mesh_xy_RB.isChecked():
if len(tally.filters[0].mesh._grids) == 3:
z = self.z[self.Bins_comboBox[self.Filters_comboBox.currentIndex() - 1].currentIndex()-2]
else:
z = self.z[0]
self.xyz = [(x, y) + (z,) for y in self.y[:self.mesh_dimension[1]] for x in self.x[:self.mesh_dimension[0]]]
if self.Mesh_xz_RB.isChecked():
y = self.y[self.Bins_comboBox[self.Filters_comboBox.currentIndex() - 1].currentIndex()-2]
self.xyz = [(x,) + (y,) + (z,) for z in self.z[:self.mesh_dimension[1]] for x in self.x[:self.mesh_dimension[0]]]
if self.Mesh_yz_RB.isChecked():
x = self.x[self.Bins_comboBox[self.Filters_comboBox.currentIndex() - 1].currentIndex()-2]
self.xyz = [(x,) + (y, z) for z in self.z[:self.mesh_dimension[1]] for y in self.y[:self.mesh_dimension[0]]]
self.Filter_Bins_Select(tally_id, filter_id)
self.Bins_comboBox[idx].setCurrentIndex(0)
elif self.Tally_id_comboBox.currentIndex() > 0 and 'Keff' in self.Tally_id_comboBox.currentText():
self.Filter_Bins_Select(0, 0)
self.Bins_comboBox[0].setCurrentIndex(0)
def Filter_Bins_Select(self, tally_id, filter_id):