-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsEQE_Analysis.py
4760 lines (3933 loc) · 213 KB
/
sEQE_Analysis.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 28 11:59:40 2018
@author: Anna Jungbluth
"""
import math
import os
import sys
import tkinter as tk
import warnings
from tkinter import filedialog
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import pandas as pd
import seaborn
# for the gui
from PyQt5 import QtWidgets
from numpy import exp, linspace
from scipy.optimize import curve_fit
from tqdm import tqdm
from collections import defaultdict
from scipy.interpolate import interp1d
import sEQE_Analysis_template
from source.add_subtract import subtract_Opt
from source.compilation import compile_EQE, compile_EL, compile_Data
from source.electroluminescence import bb_spectrum
from source.gaussian import calculate_gaussian_absorption, calculate_gaussian_disorder_absorption, \
calculate_MLJ_absorption, calculate_MLJ_disorder_absorption, calculate_combined_fit, calculate_combined_fit_MLJ
from source.normalization import normalize_EQE
from source.plot import plot, set_up_plot, set_up_EQE_plot, set_up_EL_plot
from source.reference_correction import calculate_Power
from source.utils import interpolate, sep_list, get_logger
from source.utils_plot import is_Colour, pick_EQE_Color, pick_EQE_Label, pick_Label
from source.validity import Ref_Data_is_valid, EQE_is_valid, Data_is_valid, Normalization_is_valid, Fit_is_valid, \
StartStop_is_valid
from source.utils_fit import guess_fit, fit_function, calculate_guess_fit, fit_model, fit_model_double, find_best_fit
from source.utils import R_squared
warnings.filterwarnings("ignore")
warnings.simplefilter('ignore', np.RankWarning)
warnings.simplefilter('ignore', np.ComplexWarning)
warnings.filterwarnings('ignore', "Intel MKL ERROR")
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
# Set up the user interface from Designer
self.ui = sEQE_Analysis_template.Ui_MainWindow()
self.ui.setupUi(self)
# Tkinter
root = tk.Tk()
root.withdraw()
# Logger
self.logger = get_logger()
## Page 1 - Calculate EQE
self.ref_1 = []
self.ref_2 = []
self.ref_3 = []
self.ref_4 = []
self.ref_5 = []
self.ref_6 = []
self.data_1 = []
self.data_2 = []
self.data_3 = []
self.data_4 = []
self.data_5 = []
self.data_6 = []
# Handle Browse Buttons
self.ui.browseButton_1.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_1, 1))
self.ui.browseButton_2.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_2, 2))
self.ui.browseButton_3.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_3, 3))
self.ui.browseButton_4.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_4, 4))
self.ui.browseButton_5.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_5, 5))
self.ui.browseButton_6.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_6, 6))
self.ui.browseButton_7.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_7, 7))
self.ui.browseButton_8.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_8, 8))
self.ui.browseButton_9.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_9, 9))
self.ui.browseButton_10.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_10, 10))
self.ui.browseButton_11.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_11, 11))
self.ui.browseButton_12.clicked.connect(lambda: self.writeText(self.ui.textBox_p1_12, 12))
# Handle Calculate Buttons
self.ui.calculateButton_1.clicked.connect(
lambda: self.pre_EQE(self.ref_1, self.data_1, self.ui.startNM_1, self.ui.stopNM_1, 1))
self.ui.calculateButton_2.clicked.connect(
lambda: self.pre_EQE(self.ref_2, self.data_2, self.ui.startNM_2, self.ui.stopNM_2, 2))
self.ui.calculateButton_3.clicked.connect(
lambda: self.pre_EQE(self.ref_3, self.data_3, self.ui.startNM_3, self.ui.stopNM_3, 3))
self.ui.calculateButton_4.clicked.connect(
lambda: self.pre_EQE(self.ref_4, self.data_4, self.ui.startNM_4, self.ui.stopNM_4, 4))
self.ui.calculateButton_5.clicked.connect(
lambda: self.pre_EQE(self.ref_5, self.data_5, self.ui.startNM_5, self.ui.stopNM_5, 5))
self.ui.calculateButton_6.clicked.connect(
lambda: self.pre_EQE(self.ref_6, self.data_6, self.ui.startNM_6, self.ui.stopNM_6, 6))
# Handle Export All Data Button
self.ui.exportButton.clicked.connect(self.export_EQE)
# Handle Clear Plot Button
self.ui.clearButton.clicked.connect(self.clear_plot)
## Page 2 - Plot EQE
self.EQE_1 = []
self.EQE_2 = []
self.EQE_3 = []
self.EQE_4 = []
self.EQE_5 = []
self.EQE_6 = []
self.EQE_7 = []
self.EQE_8 = []
self.EQE_9 = []
self.EQE_10 = []
# Handle Import EQE Buttons
self.ui.browseEQEButton_1.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_1, 'p1'))
self.ui.browseEQEButton_2.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_4, 'p4'))
self.ui.browseEQEButton_3.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_7, 'p7'))
self.ui.browseEQEButton_4.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_10, 'p10'))
self.ui.browseEQEButton_5.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_13, 'p13'))
self.ui.browseEQEButton_6.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_16, 'p16'))
self.ui.browseEQEButton_7.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_19, 'p19'))
self.ui.browseEQEButton_8.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_22, 'p22'))
self.ui.browseEQEButton_9.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_25, 'p25'))
self.ui.browseEQEButton_10.clicked.connect(lambda: self.writeText(self.ui.textBox_p2_28, 'p28'))
# Handle Plot EQE Buttons
self.ui.plotEQEButton_Wavelength.clicked.connect(lambda: self.pre_plot_EQE(0))
self.ui.plotEQEButton_Energy.clicked.connect(lambda: self.pre_plot_EQE(1))
self.ref_label = '$\mathregular{C_{60}}$'
## Page 3 - Fit EQE (Marcus Theory)
self.data_fit_1 = []
self.data_fit_2 = []
# Handle Import EQE Buttons
self.ui.browseFitButton_1.clicked.connect(lambda: self.writeText(self.ui.textBox_f1, 'f1'))
self.ui.browseFitButton_2.clicked.connect(lambda: self.writeText(self.ui.textBox_f4, 'f4'))
# Handle Gaussian Fit Buttons
self.ui.gaussianFit_1.clicked.connect(
lambda: self.pre_fit_EQE(self.data_fit_1, self.ui.startPlot_1, self.ui.stopPlot_1, self.ui.startFit_1,
self.ui.stopFit_1, self.ui.startFitPlot_1, self.ui.stopFitPlot_1,
self.ui.textBox_f1, self.ui.textBox_f2, self.ui.textBox_f3, 1))
self.ui.gaussianFit_2.clicked.connect(
lambda: self.pre_fit_EQE(self.data_fit_2, self.ui.startPlot_2, self.ui.stopPlot_2, self.ui.startFit_2,
self.ui.stopFit_2, self.ui.startFitPlot_2, self.ui.stopFitPlot_2,
self.ui.textBox_f4, self.ui.textBox_f5, self.ui.textBox_f6, 2))
# Handle Heat Map Buttons
self.ui.heatButton_1.clicked.connect(
lambda: self.heatMap(self.data_fit_1, self.ui.startStart_1, self.ui.startStop_1,
self.ui.stopStart_1, self.ui.stopStop_1, self.ui.textBox_f1,
self.ui.textBox_f2, self.ui.textBox_f3, 1))
self.ui.heatButton_2.clicked.connect(
lambda: self.heatMap(self.data_fit_2, self.ui.startStart_2, self.ui.startStop_2,
self.ui.stopStart_2, self.ui.stopStop_2, self.ui.textBox_f4,
self.ui.textBox_f5, self.ui.textBox_f6, 2))
self.ui.clearButton_2.clicked.connect(self.clear_EQE_plot)
## Page 4 - Extended Fits (Marcus Theory)
# Double Fits
self.bias = False
self.tolerance = None
self.data_double = []
# Handle Import Data Button
self.ui.browseDoubleFitButton.clicked.connect(lambda: self.writeText(self.ui.textBox_dF1, 'double1'))
# Handle Double Fit Button
self.ui.doubleFitButton.clicked.connect(lambda: self.double_fit())
# Simultaneous Peak Fitting
self.bias_sim = False
self.tolerance_sim = False
self.data_sim = []
# Handle Import Data Button
self.ui.browseSimFitButton.clicked.connect(lambda: self.writeText(self.ui.textBox_simFit, 'sim'))
# Handle Sim Fit Button
self.ui.simDoubleFitButton_single.clicked.connect(lambda: self.sim_double_fit_single())
self.ui.simDoubleFitButton.clicked.connect(lambda: self.sim_double_fit())
## Page 5 - Fit EQE (MLJ Theory)
self.data_xFit_1 = []
self.S_i = self.ui.Huang_Rhys.value()
self.hbarw_i = self.ui.vib_Energy.value()
# Handle Import EQE Buttons
self.ui.browseButton_extraFit.clicked.connect(lambda: self.writeText(self.ui.textBox_xF1, 'xF1'))
# Handle Fit Button
self.ui.extraFitButton.clicked.connect(
lambda: self.pre_fit_EQE(self.data_xFit_1, self.ui.startExtraPlot, self.ui.stopExtraPlot,
self.ui.startExtraFit, self.ui.stopExtraFit, self.ui.startExtraFitPlot,
self.ui.stopExtraFitPlot, self.ui.textBox_xF1, self.ui.textBox_xF2,
self.ui.textBox_xF3, 'x1'))
# Handle Heat Map Button
self.ui.extraHeatButton.clicked.connect(
lambda: self.heatMap(self.data_xFit_1, self.ui.extraStartStart, self.ui.extraStartStop,
self.ui.extraStopStart, self.ui.extraStopStop, self.ui.textBox_xF1,
self.ui.textBox_xF2, self.ui.textBox_xF3, 'x1'))
# Handle Clear Extra Fit Button
self.ui.clearButton_extraFit.clicked.connect(self.clear_EQE_plot)
# Double Fits
self.bias = False
self.tolerance = None
self.data_extraDouble = []
# Handle Import Data Button
self.ui.browseButton_extraDoubleFit.clicked.connect(lambda: self.writeText(self.ui.textBox_extraDouble, 'xDF1'))
# Handle Double Fit Button
self.ui.extraDoubleFitButton.clicked.connect(lambda: self.double_fit_MLJ())
## Page 6 - Fit EL and EQE
self.EL = []
self.EL_EQE = []
self.Red_EL_cal = []
self.Red_EL_meas = []
self.Red_EQE_meas = []
# Handle Import EL and EQE Data Buttons
self.ui.browseELButton_1.clicked.connect(lambda: self.writeText(self.ui.textBox_EL1, 'el1'))
self.ui.browseELButton_2.clicked.connect(lambda: self.writeText(self.ui.textBox_EL4, 'el2'))
# Handle EL Plot Buttons
self.ui.plotELButton_1.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL, self.ui.startPlot_EL1, self.ui.stopPlot_EL1, 0)) # Plot EL
self.ui.plotELButton_2.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL, self.ui.startPlot_EL2, self.ui.stopPlot_EL2, 1)) # Plot Abs
self.ui.plotELButton_3.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL_EQE, self.ui.startPlot_EQE, self.ui.stopPlot_EQE, 2)) # Plot EQE
# Handle Fit Buttons
self.ui.fitButton_EL1.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL, self.ui.startPlot_EL1, self.ui.stopPlot_EL1, 0, fit=True)) # Fit EL
self.ui.fitButton_EL2.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL, self.ui.startPlot_EL2, self.ui.stopPlot_EL2, 1, fit=True)) # Fit Abs
self.ui.fitButton_EL3.clicked.connect(
lambda: self.pre_plot_EL_EQE(self.EL_EQE, self.ui.startPlot_EQE, self.ui.stopPlot_EQE, 2,
fit=True)) # Fit EQE
# Handle Clear EL Plot Button
self.ui.clearButton_EL.clicked.connect(lambda: self.clear_EL_plot())
## Page 7 - Subtract and Add Peak Fits
# Subtract Peak Fits
self.data_subFit = []
self.data_subEQE = []
# Handle Import Fit and EQE Data Buttons
self.ui.browseSubButton_Fit.clicked.connect(lambda: self.writeText(self.ui.textBox_p6_1, 'sub1'))
self.ui.browseSubButton_EQE.clicked.connect(lambda: self.writeText(self.ui.textBox_p6_4, 'sub2'))
# Handle Subtract Fit Data Button
self.ui.subButton.clicked.connect(
lambda: self.subtract_Fit(self.data_subFit, self.data_subEQE, self.ui.textBox_p6_2, self.ui.textBox_p6_5,
self.ui.textBox_p6_3, self.ui.textBox_p6_6))
# Add Peak Fits
self.data_addOptFit = []
self.data_addCTFit = []
self.data_addEQE = []
# Handle Import Fit and EQE Data Buttons
self.ui.browseAddButton_optFit.clicked.connect(lambda: self.writeText(self.ui.textBox_p7_1, 'add1'))
self.ui.browseAddButton_CTFit.clicked.connect(lambda: self.writeText(self.ui.textBox_p7_4, 'add2'))
self.ui.browseAddButton_EQE.clicked.connect(lambda: self.writeText(self.ui.textBox_p7_7, 'add3'))
# Handle Plot Fit Button
self.ui.plotAddButton.clicked.connect(
lambda: self.add_Fits(self.data_addOptFit, self.data_addCTFit, self.data_addEQE))
# Import Photodiode Calibration Files
Si_file = pd.ExcelFile(
"calibration_files/FDS100-CAL.xlsx") # The files are in the sEQE Analysis folder, just as this program
self.Si_cal = Si_file.parse('Sheet1')
InGaAs_file = pd.ExcelFile("calibration_files/FGA21-CAL.xlsx")
self.InGaAs_cal = InGaAs_file.parse('Sheet1')
# Define Variables
# NOTE: Modify path if switching from Linux to another operating system
self.data_dir = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
self.h = 6.626 * math.pow(10, -34) # [m^2 kg/s]
self.h_2 = 4.136 * math.pow(10, -15) # [eV s]
self.c = 2.998 * math.pow(10, 8) # [m/s]
self.q = 1.602 * math.pow(10, -19) # [C]
self.k = 8.617 * math.pow(10, -5) # [ev/K]
self.export = False
self.do_plot = True
self.fit_plot = True
self.do_plot_EL = True
# Define parameters for initial guesses
# NOTE: Modify initial guesses if fit is unsuccessful
# NOTE: Some of these parameters are repeated/hard coded in utils_fit.py
# These values are used in standard/disorder, Marcus/MLJ, EQE/EL fitting functions
# Make sure to understand where the parameters all change if they are adjusted here!
self.f_guess = 0.001
self.l_guess = 0.150
# These values are used for disorder Marcus / MLJ fitting functions
# self.bounds_sig = ([0, 0, 0, 0], [0.1, 0.4, 1.6, 0.2]) # f, l, E, sig
# Normal Bounds:
self.bounds_sig = ([0, 0, 0, 0], [0.1, 0.6, 1.6, 0.2]) # f, l, E, sig
# # Adjusted Bounds:
# self.bounds_sig = ([0, 0, 0, 0], [0.1, 0.6, 1.7, 0.2]) # f, l, E, si
# These values are used in the standard/disorder simultaneous double peak fitting
# CAVEAT: I tried using the guess_fit function to test other guesses but didn't achieve great results
# CAVEAT: The other fit functions start with an peak energy guess of 1.2 eV instead of 1.3 eV
self.sim_guess = [0.001, 0.150, 1.30, 0.01, 0.150, 1.5] # fCT, lCT, ECT, fopt, lopt, Eopt
self.sim_guess_sig = [0.001, 0.150, 1.30, 0.01, 0.150, 1.5, 0.1] # fCT, lCT, ECT, fopt, lopt, Eopt, sig
# Set floating point precision
precision = 8 # decimal places
# -----------------------------------------------------------------------------------------------------------
# Functions to read file and update textbox
# -----------------------------------------------------------------------------------------------------------
def writeText(self,
text_Box,
textBox_no
):
"""Function to load data and update text box in GUI
Parameters
----------
text_Box : gui object, required
GUI text box to write filename into
textBox_no : int or str, required
GUI textbox with information on which variable to define
Returns
-------
None
"""
os.chdir(self.data_dir)
file_ = filedialog.askopenfilename()
if len(file_) != 0:
path_, filename_ = os.path.split(file_)
text_Box.clear() # Clear the text box in case sth has been uploaded already
text_Box.insertPlainText(filename_) # Insert filename into text box
## Page 1 - Calculate EQE
# Reference files:
if textBox_no == 1:
self.ref_1 = pd.read_csv(file_) # Turn file into dataFrame
elif textBox_no == 3:
self.ref_2 = pd.read_csv(file_)
elif textBox_no == 5:
self.ref_3 = pd.read_csv(file_)
elif textBox_no == 7:
self.ref_4 = pd.read_csv(file_)
elif textBox_no == 9:
self.ref_5 = pd.read_csv(file_)
elif textBox_no == 11:
self.ref_6 = pd.read_csv(file_)
# Data files:
elif textBox_no == 2:
self.data_1 = pd.read_csv(file_)
elif textBox_no == 4:
self.data_2 = pd.read_csv(file_)
elif textBox_no == 6:
self.data_3 = pd.read_csv(file_)
elif textBox_no == 8:
self.data_4 = pd.read_csv(file_)
elif textBox_no == 10:
self.data_5 = pd.read_csv(file_)
elif textBox_no == 12:
self.data_6 = pd.read_csv(file_)
## Page 2 - Plot EQE
elif textBox_no == 'p1':
self.EQE_1 = pd.read_csv(file_)
elif textBox_no == 'p4':
self.EQE_2 = pd.read_csv(file_)
elif textBox_no == 'p7':
self.EQE_3 = pd.read_csv(file_)
elif textBox_no == 'p10':
self.EQE_4 = pd.read_csv(file_)
elif textBox_no == 'p13':
self.EQE_5 = pd.read_csv(file_)
elif textBox_no == 'p16':
self.EQE_6 = pd.read_csv(file_)
elif textBox_no == 'p19':
self.EQE_7 = pd.read_csv(file_)
elif textBox_no == 'p22':
self.EQE_8 = pd.read_csv(file_)
elif textBox_no == 'p25':
self.EQE_9 = pd.read_csv(file_)
elif textBox_no == 'p28':
self.EQE_10 = pd.read_csv(file_)
## Page 3 - Fit EQE (Marcus Theory)
elif textBox_no == 'f1':
self.data_fit_1 = pd.read_csv(file_)
elif textBox_no == 'f4':
self.data_fit_2 = pd.read_csv(file_)
## Page 4 - Extended Fits (Marcus Theory)
# For Double Fits
elif textBox_no == 'double1':
self.data_double = pd.read_csv(file_)
# For Simultaneous Fits
elif textBox_no == 'sim':
self.data_sim = pd.read_csv(file_)
## Page 5 - Fit EQE (MLJ Theory)
elif textBox_no == 'xF1':
self.data_xFit_1 = pd.read_csv(file_)
elif textBox_no == 'xDF1':
self.data_extraDouble = pd.read_csv(file_)
## Page 6 - Fit EL and EQE
elif textBox_no == 'el1':
self.EL = pd.read_table(file_, sep=',', index_col=0)
elif textBox_no == 'el2':
self.EL_EQE = pd.read_csv(file_)
## Page 7 - Subtract and Add Peak Fits
# Subtract Peak Fits
elif textBox_no == 'sub1':
self.data_subFit = pd.read_csv(file_)
elif textBox_no == 'sub2':
self.data_subEQE = pd.read_csv(file_)
# Add Peak Fits
elif textBox_no == 'add1':
self.data_addOptFit = pd.read_csv(file_)
elif textBox_no == 'add2':
self.data_addCTFit = pd.read_csv(file_)
elif textBox_no == 'add3':
self.data_addEQE = pd.read_csv(file_)
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# Page 1 - Calculate EQE
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# Function to select data and reference files
def pre_EQE(self,
ref_df,
data_df,
start,
stop,
range_no
):
"""Wrapper function to load variables and data for EQE calculation
Parameters
----------
ref_df : dataFrame, required
Dataframe with reference diode measurement
data_df : dataFrame, required
Dataframe with sample measurement
start : gui object, required
GUI field with start wavelength
stop : gui object, required
GUI field with stop wavelength
range_no : int, required
Number specifying which data range to compile
Returns
-------
None
"""
startNM = start.value()
stopNM = stop.value()
if Ref_Data_is_valid(ref_df, data_df, startNM, stopNM, range_no):
self.calculate_EQE(ref_df, data_df, startNM, stopNM, range_no)
# -----------------------------------------------------------------------------------------------------------
# Function to calculate EQE
def calculate_EQE(self,
ref_df,
data_df,
startNM,
stopNM,
range_no
):
"""Function to calculate EQE from signal and reference data
Parameters
----------
ref_df : dataFrame, required
Dataframe with reference diode measurement
data_df : dataFrame, required
Dataframe with sample measurement
startNM : float, required
Start wavelength [nm]
stop : float, required
Stop wavelength [nm]
range_no : int, required
Number specifying which data range to compile
Returns
-------
None
"""
power_dict = {}
Wavelength = []
Energy = []
EQE = []
log_EQE = []
if 'Power' not in ref_df.columns:
self.logger.info('Calculating power values.')
if range_no == 1:
if self.ui.Range1_Si_button.isChecked() and not self.ui.Range1_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range1_InGaAs_button.isChecked() and not self.ui.Range1_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
elif range_no == 2:
if self.ui.Range2_Si_button.isChecked() and not self.ui.Range2_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range2_InGaAs_button.isChecked() and not self.ui.Range2_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
elif range_no == 3:
if self.ui.Range3_Si_button.isChecked() and not self.ui.Range3_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range3_InGaAs_button.isChecked() and not self.ui.Range3_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
elif range_no == 4:
if self.ui.Range4_Si_button.isChecked() and not self.ui.Range4_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range4_InGaAs_button.isChecked() and not self.ui.Range4_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
elif range_no == 5:
if self.ui.Range5_Si_button.isChecked() and not self.ui.Range5_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range5_InGaAs_button.isChecked() and not self.ui.Range5_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
elif range_no == 6:
if self.ui.Range6_Si_button.isChecked() and not self.ui.Range6_InGaAs_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.Si_cal)
except:
self.logger.error('Please select a valid reference diode.')
elif self.ui.Range6_InGaAs_button.isChecked() and not self.ui.Range6_Si_button.isChecked():
try:
ref_df['Power'] = calculate_Power(ref_df, self.InGaAs_cal)
except:
self.logger.error('Please select a valid reference diode.')
else:
self.logger.error('Please select a valid reference diode.')
if 'Power' in ref_df.columns: # Check if the power has been calculated already
for x in range(len(ref_df['Wavelength'])): # Iterate through columns of reference file
power_dict[ref_df['Wavelength'][x]] = ref_df['Power'][
x] # Add wavelength and corresponding power to dictionary
for y in range(len(data_df['Wavelength'])): # Iterate through columns of data file
if startNM <= data_df['Wavelength'][y] <= stopNM: # Calculate EQE if start <= wave <= stop, else ignore
if data_df['Wavelength'][y] in power_dict.keys(): # Check if data wavelength is in reference file
Wavelength.append(data_df['Wavelength'][y])
Energy_val = (self.h * self.c) / (
data_df['Wavelength'][y] * math.pow(10, -9) * self.q) # Calculate energy in eV
Energy.append(Energy_val)
EQE_val = (data_df['Mean Current'][y] * Energy_val) / (
power_dict[data_df['Wavelength'][y]]) # Easier way to calculate EQE
# EQE_val = ((data_df['Mean Current'][y] * self.h * self.c) / (
# data_df['Wavelength'][y] * math.pow(10,-9) * power_dict[data_df['Wavelength'][y]] * self.q))
# EQE_val = (100 * data_df['Mean Current'][y] * Energy_val) / (
# power_dict[data_df['Wavelength'][y]]) # *100 to turn into percent
EQE.append(EQE_val)
log_EQE.append(math.log10(EQE_val))
else: # If data wavelength is not in reference file
Wavelength.append(data_df['Wavelength'][y])
Energy_val = (self.h * self.c) / (data_df['Wavelength'][y] * math.pow(10, -9) * self.q)
Energy.append(Energy_val)
Power_int = interpolate(data_df['Wavelength'][y], ref_df['Wavelength'],
ref_df['Power']) # Interpolate power
EQE_int = (data_df['Mean Current'][y] * Energy_val) / (Power_int)
# EQE_int = ((data_df['Mean Current'][y] * self.h * self.c) / (
# data_df['Wavelength'][y] * math.pow(10,-9) * Power_int * self.q))
EQE.append(EQE_int)
log_EQE.append(math.log10(EQE_int))
if len(Wavelength) == len(EQE) and len(Energy) == len(log_EQE): # Check if the lists have the same length
if self.export: # If the "Export Data" button has been clicked
return (Wavelength, Energy, EQE, log_EQE)
else: # If the "Calculate EQE" button has been clicked
if self.do_plot: # This is set to true during setup of the program
self.ax1, self.ax2 = set_up_plot()
self.do_plot = False # Set self.do_plot to False to plot on the same graph
label_ = pick_Label(range_no, startNM, stopNM)
self.ax1.plot(Wavelength, EQE, linewidth=3, label=label_)
self.ax2.semilogy(Wavelength, EQE,
linewidth=3) # Equivalent to the line above but with proper log scale axes
self.ax1.legend()
plt.draw()
else:
self.logger.error('Length mismatch.')
# -----------------------------------------------------------------------------------------------------------
# Function to export EQE
def export_EQE(self):
"""Function to export EQE to csv file
Parameters
----------
None
Returns
-------
None
"""
self.export = True
ok_1 = True # Create boolean variable to use for "is_valid" function
ok_2 = True
ok_3 = True
ok_4 = True
ok_5 = True
ok_6 = True
columns = ['Wavelength', 'Energy', 'EQE', 'Log_EQE'] # Columns for dataFrame
export_file = pd.DataFrame(columns=columns) # Create empty dataFrame
wave_inc = {} # create empty dictionary
if self.ui.exportBox_1.isChecked(): # If the checkBox is checked
startNM1 = self.ui.startNM_1.value() # Pick start wavelength
stopNM1 = self.ui.stopNM_1.value() # Pick stop wavelength
if Ref_Data_is_valid(self.ref_1, self.data_1, startNM1, stopNM1,
1): # Check that files are non-empty and within wavelength range
Wave_1, Energy_1, EQE_1, log_EQE_1 = self.calculate_EQE(self.ref_1, self.data_1, startNM1, stopNM1,
1) # Extract data
export_1 = pd.DataFrame({'Wavelength': Wave_1, 'Energy': Energy_1, 'EQE': EQE_1,
'Log_EQE': log_EQE_1}) # Create dataFrame with EQE data
wave_inc['1'] = Wave_1[0] # Add the first wavelength value to the wave_inc list
else:
ok_1 = False # Set variable to False if calculation is invalid
if self.ui.exportBox_2.isChecked():
startNM2 = self.ui.startNM_2.value()
stopNM2 = self.ui.stopNM_2.value()
if Ref_Data_is_valid(self.ref_2, self.data_2, startNM2, stopNM2, 2):
Wave_2, Energy_2, EQE_2, log_EQE_2 = self.calculate_EQE(self.ref_2, self.data_2, startNM2, stopNM2, 2)
export_2 = pd.DataFrame({'Wavelength': Wave_2, 'Energy': Energy_2, 'EQE': EQE_2, 'Log_EQE': log_EQE_2})
wave_inc['2'] = Wave_2[0]
else:
ok_2 = False
if self.ui.exportBox_3.isChecked():
startNM3 = self.ui.startNM_3.value()
stopNM3 = self.ui.stopNM_3.value()
if Ref_Data_is_valid(self.ref_3, self.data_3, startNM3, stopNM3, 3):
Wave_3, Energy_3, EQE_3, log_EQE_3 = self.calculate_EQE(self.ref_3, self.data_3, startNM3, stopNM3, 3)
export_3 = pd.DataFrame({'Wavelength': Wave_3, 'Energy': Energy_3, 'EQE': EQE_3, 'Log_EQE': log_EQE_3})
wave_inc['3'] = Wave_3[0]
else:
ok_3 = False
if self.ui.exportBox_4.isChecked():
startNM4 = self.ui.startNM_4.value()
stopNM4 = self.ui.stopNM_4.value()
if Ref_Data_is_valid(self.ref_4, self.data_4, startNM4, stopNM4, 4):
Wave_4, Energy_4, EQE_4, log_EQE_4 = self.calculate_EQE(self.ref_4, self.data_4, startNM4, stopNM4, 4)
export_4 = pd.DataFrame({'Wavelength': Wave_4, 'Energy': Energy_4, 'EQE': EQE_4, 'Log_EQE': log_EQE_4})
wave_inc['4'] = Wave_4[0]
else:
ok_4 = False
if self.ui.exportBox_5.isChecked():
startNM5 = self.ui.startNM_5.value()
stopNM5 = self.ui.stopNM_5.value()
if Ref_Data_is_valid(self.ref_5, self.data_5, startNM5, stopNM5, 5):
Wave_5, Energy_5, EQE_5, log_EQE_5 = self.calculate_EQE(self.ref_5, self.data_5, startNM5, stopNM5, 5)
export_5 = pd.DataFrame({'Wavelength': Wave_5, 'Energy': Energy_5, 'EQE': EQE_5, 'Log_EQE': log_EQE_5})
wave_inc['5'] = Wave_5[0]
else:
ok_5 = False
if self.ui.exportBox_6.isChecked():
startNM6 = self.ui.startNM_6.value()
stopNM6 = self.ui.stopNM_6.value()
if Ref_Data_is_valid(self.ref_6, self.data_6, startNM6, stopNM6, 6):
Wave_6, Energy_6, EQE_6, log_EQE_6 = self.calculate_EQE(self.ref_6, self.data_6, startNM6, stopNM6, 6)
export_6 = pd.DataFrame({'Wavelength': Wave_6, 'Energy': Energy_6, 'EQE': EQE_6, 'Log_EQE': log_EQE_6})
wave_inc['6'] = Wave_6[0]
else:
ok_6 = False
if ok_1 and ok_2 and ok_3 and ok_4 and ok_5 and ok_6: # Check if all operations are ok or if fields are empty
for x in range(len(wave_inc.keys())): # Iterate through wave_inc list
minimum = min(wave_inc, key=wave_inc.get) # Find key corresponding to minimum value
if minimum == '1': # Append correct dataFrame in order of decending wavelength
export_file = export_file.append(export_1, ignore_index=True)
elif minimum == '2':
export_file = export_file.append(export_2, ignore_index=True)
elif minimum == '3':
export_file = export_file.append(export_3, ignore_index=True)
elif minimum == '4':
export_file = export_file.append(export_4, ignore_index=True)
elif minimum == '5':
export_file = export_file.append(export_5, ignore_index=True)
elif minimum == '6':
export_file = export_file.append(export_6, ignore_index=True)
del wave_inc[minimum] # Delete recently appended value
EQE_file = filedialog.asksaveasfilename() # Prompt the user to pick a folder & name to save data to
export_path, export_filename = os.path.split(EQE_file)
if len(export_path) != 0: # Check if the user actually selected a path
os.chdir(export_path) # Change the working directory
export_file.to_csv(export_filename) # Save data to csv
self.logger.info('Saving data to: %s' % str(EQE_file))
os.chdir(self.data_dir) # Change the directory back
self.export = False
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# Page 2 - Calculate EQE
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# Function to select EQE for plotting
def pre_plot_EQE(self,
number
):
"""Wrapper function to select EQE file for plotting
Parameters
----------
number : int, required
Number of the EQE file to plot
Returns
-------
None
"""
ok_EQE_1 = True
ok_EQE_2 = True
ok_EQE_3 = True
ok_EQE_4 = True
ok_EQE_5 = True
ok_EQE_6 = True
ok_EQE_7 = True
ok_EQE_8 = True
ok_EQE_9 = True
ok_EQE_10 = True
if self.ui.normalizeBox.isChecked():
norm_num = 1
else:
norm_num = 0
self.axEQE_1, self.axEQE_2 = set_up_EQE_plot(number, norm_num)
if self.ui.plotBox_1.isChecked():
ok_EQE_1 = self.plot_EQE(self.EQE_1, self.ui.startEQE_1, self.ui.stopEQE_1, self.ui.textBox_p2_1,
self.ui.textBox_p2_2, self.ui.textBox_p2_3, 1, number)
if self.ui.plotBox_2.isChecked():
ok_EQE_2 = self.plot_EQE(self.EQE_2, self.ui.startEQE_2, self.ui.stopEQE_2, self.ui.textBox_p2_4,
self.ui.textBox_p2_5, self.ui.textBox_p2_6, 2, number)
if self.ui.plotBox_3.isChecked():
ok_EQE_3 = self.plot_EQE(self.EQE_3, self.ui.startEQE_3, self.ui.stopEQE_3, self.ui.textBox_p2_7,
self.ui.textBox_p2_8, self.ui.textBox_p2_9, 3, number)
if self.ui.plotBox_4.isChecked():
ok_EQE_4 = self.plot_EQE(self.EQE_4, self.ui.startEQE_4, self.ui.stopEQE_4, self.ui.textBox_p2_10,
self.ui.textBox_p2_11, self.ui.textBox_p2_12, 4, number)
if self.ui.plotBox_5.isChecked():
ok_EQE_5 = self.plot_EQE(self.EQE_5, self.ui.startEQE_5, self.ui.stopEQE_5, self.ui.textBox_p2_13,
self.ui.textBox_p2_14, self.ui.textBox_p2_15, 5, number)
if self.ui.plotBox_6.isChecked():
ok_EQE_6 = self.plot_EQE(self.EQE_6, self.ui.startEQE_6, self.ui.stopEQE_6, self.ui.textBox_p2_16,
self.ui.textBox_p2_17, self.ui.textBox_p2_18, 6, number)
if self.ui.plotBox_7.isChecked():
ok_EQE_7 = self.plot_EQE(self.EQE_7, self.ui.startEQE_7, self.ui.stopEQE_7, self.ui.textBox_p2_19,
self.ui.textBox_p2_20, self.ui.textBox_p2_21, 7, number)
if self.ui.plotBox_8.isChecked():
ok_EQE_8 = self.plot_EQE(self.EQE_8, self.ui.startEQE_8, self.ui.stopEQE_8, self.ui.textBox_p2_22,
self.ui.textBox_p2_23, self.ui.textBox_p2_24, 8, number)
if self.ui.plotBox_9.isChecked():
ok_EQE_9 = self.plot_EQE(self.EQE_9, self.ui.startEQE_9, self.ui.stopEQE_9, self.ui.textBox_p2_25,
self.ui.textBox_p2_26, self.ui.textBox_p2_27, 9, number)
if self.ui.plotBox_10.isChecked():
ok_EQE_10 = self.plot_EQE(self.EQE_10, self.ui.startEQE_10, self.ui.stopEQE_10, self.ui.textBox_p2_28,
self.ui.textBox_p2_29, self.ui.textBox_p2_30, 10, number)
if ok_EQE_1 and ok_EQE_2 and ok_EQE_3 and ok_EQE_4 and ok_EQE_5 and ok_EQE_6 and ok_EQE_7 and ok_EQE_8 and \
ok_EQE_9 and ok_EQE_10:
self.axEQE_1.legend()
self.axEQE_2.legend()
# self.axEQE_1.legend(frameon=False, fontsize=13) # Adjusted style
# self.axEQE_2.legend(frameon=False, fontsize=13) # Adjusted style
plt.show()
else:
plt.close()
plt.close()
# -----------------------------------------------------------------------------------------------------------
# Function to plot EQE
def plot_EQE(self,
eqe_df,
startNM,
stopNM,
filename_Box,
label_Box,
color_Box,
file_no,
number
):
"""Function to plot EQE data
Parameters
----------
eqe_df : dataFrame, required
Dataframe with EQE data
startNM : float, required
Start wavelength [nm]
stop : float, required
Stop wavelength [nm]
filename_Box : gui object, required
GUI textbox with filename information for plot labeling
label_Box : gui object, required
GUI textbox with plot label
color_Box : gui object, required
GUI textbox with plot color
file_no : int, required
Number of EQE file/data range to plot
number : int, required