@@ -464,11 +464,13 @@ def slicer_plot(self, **kwargs) -> None:
464464 See https://scipp.github.io/plopp/generated/plopp.slicer.html for options.
465465 """
466466 slicer_kwargs_defaults = self ._plot_defaults ()
467- slicer_kwargs_defaults .update ({
468- 'title' : self .display_name + ' - Time of Flight Slicer' ,
469- 'keep' : ['x_pixels' , 'y_pixels' ] if not self ._has_physical_coords else ['x' , 'y' ],
470- 'mode' : 'single'
471- })
467+ slicer_kwargs_defaults .update (
468+ {
469+ 'title' : self .display_name + ' - Time of Flight Slicer' ,
470+ 'keep' : ['x_pixels' , 'y_pixels' ] if not self ._has_physical_coords else ['x' , 'y' ],
471+ 'mode' : 'single' ,
472+ }
473+ )
472474 slicer_kwargs_defaults ['coords' ].append ('tof' )
473475
474476 # Overwrite defaults with any user-provided kwargs
@@ -494,14 +496,16 @@ def spectrum_inspector(self, **kwargs) -> None:
494496 """
495497 inspector_kwargs_defaults = self ._plot_defaults ()
496498 inspector_kwargs_defaults ['ymax' ] = inspector_kwargs_defaults ['cmax' ]
497- inspector_kwargs_defaults .update ({
498- 'title' : self .display_name + ' - Spectrum Inspector' ,
499- 'ymin' : 0.0 ,
500- 'dim' : 't' ,
501- 'orientation' : 'vertical' ,
502- 'operation' : 'mean' ,
503- 'mode' : 'point' ,
504- })
499+ inspector_kwargs_defaults .update (
500+ {
501+ 'title' : self .display_name + ' - Spectrum Inspector' ,
502+ 'ymin' : 0.0 ,
503+ 'dim' : 't' ,
504+ 'orientation' : 'vertical' ,
505+ 'operation' : 'mean' ,
506+ 'mode' : 'point' ,
507+ }
508+ )
505509 # Overwrite defaults with any user-provided kwargs
506510 inspector_kwargs_defaults .update (kwargs )
507511
@@ -535,21 +539,20 @@ def roi_creator(self, **kwargs) -> None:
535539
536540 roi_selector_kwargs_defaults = self ._plot_defaults ()
537541 roi_selector_kwargs_defaults ['ymax' ] = roi_selector_kwargs_defaults ['cmax' ]
538- roi_selector_kwargs_defaults .update ({
539- 'title' : self .display_name + ' - ROI Creator' ,
540- 'ymin' : 0.0 ,
541- 'dim' : 't' ,
542- 'orientation' : 'vertical' ,
543- 'operation' : 'mean' ,
544- 'mode' : 'rectangle' ,
545- })
542+ roi_selector_kwargs_defaults .update (
543+ {
544+ 'title' : self .display_name + ' - ROI Creator' ,
545+ 'ymin' : 0.0 ,
546+ 'dim' : 't' ,
547+ 'orientation' : 'vertical' ,
548+ 'operation' : 'mean' ,
549+ 'mode' : 'rectangle' ,
550+ }
551+ )
546552 # Overwrite defaults with any user-provided kwargs
547553 roi_selector_kwargs_defaults .update (kwargs )
548-
549- plots = pp .inspector (
550- self ._data_array ,
551- ** roi_selector_kwargs_defaults
552- )
554+
555+ plots = pp .inspector (self ._data_array , ** roi_selector_kwargs_defaults )
553556
554557 # -------------------------------------------------------------------------------------------------
555558 # -------------------------- Plot the existing ROIs on the plot -----------------------------------
@@ -574,11 +577,13 @@ def roi_creator(self, **kwargs) -> None:
574577 x_end = roi .x_pixel_end
575578 y_end = roi .y_pixel_end
576579 plots [0 ].toolbar ['inspect' ]._tool .start ()
577- plots [0 ].toolbar ['inspect' ]._tool .click (x = x_start , y = y_start , button = 1 ) # button 1 is left-click
580+ plots [0 ].toolbar ['inspect' ]._tool .click (x = x_start , y = y_start , button = 1 ) # button 1 is left-click
578581 plots [0 ].toolbar ['inspect' ]._tool .click (x = x_end , y = y_end , button = 1 )
579582 plots [0 ].toolbar ['inspect' ]._tool .stop ()
580583 if hasattr (roi , '_rect_ids' ):
581- roi ._rect_ids .append (plots [0 ].toolbar ['inspect' ]._tool .children [- 1 ].id ) # Store the rectangle ID for reference when dragging corners # noqa: E501
584+ roi ._rect_ids .append (
585+ plots [0 ].toolbar ['inspect' ]._tool .children [- 1 ].id
586+ ) # Store the rectangle ID for reference when dragging corners # noqa: E501
582587 else :
583588 roi ._rect_ids = [plots [0 ].toolbar ['inspect' ]._tool .children [- 1 ].id ]
584589
@@ -622,27 +627,20 @@ def delete_rectangle_roi(rect, roi_list):
622627 # -------------------------- Connect the callbacks to the RectangleTool ---------------------------
623628 # -------------------------------------------------------------------------------------------------
624629
625- plots [0 ].toolbar ['inspect' ]._tool .on_create (partial (
626- create_rectangle_roi ,
627- roi_list = self .regions_of_interest ,
628- data_array = self ._data_array
629- ))
630-
631- plots [0 ].toolbar ['inspect' ]._tool .on_change (partial (
632- edit_rectangle_roi ,
633- roi_list = self .regions_of_interest ,
634- data_array = self ._data_array
635- ))
636-
637- plots [0 ].toolbar ['inspect' ]._tool .on_remove (partial (
638- delete_rectangle_roi ,
639- roi_list = self .regions_of_interest
640- ))
630+ plots [0 ].toolbar ['inspect' ]._tool .on_create (
631+ partial (create_rectangle_roi , roi_list = self .regions_of_interest , data_array = self ._data_array )
632+ )
633+
634+ plots [0 ].toolbar ['inspect' ]._tool .on_change (
635+ partial (edit_rectangle_roi , roi_list = self .regions_of_interest , data_array = self ._data_array )
636+ )
637+
638+ plots [0 ].toolbar ['inspect' ]._tool .on_remove (partial (delete_rectangle_roi , roi_list = self .regions_of_interest ))
641639
642640 plots [0 ].toolbar ['inspect' ].tooltip = 'Activate ROI creator tool'
643641
644642 return plots
645-
643+
646644 def spectrum (self , roi : RectROI | str | None = None ) -> sc .DataArray :
647645 """
648646 Extract the spectrum (intensity vs. time-of-flight) for a specified region of interest (ROI).
@@ -752,11 +750,13 @@ def _validate_provided_coord(
752750 return coord
753751
754752 @staticmethod
755- def _ranges_from_rectangle (rect , data_array : sc .DataArray ) -> tuple [tuple [int , int ], None ] | tuple [tuple [int , int ], tuple [sc .Variable , sc .Variable ]]: # noqa: E501
756- # To be used in the roi_selector method to convert the rectangle vertices to pixel and
753+ def _ranges_from_rectangle (
754+ rect , data_array : sc .DataArray
755+ ) -> tuple [tuple [int , int ], None ] | tuple [tuple [int , int ], tuple [sc .Variable , sc .Variable ]]: # noqa: E501
756+ # To be used in the roi_selector method to convert the rectangle vertices to pixel and
757757 # physical coordinate ranges for the new ROI.
758758 x_vertex_list , y_vertex_list = rect .vertices
759- if 'x' not in data_array .coords : # If 'x' exists, so does 'y' due to our constructor.
759+ if 'x' not in data_array .coords : # If 'x' exists, so does 'y' due to our constructor.
760760 x_pixel_range = (int (min (x_vertex_list )), int (max (x_vertex_list )))
761761 y_pixel_range = (int (min (y_vertex_list )), int (max (y_vertex_list )))
762762 x_range = None
@@ -768,7 +768,7 @@ def _ranges_from_rectangle(rect, data_array: sc.DataArray) -> tuple[tuple[int, i
768768 x_range = (sc .scalar (min (x_vertex_list ), unit = x_unit ), sc .scalar (max (x_vertex_list ), unit = x_unit ))
769769 y_range = (sc .scalar (min (y_vertex_list ), unit = y_unit ), sc .scalar (max (y_vertex_list ), unit = y_unit ))
770770
771- sliced_data_array = data_array ['x' , x_range [0 ]: x_range [1 ]]['y' , y_range [0 ]: y_range [1 ]]
771+ sliced_data_array = data_array ['x' , x_range [0 ] : x_range [1 ]]['y' , y_range [0 ] : y_range [1 ]]
772772
773773 sliced_x_pixels = sliced_data_array .coords ['x_pixels' ].values
774774 sliced_y_pixels = sliced_data_array .coords ['y_pixels' ].values
@@ -784,8 +784,8 @@ def _plot_defaults(self):
784784 'cmin' : 0.0 ,
785785 'cmax' : min (3.0 , float (self ._data_array .max ().value * 1.1 )),
786786 'mask_color' : 'red' ,
787- 'coords' : ['x_pixels' , 'y_pixels' ] if not self ._has_physical_coords else ['x' , 'y' ],
787+ 'coords' : ['x_pixels' , 'y_pixels' ] if not self ._has_physical_coords else ['x' , 'y' ],
788788 }
789789
790790 def __repr__ (self ):
791- return f" { self .display_name } with shape { self ._data_array .shape } and regions of interest: { [roi .display_name for roi in self .regions_of_interest ]} " # noqa: E501
791+ return f' { self .display_name } with shape { self ._data_array .shape } and regions of interest: { [roi .display_name for roi in self .regions_of_interest ]} ' # noqa: E501
0 commit comments