@@ -208,10 +208,12 @@ def plot(image_index, vrange):
208208 image_index = widgets .IntSlider (min = 0 ,
209209 max = len (self .data ) - 1 ,
210210 value = 0 ,
211+ style = {"description_width" : "150px" },
211212 layout = widgets .Layout (width = "50%" )),
212213 vrange = widgets .FloatRangeSlider (min = 0 ,
213214 max = vmax ,
214215 value = [0 , vmax ],
216+ style = {"description_width" : "150px" },
215217 layout = widgets .Layout (width = "50%" ))
216218 )
217219 display (v )
@@ -229,11 +231,6 @@ def update_config_after_rotation(self):
229231 self .config ["rotation_angle" ]["rotate_90_flag" ] = self .v .children [0 ].value
230232
231233 def rotate_images (self ):
232- # fig = plt.figure(num="Rotation of images")
233- # ax0 = plt.subplot(221)
234- # ax1 = plt.subplot(223)
235- # ax2 = plt.subplot(122)
236-
237234 default_rotate_angle = self .config ["rotation_angle" ]["angle" ]
238235 default_rot_90_flag = self .config ["rotation_angle" ]["rotate_90_flag" ]
239236
@@ -254,10 +251,11 @@ def plot(rot_90_flag, rot_value, image_index, vert_guide, profile1_h, profile2_h
254251
255252 vmin , vmax = vrange
256253
257- fig = plt .figure (num = "Rotation of images" )
258- ax0 = plt .subplot (221 )
259- ax1 = plt .subplot (223 )
260- ax2 = plt .subplot (122 )
254+ fig = plt .figure (num = "Rotation of images" , figsize = (15 , 10 ))
255+ ax0 = plt .subplot (231 ) # preview
256+ ax1 = plt .subplot (234 ) # horizontal profiles
257+ ax3 = plt .subplot (132 ) # vertical profile
258+ ax2 = plt .subplot (133 ) # region between the two profiles
261259
262260 # ax0.cla()
263261 data = self .data [image_index ]
@@ -304,12 +302,6 @@ def plot(rot_90_flag, rot_value, image_index, vert_guide, profile1_h, profile2_h
304302 # ax1.cla()
305303 ax1 .plot (profile1 , "b" , label = "profile 1" )
306304 ax1 .plot (profile2 , "g" , label = "profile 2" )
307- plt .tight_layout ()
308-
309- # print(f"{point1 =}")
310- # print(f"{point2 =}")
311- # print(f"{point3 =}")
312- # print(f"{point4 =}")
313305
314306 # ax2.cla()
315307 top = point1 [1 ]
@@ -320,7 +312,18 @@ def plot(rot_90_flag, rot_value, image_index, vert_guide, profile1_h, profile2_h
320312 tilted_data = data [top :bottom , left :right ]
321313 ax2 .imshow (tilted_data , vmin = vmin , vmax = vmax )
322314 ax2 .axvline (profile_margin , linestyle = "--" , color = "r" )
323- ax2 .set_title ("Preview of region between the two profiles" )
315+ ax2 .set_title ("Zoom between \n hori. guides" )
316+
317+ vertical_profile = data [top_profileh : bottom_profileh , vert_guide ]
318+ vertical_profile = vertical_profile [::- 1 ]
319+ pixels = np .arange (len (vertical_profile ))
320+ ax3 .plot (vertical_profile , pixels , "r" , label = "vertical profile" )
321+ ax3 .set_xlabel ("Counts" )
322+ ax3 .set_ylabel ("Pixels" )
323+ ax3 .invert_yaxis ()
324+ ax3 .set_title ("Vertical profile" )
325+
326+ plt .tight_layout ()
324327
325328 self .v = interactive (
326329 plot ,
@@ -393,6 +396,7 @@ def plot(fig_size, image_index, left_right, top_bottom, profile_marker, vrange):
393396 ax0 = plt .subplot (221 )
394397 ax1 = plt .subplot (223 )
395398 ax2 = plt .subplot (122 )
399+ # ax3 = plt.subplot(133) # vertical profile in the cropped region
396400
397401 vmin , vmax = vrange
398402
@@ -422,6 +426,17 @@ def plot(fig_size, image_index, left_right, top_bottom, profile_marker, vrange):
422426 ax2 .imshow (cropped_data , vmin = vmin , vmax = vmax )
423427 ax2 .set_title ("Cropped Data Preview" )
424428
429+ # vertical_profile = np.sum(self.data[image_index][top : bottom + 1, left : right + 1], axis=1)
430+ # vertical_profile = vertical_profile[::-1]
431+ # pixels = np.arange(len(vertical_profile))
432+ # ax3.plot(vertical_profile, pixels, "r")
433+ # #ax3.plot(pixels, vertical_profile, "r")
434+ # # ax3.set_yscale("log")
435+ # ax3.set_title("Vertical profile in the cropped region")
436+ # ax3.set_xlabel("Counts")
437+ # ax3.set_ylabel("Pixels")
438+
439+
425440 return left , right , top , bottom
426441
427442 description_width = "150px"
@@ -465,7 +480,39 @@ def plot(fig_size, image_index, left_right, top_bottom, profile_marker, vrange):
465480 )
466481 display (self .crop_ui )
467482
468- def crop_region (self ):
483+ def checking_edges (self ):
484+ [x0 , x1 , y0 , y1 ] = self .crop_ui .result
485+ def plot_checking (image_index ):
486+ fig , axs = plt .subplots (nrows = 2 , ncols = 1 , figsize = (15 , 10 ),
487+ gridspec_kw = {'hspace' : 0 },
488+ sharex = False )
489+
490+ data = self .data [image_index ]
491+ data = data [y0 : y1 + 1 , x0 : x1 + 1 ]
492+ # rotate 90 degrees
493+ data_rotated = np .rot90 (data , k = 3 )
494+
495+ axs [0 ].imshow (data_rotated , cmap = "viridis" )
496+ axs [0 ].tick_params (labelbottom = False )
497+ axs [0 ].tick_params (labeltop = True )
498+
499+ profile = np .sum (data , axis = 1 )
500+ profile = profile [::- 1 ]
501+ pixels = np .arange (len (profile ))
502+ axs [1 ].plot (pixels , profile , "r" )
503+ # limit x axis to the cropped region
504+ axs [1 ].set_xlim ([0 , x1 - x0 ])
505+ axs [1 ].set_title ("Vertical profile in the cropped region" )
506+ axs [1 ].set_ylabel ("" )
507+ axs [1 ].set_xlabel ("Pixels" )
508+
509+ v = interactive (
510+ plot_checking ,
511+ image_index = widgets .IntSlider (min = 0 , max = self .number_of_images - 1 , value = 0 , layout = widgets .Layout (width = "50%" )),
512+ )
513+ display (v )
514+
515+ def crop_images (self ):
469516 [x0 , x1 , y0 , y1 ] = self .crop_ui .result
470517 self .crop = {"x0" : 0 , "x1" : x1 , "y0" : y0 , "y1" : y1 }
471518 self .config ["default_crop" ]["x0" ] = x0
@@ -478,7 +525,7 @@ def crop_region(self):
478525
479526 def export_cropped_images (self ):
480527 if self .cropped_data is None :
481- self .crop_region ()
528+ self .crop_images ()
482529
483530 display (
484531 HTML (
0 commit comments