1212import customplotting .mscope as cpm
1313# local modules
1414
15-
16-
1715pg .mkQApp ()
1816pg .setConfigOption ('background' , 'w' )
1917pg .setConfigOption ('imageAxisOrder' , 'row-major' )
@@ -34,27 +32,29 @@ def __init__(self):
3432 self .ui = WindowTemplate ()
3533 self .ui .setupUi (self )
3634
35+ #set up ui signals
3736 self .ui .load_scan_pushButton .clicked .connect (self .open_pkl_file )
3837 self .ui .plot_intensity_sums_pushButton .clicked .connect (self .plot_intensity_sums )
3938 self .ui .plot_raw_hist_data_pushButton .clicked .connect (self .plot_raw_scan )
4039 self .ui .save_intensities_image_pushButton .clicked .connect (self .save_intensities_image )
4140 self .ui .save_intensities_array_pushButton .clicked .connect (self .save_intensities_array )
4241 self .ui .compare_checkBox .stateChanged .connect (self .switch_compare )
4342 self .ui .intensity_sums_viewBox .roi .sigRegionChanged .connect (self .line_profile_update_plot )
44-
4543 self .ui .import_pkl_pushButton .clicked .connect (self .import_pkl_to_convert )
4644 self .ui .pkl_to_h5_pushButton .clicked .connect (self .pkl_to_h5 )
45+
4746 self .show ()
4847
49- """Open Scan Files"""
5048 def open_pkl_file (self ):
49+ """ Open FLIM scan file """
5150 try :
5251 self .filename = QtWidgets .QFileDialog .getOpenFileName (self )
5352 self .pkl_file = pickle .load (open (self .filename [0 ], 'rb' ))
5453 except Exception as err :
5554 print (format (err ))
5655
5756 def import_pkl_to_convert (self ):
57+ """ Open pkl file to convert to h5 """
5858 try :
5959 self .pkl_to_convert = QtWidgets .QFileDialog .getOpenFileName (self )
6060 self .ui .result_textBrowser .append ("Done Loading - .pkl to convert" )
@@ -70,11 +70,10 @@ def plot_intensity_sums(self):
7070 self .x_scan_size = float (data ['Scan Parameters' ]['X scan size (um)' ])
7171 self .y_step_size = float (data ['Scan Parameters' ]['Y step size (um)' ])
7272 self .y_scan_size = float (data ['Scan Parameters' ]['Y scan size (um)' ])
73- # TODO test line scan plots
7473
7574 hist_data = data ["Histogram data" ]
7675 hist_data = np .reshape (hist_data , newshape = (hist_data .shape [0 ], self .numb_pixels_X * self .numb_pixels_Y ))
77- self .intensity_sums = np .sum (hist_data , axis = 0 )
76+ self .intensity_sums = np .sum (hist_data , axis = 0 ) #sum intensities for each pixel
7877 self .intensity_sums = np .reshape (self .intensity_sums , newshape = (self .numb_pixels_X , self .numb_pixels_Y ))
7978 self .ui .intensity_sums_viewBox .view .invertY (False ) # stop y axis invert
8079 self .ui .intensity_sums_viewBox .setImage (self .intensity_sums , scale =
@@ -88,6 +87,7 @@ def plot_intensity_sums(self):
8887 print (format (err ))
8988
9089 def line_profile_update_plot (self ):
90+ """ Handle line profile for intensity sum viewbox """
9191 if hasattr (self , "intensity_sums" ):
9292 roiPlot = self .ui .intensity_sums_viewBox .getRoiPlot ()
9393 roiPlot .clear ()
@@ -144,10 +144,10 @@ def plot_raw_scan(self):
144144
145145 def switch_compare (self ):
146146 """
147- Handles compare checkbox. If checked, show second ROI that user can use for comparison to first ROI.
147+ Handles compare checkbox. If checked, show second ROI on raw histogram data that user can use for comparison to first ROI.
148148 """
149149 if self .ui .compare_checkBox .isChecked () and hasattr (self , "hist_image" ):
150- if not hasattr (self , "roi2" ):
150+ if not hasattr (self , "roi2" ): #create roi if doesn't exist yet
151151 self .roi2 = pg .ROI (pos = [0 ,0 ], size = [int (self .x_scan_size / 2 ), int (self .y_scan_size / 2 )], movable = True , pen = 'r' )
152152 self .roi2 .addScaleHandle ([1 , 1 ], [0 , 0 ])
153153 self .roi2 .addRotateHandle ([0 , 0 ], [1 , 1 ])
@@ -162,12 +162,13 @@ def switch_compare(self):
162162 else :
163163 self .roi2 .hide ()
164164 self .roi2_plot .hide ()
165- else :
165+ else : #if not checked, hide roi
166166 if hasattr (self , "roi2" ):
167167 self .roi2 .hide ()
168168 self .roi2_plot .hide ()
169169
170170 def update_roi2_plot (self ):
171+ """ Update plot corresponding to second roi """
171172 #Adapted from pyqtgraph imageview sourcecode
172173
173174 image = self .ui .raw_hist_data_viewBox .getProcessedImage ()
@@ -177,6 +178,7 @@ def update_roi2_plot(self):
177178 data , coords = self .roi2 .getArrayRegion (image .view (np .ndarray ), self .ui .raw_hist_data_viewBox .imageItem , axes , returnMappedCoords = True )
178179 if data is None :
179180 return
181+
180182 # Average data within entire ROI for each frame
181183 data = data .mean (axis = max (axes )).mean (axis = min (axes ))
182184 xvals = self .ui .raw_hist_data_viewBox .tVals
@@ -199,7 +201,7 @@ def save_intensities_array(self):
199201 filename_ext = os .path .basename (self .filename [0 ])
200202 filename = os .path .splitext (filename_ext )[0 ] #get filename without extension
201203 save_to = os .getcwd () + "\\ " + filename + "_intensity_sums.txt"
202- np .savetxt (save_to , self .intensity_sums .T , fmt = '%f' ) #save transpoed intensity sums, as original array handles x in cols and y in rows
204+ np .savetxt (save_to , self .intensity_sums .T , fmt = '%f' ) #save transposed intensity sums, as original array handles x in cols and y in rows
203205 except :
204206 pass
205207
@@ -220,15 +222,15 @@ def pkl_to_h5(self):
220222 def traverse_dict_into_h5 (self , dictionary , h5_output ):
221223 #Create an h5 file using .pkl with scan data and params
222224 for key in dictionary :
223- if type (dictionary [key ]) == dict :
225+ if type (dictionary [key ]) == dict : #if subdictionary, create a group
224226 group = h5_output .create_group (key )
225227 previous_dict = dictionary [key ]
226- self .traverse_dict_into_h5 (dictionary [key ], group )
228+ self .traverse_dict_into_h5 (dictionary [key ], group ) #traverse subdictionary
227229 else :
228230 if key == "Histogram data" or key == "Time data" :
229231 h5_output .create_dataset (key , data = dictionary [key ])
230232 else :
231- h5_output .attrs [key ] = dictionary [key ]
233+ h5_output .attrs [key ] = dictionary [key ] #if not dataset, create attribute
232234
233235 def close_application (self ):
234236 choice = QtGui .QMessageBox .question (self , 'EXIT!' ,
0 commit comments