2525# local module imports
2626try :
2727 from Lifetime_analysis .Fit_functions import stretch_exp_fit , double_exp_fit , single_exp_fit
28- from Lifetime_analysis .picoharp_phd import read_picoharp_phd
28+ from Lifetime_analysis .read_ph_phd import read_picoharp_phd
2929 from Lifetime_analysis .Fit_functions_with_irf import fit_exp_stretch_diffev , fit_exp_stretch_fmin_tnc , fit_multi_exp_diffev , fit_multi_exp_fmin_tnc
3030except :
3131 from Fit_functions import stretch_exp_fit , double_exp_fit , single_exp_fit
3232 from Fit_functions_with_irf import fit_exp_stretch_diffev , fit_exp_stretch_fmin_tnc , fit_multi_exp_diffev , fit_multi_exp_fmin_tnc
33- from picoharp_phd import read_picoharp_phd
33+ from read_ph_phd import read_picoharp_phd
3434
3535"""Recylce params for plotting"""
3636plt .rc ('xtick' , labelsize = 20 )
@@ -95,10 +95,12 @@ def __init__(self):
9595 self .file = None
9696 self .out = None # output file after fitting
9797 self .data_list = []
98- self .fit_lifetime_called = False
98+ self .fit_lifetime_called_w_irf = False
99+ self .fit_lifetime_called_wo_irf = False
99100 self .x_mem = [] # containers for adding x data to memory
100101 self .y_mem = [] # containers for adding y data to memory
101102 self .best_fit_mem = [] # containers for adding best fit data to memory
103+ self .best_fit_mem_x = [] # containers for adding best fit data to memory
102104 self .legend = [] # containers for adding legend to memory
103105
104106 #variables accounting for data received from FLIM analysis
@@ -127,6 +129,10 @@ def open_with_skip_rows_window(self):
127129 skip_rows = self .skip_rows_window .ui .skip_rows_spinBox .value ()
128130 if ".txt" in self .filename [0 ]:
129131 self .file = np .loadtxt (self .filename [0 ], skiprows = skip_rows )
132+
133+ if self .file .ndim == 1 : # if there is only one trace, reshape to 2D
134+ self .file = self .file .reshape (self .file .shape [0 ], 1 )
135+
130136 elif ".csv" in self .filename [0 ]:
131137 self .file = np .genfromtxt (self .filename [0 ], skip_header = skip_rows , delimiter = "," )
132138
@@ -147,6 +153,10 @@ def open_irf_with_skip_rows_window(self):
147153 irf_skip_rows = self .irf_skip_rows_window .ui .skip_rows_spinBox .value ()
148154 if ".txt" in self .irf_filename [0 ]:
149155 self .irf_file = np .loadtxt (self .irf_filename [0 ], skiprows = irf_skip_rows )
156+
157+ if self .irf_file .ndim == 1 : # if there is only one trace, reshape to 2d array
158+ self .irf_file = self .irf_file .reshape (self .irf_file .shape [0 ], 1 )
159+
150160 elif ".csv" in self .irf_filename [0 ]:
151161 self .irf_file = np .genfrontxt (self .irf_filename [0 ], skip_header = irf_skip_rows , delimiter = "," )
152162
@@ -258,7 +268,8 @@ def plot(self):
258268 x ,y = self .acquire_settings () #get data
259269
260270 self .ui .plot .plot (x , y , clear = self .ui .clear_plot_checkBox .isChecked (), pen = pg .mkPen (self .plot_color ))
261- self .fit_lifetime_called = False
271+ self .fit_lifetime_called_w_irf = False
272+ self .fit_lifetime_called_wo_irf = False
262273
263274 try :
264275 self .ui .Result_textBrowser .setText ("Integral Counts :\n " "{:.2E}" .format (
@@ -303,7 +314,7 @@ def fit_and_plot(self):
303314 self .ui .plot .plot (t , y , clear = self .ui .clear_plot_checkBox .isChecked (), pen = pg .mkPen (self .plot_color ))
304315
305316 if fit_func == "Stretched Exponential" : #stretch exponential tab
306- tc , beta , a , avg_tau , PL_fit = stretch_exp_fit (TRPL_interp , t )
317+ tc , beta , a , avg_tau , PL_fit , noise = stretch_exp_fit (TRPL_interp , t )
307318 self .out = np .empty ((len (t ), 3 ))
308319 self .out [:,0 ] = t #time
309320 self .out [:,1 ] = TRPL_interp #Raw PL
@@ -313,11 +324,12 @@ def fit_and_plot(self):
313324 "\n Fit Method: " + "diff_ev" + #TODO : change when diff_ev and fmin_tnc implemented for non-irf
314325 "\n Average Lifetime = " + str (avg_tau )+ " ns"
315326 "\n Characteristic Tau = " + str (tc )+ " ns"
316- "\n Beta = " + str (beta ))
327+ "\n Beta = " + str (beta )+
328+ "\n Noise = " + str (noise ))
317329 self .ui .average_lifetime_spinBox .setValue (avg_tau )
318330
319331 elif fit_func == "Double Exponential" : #double exponential tab
320- tau1 , a1 , tau2 , a2 , avg_tau , PL_fit = double_exp_fit (TRPL_interp , t )
332+ tau1 , a1 , tau2 , a2 , avg_tau , PL_fit , noise = double_exp_fit (TRPL_interp , t )
321333 self .out = np .empty ((len (t ), 3 ))
322334 self .out [:,0 ] = t #time
323335 self .out [:,1 ] = TRPL_interp #Raw PL
@@ -329,11 +341,12 @@ def fit_and_plot(self):
329341 "\n Tau 1 = " + str (tau1 )+ " ns"
330342 "\n A 1 = " + str (a1 )+
331343 "\n Tau 2 = " + str (tau2 )+ " ns"
332- "\n A 2 = " + str (a2 ))
344+ "\n A 2 = " + str (a2 )+
345+ "\n Noise = " + str (noise ))
333346 #TODO - once tau_avg implemented, set average lifetime spinbox to tau_avg value
334347
335348 elif fit_func == "Single Exponential" : #single exponential tab
336- tau , a , PL_fit = single_exp_fit (TRPL_interp , t )
349+ tau , a , PL_fit , noise = single_exp_fit (TRPL_interp , t )
337350 self .out = np .empty ((len (t ), 3 ))
338351 self .out [:,0 ] = t #time
339352 self .out [:,1 ] = TRPL_interp #Raw PL
@@ -342,12 +355,14 @@ def fit_and_plot(self):
342355 self .ui .Result_textBrowser .setText ("Fit Results:\n \n Fit Function: Single Exponential"
343356 "\n Fit Method: " + "diff_ev" +
344357 "\n Lifetime = " + str (tau )+ " ns"
345- "\n A = " + str (a ))
358+ "\n A = " + str (a )+
359+ "\n Noise = " + str (noise ))
346360 self .ui .average_lifetime_spinBox .setValue (tau )
347361
348362 #add fit params to data_list
349363 self .data_list .append ("Data Channel: " + str (self .ui .Data_channel_spinBox .value ()) + "\n " + self .ui .Result_textBrowser .toPlainText ())
350- self .fit_lifetime_called = True
364+ self .fit_lifetime_called_wo_irf = True
365+ self .fit_lifetime_called_w_irf = False
351366
352367 self .ui .plot .setLabel ('left' , 'Intensity' , units = 'a.u.' )
353368 self .ui .plot .setLabel ('bottom' , 'Time (ns)' )
@@ -475,7 +490,8 @@ def fit_and_plot_with_irf(self):
475490
476491 #add fit params to data_list
477492 self .data_list .append ("Data Channel: " + str (self .ui .Data_channel_spinBox .value ()) + "\n " + self .ui .Result_textBrowser .toPlainText ())
478- self .fit_lifetime_called = True
493+ self .fit_lifetime_called_w_irf = True
494+ self .fit_lifetime_called_wo_irf = False
479495 except Exception as e :
480496 self .ui .Result_textBrowser .append (format (e ))
481497
@@ -548,12 +564,19 @@ def clean_up_after_fig_export(self):
548564 self .y_mem = []
549565 self .legend = []
550566 self .best_fit_mem = []
567+ self .best_fit_mem_x = []
551568
552569 def add_trace_to_mem (self ):
553570 try :
554- if self .fit_lifetime_called == True :
571+ if self .fit_lifetime_called_w_irf == True :
555572 self .x_mem .append (self .out [:,0 ])
556573 self .y_mem .append (self .out [:,1 ])
574+ self .best_fit_mem_x .append (self .out [:,0 ])
575+ self .best_fit_mem .append (self .out [:,2 ])
576+ elif self .fit_lifetime_called_wo_irf == True :
577+ self .x_mem .append (self .acquire_settings ()[0 ])
578+ self .y_mem .append (self .acquire_settings ()[1 ])
579+ self .best_fit_mem_x .append (self .out [:,0 ])
557580 self .best_fit_mem .append (self .out [:,2 ])
558581 else :
559582 self .x_mem .append (self .acquire_settings ()[0 ])
@@ -578,8 +601,8 @@ def pub_ready_plot_export(self):
578601 plt .tick_params (direction = 'out' , length = 8 , width = 3.5 )
579602 for i in range (len (self .x_mem )):
580603 plt .plot (self .x_mem [i ], self .y_mem [i ], label = str (self .legend [i ]))
581- if self .fit_lifetime_called == True :
582- plt .plot (self .x_mem [i ], self .best_fit_mem [i ],'k--' )
604+ if self .fit_lifetime_called_w_irf == True or self . fit_lifetime_called_wo_irf == True :
605+ plt .plot (self .best_fit_mem_x [i ], self .best_fit_mem [i ],'k--' )
583606
584607 plt .yscale ('log' )
585608 plt .xlabel ("Time (ns)" , fontsize = 20 , fontweight = 'bold' )
0 commit comments