@@ -29,6 +29,8 @@ def update_real_space_view(self, reset=False):
2929 "Integrating" ,
3030 "Maximum" ,
3131 "CoM" ,
32+ "CoM X" ,
33+ "CoM Y" ,
3234 "iCoM" ,
3335 ], detector_mode
3436
@@ -50,7 +52,8 @@ def update_real_space_view(self, reset=False):
5052 if detector_shape == "Rectangular" :
5153 # Get slices corresponding to ROI
5254 slices , transforms = self .virtual_detector_roi .getArraySlice (
53- self .datacube .data [0 , 0 , :, :], self .diffraction_space_widget .getImageItem ()
55+ self .datacube .data [0 , 0 , :, :].T ,
56+ self .diffraction_space_widget .getImageItem (),
5457 )
5558 slice_y , slice_x = slices
5659
@@ -156,6 +159,10 @@ def update_real_space_view(self, reset=False):
156159
157160 if detector_mode == "CoM" :
158161 vimg = CoMx + 1.0j * CoMy
162+ elif detector_mode == "CoM X" :
163+ vimg = CoMx
164+ elif detector_mode == "CoM Y" :
165+ vimg = CoMy
159166 elif detector_mode == "iCoM" :
160167 dpc = py4DSTEM .process .phase .DPC (verbose = False )
161168 dpc .preprocess (
@@ -313,7 +320,7 @@ def update_diffraction_space_view(self, reset=False):
313320 elif detector_shape == "Rectangular" :
314321 # Get slices corresponding to ROI
315322 slices , _ = self .real_space_rect_selector .getArraySlice (
316- np .zeros ((self .datacube .Rshape )), self .real_space_widget .getImageItem ()
323+ np .zeros ((self .datacube .Rshape )). T , self .real_space_widget .getImageItem ()
317324 )
318325 slice_y , slice_x = slices
319326
@@ -401,12 +408,18 @@ def update_realspace_detector(self):
401408 )
402409 assert detector_shape in ["Point" , "Rectangular" ], detector_shape
403410
404- if self .datacube is None :
405- return
411+ main_pen = {"color" : "g" , "width" : 6 }
412+ handle_pen = {"color" : "r" , "width" : 9 }
413+ hover_pen = {"color" : "c" , "width" : 6 }
414+ hover_handle = {"color" : "c" , "width" : 9 }
406415
407- x , y = self .datacube .data .shape [:2 ]
408- x0 , y0 = x // 2 , y // 2
409- xr , yr = x / 10 , y / 10
416+ if self .datacube is None :
417+ x0 , y0 = 0 , 0
418+ xr , yr = 4 , 4
419+ else :
420+ x , y = self .datacube .data .shape [2 :]
421+ y0 , x0 = x // 2 , y // 2
422+ xr , yr = (np .minimum (x , y ) / 10 ,) * 2
410423
411424 # Remove existing detector
412425 if hasattr (self , "real_space_point_selector" ):
@@ -416,19 +429,27 @@ def update_realspace_detector(self):
416429 self .real_space_widget .view .scene ().removeItem (self .real_space_rect_selector )
417430 self .real_space_rect_selector = None
418431
419- # Rectangular detector
432+ # Point detector
420433 if detector_shape == "Point" :
421434 self .real_space_point_selector = pg_point_roi (
422435 self .real_space_widget .getView (),
423436 center = (x0 - 0.5 , y0 - 0.5 ),
437+ pen = main_pen ,
438+ hoverPen = hover_pen ,
424439 )
425440 self .real_space_point_selector .sigRegionChanged .connect (
426441 partial (self .update_diffraction_space_view , False )
427442 )
428443
444+ # Rectangular detector
429445 elif detector_shape == "Rectangular" :
430446 self .real_space_rect_selector = pg .RectROI (
431- [int (x0 - xr / 2 ), int (y0 - yr / 2 )], [int (xr ), int (yr )], pen = (3 , 9 )
447+ [int (x0 - xr / 2 ), int (y0 - yr / 2 )],
448+ [int (xr ), int (yr )],
449+ pen = main_pen ,
450+ handlePen = handle_pen ,
451+ hoverPen = hover_pen ,
452+ handleHoverPen = hover_handle ,
432453 )
433454 self .real_space_widget .getView ().addItem (self .real_space_rect_selector )
434455 self .real_space_rect_selector .sigRegionChangeFinished .connect (
@@ -447,12 +468,18 @@ def update_diffraction_detector(self):
447468 detector_shape = self .detector_shape_group .checkedAction ().text ().strip ("&" )
448469 assert detector_shape in ["Point" , "Rectangular" , "Circle" , "Annulus" ]
449470
450- if self .datacube is None :
451- return
471+ main_pen = {"color" : "g" , "width" : 6 }
472+ handle_pen = {"color" : "r" , "width" : 9 }
473+ hover_pen = {"color" : "c" , "width" : 6 }
474+ hover_handle = {"color" : "c" , "width" : 9 }
452475
453- x , y = self .datacube .data .shape [2 :]
454- x0 , y0 = x // 2 , y // 2
455- xr , yr = x / 10 , y / 10
476+ if self .datacube is None :
477+ x0 , y0 = 0 , 0
478+ xr , yr = 4 , 4
479+ else :
480+ x , y = self .datacube .data .shape [2 :]
481+ y0 , x0 = x // 2 , y // 2
482+ xr , yr = (np .minimum (x , y ) / 10 ,) * 2
456483
457484 # Remove existing detector
458485 if hasattr (self , "virtual_detector_point" ):
@@ -479,6 +506,8 @@ def update_diffraction_detector(self):
479506 self .virtual_detector_point = pg_point_roi (
480507 self .diffraction_space_widget .getView (),
481508 center = (x0 - 0.5 , y0 - 0.5 ),
509+ pen = main_pen ,
510+ hoverPen = hover_pen ,
482511 )
483512 self .virtual_detector_point .sigRegionChanged .connect (
484513 partial (self .update_real_space_view , False )
@@ -487,7 +516,12 @@ def update_diffraction_detector(self):
487516 # Rectangular detector
488517 elif detector_shape == "Rectangular" :
489518 self .virtual_detector_roi = pg .RectROI (
490- [int (x0 - xr / 2 ), int (y0 - yr / 2 )], [int (xr ), int (yr )], pen = (3 , 9 )
519+ [int (x0 - xr / 2 ), int (y0 - yr / 2 )],
520+ [int (xr ), int (yr )],
521+ pen = main_pen ,
522+ handlePen = handle_pen ,
523+ hoverPen = hover_pen ,
524+ handleHoverPen = hover_handle ,
491525 )
492526 self .diffraction_space_widget .getView ().addItem (self .virtual_detector_roi )
493527 self .virtual_detector_roi .sigRegionChangeFinished .connect (
@@ -497,7 +531,12 @@ def update_diffraction_detector(self):
497531 # Circular detector
498532 elif detector_shape == "Circle" :
499533 self .virtual_detector_roi = pg .CircleROI (
500- [int (x0 - xr / 2 ), int (y0 - yr / 2 )], [int (xr ), int (yr )], pen = (3 , 9 )
534+ [int (x0 - xr / 2 ), int (y0 - yr / 2 )],
535+ [int (xr ), int (yr )],
536+ pen = main_pen ,
537+ handlePen = handle_pen ,
538+ hoverPen = hover_pen ,
539+ handleHoverPen = hover_handle ,
501540 )
502541 self .diffraction_space_widget .getView ().addItem (self .virtual_detector_roi )
503542 self .virtual_detector_roi .sigRegionChangeFinished .connect (
@@ -508,15 +547,23 @@ def update_diffraction_detector(self):
508547 elif detector_shape == "Annulus" :
509548 # Make outer detector
510549 self .virtual_detector_roi_outer = pg .CircleROI (
511- [int (x0 - xr ), int (y0 - yr )], [int (2 * xr ), int (2 * yr )], pen = (3 , 9 )
550+ [int (x0 - xr ), int (y0 - yr )],
551+ [int (2 * xr ), int (2 * yr )],
552+ pen = main_pen ,
553+ handlePen = handle_pen ,
554+ hoverPen = hover_pen ,
555+ handleHoverPen = hover_handle ,
512556 )
513557 self .diffraction_space_widget .getView ().addItem (self .virtual_detector_roi_outer )
514558
515559 # Make inner detector
516560 self .virtual_detector_roi_inner = pg .CircleROI (
517561 [int (x0 - xr / 2 ), int (y0 - yr / 2 )],
518562 [int (xr ), int (yr )],
519- pen = (4 , 9 ),
563+ pen = main_pen ,
564+ hoverPen = hover_pen ,
565+ handlePen = handle_pen ,
566+ handleHoverPen = hover_handle ,
520567 movable = False ,
521568 )
522569 self .diffraction_space_widget .getView ().addItem (self .virtual_detector_roi_inner )
@@ -623,8 +670,8 @@ def update_tooltip(self):
623670 if scene .getView ().rect ().contains (pos_in_scene ):
624671 pos_in_data = scene .view .mapSceneToView (pos_in_scene )
625672
626- y = int (np .clip (np .floor (pos_in_data .x ()), 0 , data .shape [0 ] - 1 ))
627- x = int (np .clip (np .floor (pos_in_data .y ()), 0 , data .shape [1 ] - 1 ))
673+ y = int (np .clip (np .floor (pos_in_data .x ()), 0 , data .shape [1 ] - 1 ))
674+ x = int (np .clip (np .floor (pos_in_data .y ()), 0 , data .shape [0 ] - 1 ))
628675
629676 if np .isrealobj (data ):
630677 display_text = f"[{ x } ,{ y } ]: { data [x ,y ]:.5g} "
0 commit comments