-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEfsTA.py
1619 lines (1387 loc) · 57.7 KB
/
EfsTA.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
from PyQt5 import QtWidgets as QW
from PyQt5.uic import loadUi
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QColor, QGuiApplication
import PopUps as PU
import ChirpCorrector as CC
import Controller as Cont
import numpy as np
import os as os
import TTIMG
class MainWindow(QW.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = loadUi("gui.ui", self)
self.startUp()
self.functionality()
def startUp(self):
"""
Ensures that upon startup everything is shown correctly.
Returns
-------
None.
"""
self.ui.UI_stack.setCurrentIndex(0)
self.default_palette = QGuiApplication.palette()
self.finalInputs = {}
self.ui.input_tree.header().setSectionResizeMode(QW.QHeaderView.ResizeToContents)
self.radios = QW.QButtonGroup(self)
self.radios.addButton(self.ui.GLA_radio)
self.radios.addButton(self.ui.GTA_radio_preset_model)
self.radios.addButton(self.ui.GTA_radio_custom_model)
self.radios.addButton(self.ui.GTA_radio_custom_matrix)
self.ui.Analysis_stack.setCurrentIndex(0)
self.createTheme()
def onQuit(self):
"""
Resets the color of the application and saves input values.
Returns
-------
None.
"""
EfsTA.setPalette(self.default_palette)
self.saveAllInputs()
self.savePickle()
def functionality(self):
"""
Adds functionality to the respective UI element.
Returns
-------
None.
"""
# All
self.ui.actionTheme.triggered.connect(self.changeTheme)
EfsTA.aboutToQuit.connect(self.onQuit)
# Intro
self.ui.Exp_TA.clicked.connect(self.initTA)
self.ui.Exp_trEPR.clicked.connect(self.initEPR)
# GDV
self.ui.GVD_skip.clicked.connect(lambda: self.ui.UI_stack.setCurrentIndex(3))
self.ui.GVD_correct.clicked.connect(lambda: self.ui.UI_stack.setCurrentIndex(2))
# Chirp
self.ui.Chirp_Browse_Sample.clicked.connect(lambda: self.getFilePaths("button", self.ui.Chirp_Sample_Dir))
self.ui.Chirp_Browse_Solvent.clicked.connect(lambda: self.getFilePaths("button", self.ui.Chirp_Solvent_Dir))
self.ui.Chirp_Browse_Chirp.clicked.connect(lambda: self.getFilePaths("button", self.ui.Chirp_Chirp_Dir))
self.ui.Chirp_Sample_Dir.editingFinished.connect(lambda: self.getFilePaths("text", self.ui.Chirp_Sample_Dir))
self.ui.Chirp_Solvent_Dir.editingFinished.connect(lambda: self.getFilePaths("text", self.ui.Chirp_Solvent_Dir))
self.ui.Chirp_Chirp_Dir.editingFinished.connect(lambda: self.getFilePaths("text", self.ui.Chirp_Chirp_Dir))
self.ui.Chirp_Done.clicked.connect(self.checkChirpFilesIfEmpty)
self.ui.Data_directory.editingFinished.connect(lambda: self.getFolderPaths("text", self.ui.Data_directory))
self.ui.Data_backToChirp.clicked.connect(lambda: self.ui.UI_stack.setCurrentIndex(2))
self.ui.Analysis_stack.currentChanged.connect(self.presentInputs)
self.ui.Data_browse.clicked.connect(lambda: self.getFolderPaths("button", self.ui.Data_directory))
self.ui.input_confirm.clicked.connect(self.finalCheck)
self.ui.GTA_input_custom_model_saved_equations.currentIndexChanged.connect(lambda: self.setCustomModel(self.ui.GTA_input_custom_model_saved_equations.currentIndex()))
self.ui.Data_clear_cache.clicked.connect(self.clearPickle)
self.ui.GTA_open_table.clicked.connect(self.checkIfCustomMatrixSizeEmpty)
self.ui.GTA_custom_model_save.clicked.connect(self.saveCustomModel)
self.ui.GTA_custom_model_del.clicked.connect(self.deleteCustomModel)
self.ui.Plotting_raw.clicked.connect(self.rawPlotting)
self.ui.GTA_input_preset_model_tau.editingFinished.connect(lambda: self.summonRadio("preset"))
self.ui.GTA_input_custom_model_tau.editingFinished.connect(lambda: self.summonRadio("custom"))
self.ui.GLA_input_tau.editingFinished.connect(lambda: self.summonRadio("gla"))
def initTA(self):
self.ui.plot_type.addItems(["fsTA", "nsTA"])
self.ui.plot_xAxis.setText("$\lambda$ / nm")
self.ui.plot_yAxis.setText("delay / ps")
self.ui.plot_zAxis.setText("$\Delta A$")
self.ui.UI_stack.setCurrentIndex(1)
self.ui.plot_type.currentIndexChanged.connect(lambda: self.setAxisTA(self.ui.plot_type.currentIndex()))
def initEPR(self):
self.ui.plot_type.addItems(["μs trEPR", "ms trEPR"])
self.ui.plot_xAxis.setText("$B_0$ / mT")
self.ui.plot_yAxis.setText("time / $\mu$s")
self.ui.plot_zAxis.setText("d$\chi$'' / d$B_0$")
self.ui.UI_stack.setCurrentIndex(3)
self.ui.plot_type.currentIndexChanged.connect(lambda: self.setAxisEPR(self.ui.plot_type.currentIndex()))
###################################Utility#####################################
def readSingleValue(self, UI_element):
'''
Take a QLineEdit, reads the text and returns the value as a float.
Parameters
----------
UI_element : QLineEdit
The UI element from which the input is read..
Returns
-------
value : float
The converted input text.
'''
text = UI_element.text()
if text == "":
value = None
else:
value = float(text)
return value
def readList(self, UI_element):
'''
Take a QLineEdit, reads the text and returns a list of floats.
Parameters
----------
UI_element : QLineEdit
The UI element from which the input is read..
Returns
-------
value : list
A list of the converted text elements.
'''
text = UI_element.text()
if text == "":
values = []
else:
values = text.split(',')
for ind, val in enumerate(values):
if val != "":
values[ind] = float(val)
else:
val.remove("")
return values
def getFolderPaths(self, input_type, UI_element):
'''
Opens a filedialog window for the user to select the folder directory, where the data is stored.
Returns
-------
None.
'''
if input_type == "button":
directory = QW.QFileDialog.getExistingDirectory(self, 'Select Folder')
UI_element.setText(directory)
elif input_type == "text":
directory = UI_element.text()
if UI_element == self.ui.Data_directory:
self.readData(directory)
def getFilePaths(self, input_type, UI_element):
'''
Opens a filedialog window for the user to select a file.
Returns
-------
None.
'''
if input_type == "button":
directory = QW.QFileDialog.getOpenFileName(self, 'Select File')
UI_element.setText(directory[0])
elif input_type == "text":
directory = UI_element.text()
####################################GVD########################################
def checkChirpFilesIfEmpty(self):
'''
Checks which file paths are provided for the import.
Returns
-------
sample_dir : string
Sample measurement file path.
solvent_dir : string
Solvent measurement file path.
chirp_dir : string
Chirp/OKE measurement file path.
'''
sample_dir = self.ui.Chirp_Sample_Dir.text()
solvent_dir = self.ui.Chirp_Solvent_Dir.text()
chirp_dir = self.ui.Chirp_Chirp_Dir.text()
rmBG = True
OKE = True
if sample_dir == "":
self.openFailSafe("Please provide a sample file.")
return
if solvent_dir == "":
rmBG = False
self.openFailSafe("Warning! No background provided. Correction will proceede without background subtraction.")
if chirp_dir == "":
self.openFailSafe("Warning! No chirp/OKE measurment provided. Correction quality will be lower.")
OKE = False
self.ui.Chirp_Manually.setChecked(False)
self.corrChirp(sample_dir, solvent_dir, chirp_dir, rmBG, OKE)
def corrChirp(self, sample_dir, solvent_dir, chirp_dir, rmBG, OKE):
options = {"Scatter": self.ui.Chirp_Scatter.isChecked(),
"Manually": self.ui.Chirp_Manually.isChecked(),
"rmBG": rmBG,
"OKE": OKE
}
x = {"Sample_Dir": sample_dir,
"Solvent_Dir": solvent_dir,
"Chirp_Dir": chirp_dir,
"Wave_Range": self.readList(self.ui.Chirp_Wave_Range),
"Scale": self.readSingleValue(self.ui.Chirp_Scale),
"Exc_Wave": self.readSingleValue(self.ui.Chirp_Exclude_Wave),
"Header": self.ui.Chirp_Header.value(),
"Options": options
}
CCorr = CC.ChirpCorrector(x, self)
CCorr.correctData()
#####################################DATA######################################
def checkIfBrowseEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.Data_directory.text() == "":
self.openFailSafe("Please select a folder directory.")
return True
def readData(self, directory):
self.finalInputs['Directory'] = directory
if directory != "":
self.Controller = Cont.Controller(directory)
path = self.Controller.path + "/"
names = ["delays_filename", "lambdas_filename", "spectra_filename"]
if all(hasattr(self.Controller, attr) for attr in names) is False:
self.openFailSafe('Please make sure the selected folder ' +
'contains *.txt files ending with: \n' +
'"taspectra.txt", "delays.txt" and' +
'"lambda.txt" for TA or \n' +
'"eprspectra.txt", "time.txt" and' +
'"field.txt" for trEPR.')
else:
temp = self.Controller.delays_filename[::-1]
temp = temp.index("/")
name = self.Controller.delays_filename[-temp:-11]
txt = name + "_input_backup"
pickle = path + txt + ".dir"
if os.path.isfile(pickle):
self.setPickle()
else:
self.openFailSafe("Please select a folder directory.")
def getLowerDelayBound(self):
"""
Reads the lower delay bound input by the user if empty returns None.
Returns
-------
delay_lb: float
The lower delay bound input by the user.
"""
return self.readSingleValue(self.ui.Data_delay_input_lb)
def getUpperDelayBound(self):
"""
Reads the upper delay bound input by the user if empty returns None.
Returns
-------
delay_ub: float
The upper delay bound input by the user.
"""
return self.readSingleValue(self.ui.Data_delay_input_ub)
def getLowerWavelengthBound(self):
"""
Reads the lower lambda bound input by the user if empty returns None.
Returns
-------
lambda_lb: float
The lower lambda bound input by the user.
"""
return self.readSingleValue(self.ui.Data_wavelength_input_lb)
def getUpperWavelengthBound(self):
"""
Reads the upper lambda bound input by the user if empty returns None.
Returns
-------
lambda_ub: float
The upper lambda bound input by the user.
"""
return self.readSingleValue(self.ui.Data_wavelength_input_ub)
def getMultiplier(self):
"""
Reads the ΔA data multiplier input by the user if empty returns 1.
Returns
-------
mul : int
The multiplier for the ΔA data input by the user.
"""
if (self.ui.Data_input_multiplier.text() == "" or
int(self.ui.Data_input_multiplier.text()) <= 0):
mul = 1
else:
mul = int(self.ui.Data_input_multiplier.text())
return mul
def checkIfAxisEmpty(self):
"""
Checks if a label for each axis was input.
Returns
-------
None.
"""
if (self.ui.plot_xAxis.text() or self.ui.plot_yAxis.text() or self.ui.plot_zAxis.text()) == "":
self.openFailSafe("Please input guessed lifetimes.")
return True
def getAxis(self):
"""
Reads the labels for each axis and returns them in a list.
Returns
-------
labels : list
A list containing the axis labels x,y,z.
"""
self.Controller.labels = [self.ui.plot_xAxis.text(), self.ui.plot_yAxis.text(), self.ui.plot_zAxis.text()]
def setAxisTA(self, ind):
"""
Sets the axis labels for the selected experiment.
Parameters
----------
ind : int
The index of the experiment type.
Returns
-------
None.
"""
if ind == 0:
self.ui.plot_xAxis.setText("$\lambda$ / nm")
self.ui.plot_yAxis.setText("delay / ps")
self.ui.plot_zAxis.setText("$\Delta A$")
if ind == 1:
self.ui.plot_xAxis.setText("$\lambda$ / nm")
self.ui.plot_yAxis.setText("delay / ns")
self.ui.plot_zAxis.setText("$\Delta A$")
def setAxisEPR(self, ind):
"""
Sets the axis labels for the selected experiment.
Parameters
----------
ind : int
The index of the experiment type.
Returns
-------
None.
"""
if ind == 0:
self.ui.plot_xAxis.setText("$B_0$ / mT")
self.ui.plot_yAxis.setText("time / $\mu$s")
self.ui.plot_zAxis.setText("d$\chi$'' / d$B_0$")
if ind == 1:
self.ui.plot_xAxis.setText("$B_0$ / mT")
self.ui.plot_yAxis.setText("time / ms")
self.ui.plot_zAxis.setText("d$\chi$'' / d$B_0$")
#####################################GLA#######################################
def checkIfGLATauEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.GLA_input_tau.text() == "":
self.openFailSafe("Please input guessed lifetimes.")
return True
def getGLATaus(self):
"""
Reads the lifetimes input by the user, if GLA is selected.
Returns
-------
list
The lifetimes input by the user.
"""
return self.readList(self.ui.GLA_input_tau)
def getGLAOptMethod(self):
"""
Reads the algorithm choice for the minimization of the ChiSquare
function by the user.
Returns
-------
string
The name of the minimization algorithm.
"""
return self.ui.GLA_algorithm_optimize.currentText()
def calculationGLA(self, db, wb):
'''
Starts the calculation for the global lifetime analysis and opens up
a popup window with the results.
Parameters
----------
db : list
Lower and upper bound for the delays.
wb : list
Lower and upper bound for the wavelengths.
Returns
-------
None.
'''
self.tau_fit, spec, res, D_fit, fit_report = self.Controller.calcDAS(self.prepareParam("gla"), db, wb, self.getGLAOptMethod())
self.openPopUpResults(0, self.Controller)
#####################################GTA#######################################
def checkIfBoundsMatch(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.GTA_input_tau_lb.text() != "":
if (self.ui.GTA_input_tau_lb.text().count(",") !=
self.ui.GTA_input_preset_model_tau.text().count(",")):
self.openFailSafe("Please provide a bound for each lifetime.")
return False
if self.ui.GTA_input_tau_ub.text() != "":
if (self.ui.GTA_input_tau_ub.text().count(",") !=
self.ui.GTA_input_preset_model_tau.text().count(",")):
self.openFailSafe("Please provide a bound for each lifetime.")
return False
def getTauBounds(self):
"""
Reads the bounds for the lifetimes during the calculation.
Returns
-------
list
A list containing the lower bounds and upper bounds list.
"""
tau_lb = self.readList(self.ui.GTA_input_tau_lb)
tau_ub = self.readList(self.ui.GTA_input_tau_ub)
if any(isinstance(obj, float) for obj in tau_lb):
tau_lb = [None if item == '' else item for item in tau_lb]
else:
tau_lb = []
if any(isinstance(obj, float) for obj in tau_ub):
tau_ub = [None if item == '' else item for item in tau_ub]
else:
tau_ub = []
return [tau_lb, tau_ub]
def getCustomConcentration(self):
"""
Reads the concentration vector input by the user and returns it.
Returns
-------
c0 : list
The concentration vector set by the user.
"""
c0 = self.readList(self.ui.GTA_input_concentration)
if any(isinstance(obj, float) for obj in c0):
c0 = c0
else:
c0 = []
return c0
def getGTAOptMethod(self):
"""
Returns the current selected optimization algorithm.
Returns
-------
string
The name of the selected optimization algorithm.
"""
return self.ui.GTA_algorithm_optimize.currentText()
def getGTAIvpMethod(self):
"""
Returns the current selected ivp solver algorithm.
Returns
-------
string
The name of the selected ivp solver algorithm.
"""
return self.ui.GTA_algorithm_initial_value_problem.currentText()
def calculationGTA(self, db, wb, model, K):
'''
Starts the calculation for the global target analysis and opens up
a popup window with the results.
Parameters
----------
db : list
Lower and upper bound for the delays.
wb : list
Lower and upper bound for the wavelengths.
model : int/string
The chosen kinetic model.
K : np.ndarray
The kinetic matrix.
Returns
-------
None.
'''
K = np.array(K)
if model == "custom matrix":
self.tau_fit, spec, res, D_fit, fit_report = self.Controller.calcSAS(K, [], self.getCustomConcentration(), db, wb, model, [], [], self.getGTAOptMethod(), self.getGTAIvpMethod())
elif model == "custom model":
self.tau_fit, spec, res, D_fit, fit_report = self.Controller.calcSAS(K, self.prepareParam("custom"), self.getCustomConcentration(), db, wb, model, [], [], self.getGTAOptMethod(), self.getGTAIvpMethod())
else:
self.tau_fit, spec, res, D_fit, fit_report = self.Controller.calcSAS(K, self.prepareParam("preset"), self.getCustomConcentration(), db, wb, model, self.getTauBounds()[0], self.getTauBounds()[1], self.getGTAOptMethod(), self.getGTAIvpMethod())
self.openPopUpResults(model, self.Controller)
#Preset
def getPresetModel(self):
"""
Returns the currently selected kinetic model.
Returns
-------
int
The integer corresponding to a kinetic model.
"""
return self.ui.GTA_preset_model_selection.currentIndex()
def checkIfPresetModelTauEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.GTA_input_preset_model_tau.text() == "":
self.openFailSafe("Please input guessed lifetimes.")
return True
def getGTAPresetModelTaus(self):
"""
Reads the lifetimes input by the user, if a preset model is selected.
Returns
-------
tau : list
The lifetimes input by the user.
"""
return self.readList(self.ui.GTA_input_preset_model_tau)
#Custom
def checkIfCustomModelEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.GTA_input_custom_model_equation.text() == "":
self.openFailSafe("Please input a transition equation.")
return True
elif self.ui.GTA_input_custom_model_tau.text() == "":
self.openFailSafe("Please input guessed lifetimes.")
return True
def getGTACustomModelTaus(self):
"""
Reads the lifetimes input by the user, if a custom model is selected.
Returns
-------
tau : list
The lifetimes input by the user.
"""
return self.readList(self.ui.GTA_input_custom_model_tau)
def saveCustomModel(self):
"""
Saves the currently input transition equation to the combobox.
Returns
-------
None.
"""
if self.ui.GTA_input_custom_model_equation.text() == "":
pass
elif self.ui.GTA_input_custom_model_saved_equations.findText(self.ui.GTA_input_custom_model_equation.text()) != -1:
pass
else:
self.ui.GTA_input_custom_model_saved_equations.addItem(self.ui.GTA_input_custom_model_equation.text())
def deleteCustomModel(self):
"""
Deletes the currently selected transition equation from the combobox.
Returns
-------
None.
"""
if self.ui.GTA_input_custom_model_saved_equations.currentText() == "":
pass
else:
self.ui.GTA_input_custom_model_saved_equations.removeItem(self.ui.GTA_input_custom_model_saved_equations.currentIndex())
def setCustomModel(self, ind):
'''
Sets the custom model to the previously selected model.
Parameters
----------
ind : int
The index of the selected custom model.
Returns
-------
None.
'''
self.ui.GTA_input_custom_model_saved_equations.setCurrentIndex(ind)
model = self.ui.GTA_input_custom_model_saved_equations.currentText()
self.ui.GTA_input_custom_model_equation.setText(model)
def getCustomModelEquation(self):
"""
Returns the custom transition equation.
Returns
-------
str
The custom transition equation.
"""
return self.ui.GTA_input_custom_model_equation.text()
def getCustomModel(self):
'''
Transforms the custom model input by the user as a transition equation into the corresponding kinetic matrix with the input lifetimes.
Returns
-------
M : np.ndarray
The kinetic matrix created from the transition equation and the
lifetime imputs.
'''
#dictionary used to convert species names to corresponding matrix coordinates
letterstonumbers = {"A": 0,
"B": 1,
"C": 2,
"D": 3,
"E": 4,
"F": 5,
"G": 6,
"H": 7,
"I": 8,
"J": 9,
"K": 10,
"L": 11,
"M": 12,
"N": 13,
"O": 14,
"P": 15,
"Q": 16,
"R": 17,
"S": 18,
"T": 19,
"U": 20,
"V": 21,
"W": 22,
"X": 23,
"Y": 24,
"Z": 25,
"v": -1 #not a coordinate just a way to identify void decays
}
#GUI input
eq = self.getCustomModelEquation()
tau = self.getGTACustomModelTaus()
#checks if the equation used arrows
arrow = False
if "->" in eq:
arrow = True
#checks if there are any void transitions
void = False
if "v" in eq:
void = True
#splitting different decay paths
eq_split = eq.split(";")
#splitting each path into involved species
separated_species = []
if arrow is True:
for string in eq_split:
temp = string.split("->")
separated_species.append(temp)
else:
for string in eq_split:
temp = list(string)
separated_species.append(temp)
#forming pairs of two to set up matrix input
paired_species = []
for list_ in separated_species:
for i in range(len(list_) - 1):
paired_species.append([list_[i], list_[i + 1]])
#converting species names to numbers for matrix coordinates
for list_ in paired_species:
for i in range(len(list_)):
list_[i] = letterstonumbers[list_[i]]
#determining and creating the matrix dimensions by unique species
all_letters = np.array(paired_species).flatten()
if void is False:
species = len(np.unique(all_letters))
else:
species = len(np.unique(all_letters)) - 1
M = np.zeros((species, species))
#filling the matrix with the lifetimes using the determined coordinates
tau_index = 0
for list_ in paired_species:
if list_[1] == -1:
M[list_[0]][list_[0]] += tau[tau_index]
else:
if list_[0] < list_[1]:
M[list_[0]][list_[0]] += tau[tau_index]
M[list_[1]][list_[0]] += tau[tau_index]
elif list_[0] > list_[1]:
M[list_[0]][list_[0]] += tau[tau_index]
M[list_[1]][list_[0]] += tau[tau_index]
else:
M[list_[0]][list_[0]] += tau[tau_index]
tau_index += 1
#adjusting the signs for the main diagonal to be negative
N = np.ones((species, species))
np.fill_diagonal(N, -1)
M = M * N
if M[-1][-1] == -0:
M[-1][-1] *= -1
return M
#Matrix
def checkIfCustomMatrixSizeEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if self.ui.GTA_input_rows_and_columns.value() != 0:
self.ui.GTA_radio_custom_matrix.setChecked(True)
self.openPopUpMatrixInput(self.ui.GTA_input_rows_and_columns.value())
else:
self.openFailSafe("Please input a table size.")
return True
def checkIfCustomMatrixEmpty(self):
"""
Checks if the required information is provided, if not opens up a popup
window, letting the user know which information is missing.
Returns
-------
bool
True if empty.
"""
if hasattr(self, 'custom_Matrix') is False:
self.openFailSafe("Please input a kinetic matrix.")
return True
def closePopupMatrix(self, popup):
"""
Transfers the custom matrix input by the user from the popup object to
the main window and closes the popup window.
Parameters
----------
popup : TableWindow
The TableWindow object created by the main window.
Returns
-------
None.
"""
self.custom_Matrix = popup.custom_Matrix
popup.close()
#####################################PREPARE PARAMETERS########################
def summonRadio(self, layout_origin):
"""
Summons radio buttons corresponding to the input lifetimes for the selection
of fixed values.
Parameters
----------
layout_origin : string
"preset","custom" or "gla" depending on the last edited QLineEdit.
Returns
-------
None.
"""
if layout_origin == "preset":
layout = self.ui.GTA_preset_model_fix_layout
taus = self.getGTAPresetModelTaus()
self.ui.GTA_radio_preset_model.setChecked(True)
elif layout_origin == "custom":
layout = self.ui.GTA_custom_model_fix_layout
taus = self.getGTACustomModelTaus()
self.ui.GTA_radio_custom_model.setChecked(True)
elif layout_origin == "gla":
layout = self.ui.GLA_fix_layout
taus = self.getGLATaus()
self.ui.GLA_radio.setChecked(True)
for i in reversed(range(layout.count())):
widgetToRemove = layout.itemAt(i).widget()
widgetToRemove.deleteLater()
for tau in taus:
layout.addWidget(QW.QRadioButton(str(tau), autoExclusive=False))
def prepareParam(self, method):
"""
Prepares the user inputs for the conversion to lmfit parameters.
Parameters
----------
method : string
"preset","custom" or "gla" depending on the selected analysis method.
Returns
-------
prepParam : list
A list containing tuples with the lifetime and a boolean stating if the
lifetime will be varied.
"""
if method == "preset":
layout = self.ui.GTA_preset_model_fix_layout
taus = self.getGTAPresetModelTaus()
elif method == "custom":
layout = self.ui.GTA_custom_model_fix_layout
taus = self.getGTACustomModelTaus()
elif method == "gla":
layout = self.ui.GLA_fix_layout
taus = self.getGLATaus()
widgets = (layout.itemAt(i).widget() for i in range(layout.count()))
if layout.count() == 0:
prepParam = [(t, True) for t in taus]
else:
prepParam = []
for widget in widgets:
if isinstance(widget, QW.QRadioButton):
prepParam.append((float(widget.text()), not widget.isChecked()))
return prepParam
#####################################PLOT######################################
def checkIfWavelengthSlicesEmpty(self):
"""
Checks if the user provided specific wavelengths for data slicing.
If not disables corresponding plot option.
Returns
-------
None.
"""
if self.ui.plot_input_wavelength_slices.text() == "":
self.ui.plot_wavelength_slices.setChecked(False)
def getWavelengthSlices(self):
"""
Reads the lambdas input by the user if empty, returns an empty list.
Returns
-------
user_lambdas: list
A list containing the lambdas input by the user.
"""
return self.readList(self.ui.plot_input_wavelength_slices)
def checkIfDelaySlicesEmpty(self):
"""
Checks if the user provided specific delays for data slicing.
If not disables corresponding plot option.
Returns
-------
None.
"""
if self.ui.plot_input_delay_slices.text() == "":
self.ui.plot_delay_slices.setChecked(False)
def getDelaySlices(self):
"""
Reads the delays input by the user if empty, returns an empty list.