@@ -170,6 +170,7 @@ def __init__(
170
170
vmin_vmax_sliders : bool = False ,
171
171
grid_shape : Tuple [int , int ] = None ,
172
172
names : List [str ] = None ,
173
+ grid_plot_kwargs : dict = None ,
173
174
** kwargs
174
175
):
175
176
"""
@@ -227,6 +228,9 @@ def __init__(
227
228
grid_shape: Optional[Tuple[int, int]]
228
229
manually provide the shape for a gridplot, otherwise a square gridplot is approximated.
229
230
231
+ grid_plot_kwargs: dict, optional
232
+ passed to `GridPlot`
233
+
230
234
names: Optional[str]
231
235
gives names to the subplots
232
236
@@ -471,12 +475,12 @@ def __init__(
471
475
472
476
if vmin_vmax_sliders :
473
477
data_range = np .ptp (minmax )
474
- data_range_30p = np .ptp (minmax ) * 0.3
478
+ data_range_40p = np .ptp (minmax ) * 0.3
475
479
476
480
minmax_slider = FloatRangeSlider (
477
481
value = minmax ,
478
- min = minmax [0 ] - data_range_30p ,
479
- max = minmax [1 ] + data_range_30p ,
482
+ min = minmax [0 ] - data_range_40p ,
483
+ max = minmax [1 ] + data_range_40p ,
480
484
step = data_range / 150 ,
481
485
description = f"min-max" ,
482
486
readout = True ,
@@ -494,11 +498,15 @@ def __init__(
494
498
kwargs ["vmin" ], kwargs ["vmax" ] = minmax
495
499
496
500
frame = self ._process_indices (self .data [0 ], slice_indices = self ._current_index )
501
+ frame = self ._process_frame_apply (frame , 0 )
497
502
498
503
self .image_graphics : List [ImageGraphic ] = [self .plot .add_image (data = frame , name = "image" , ** kwargs )]
499
504
500
505
elif self ._plot_type == "grid" :
501
- self ._plot : GridPlot = GridPlot (shape = grid_shape , controllers = "sync" )
506
+ if grid_plot_kwargs is None :
507
+ grid_plot_kwargs = {"controllers" : "sync" }
508
+
509
+ self ._plot : GridPlot = GridPlot (shape = grid_shape , ** grid_plot_kwargs )
502
510
503
511
self .image_graphics = list ()
504
512
for data_ix , (d , subplot ) in enumerate (zip (self .data , self .plot )):
@@ -513,12 +521,12 @@ def __init__(
513
521
514
522
if vmin_vmax_sliders :
515
523
data_range = np .ptp (minmax )
516
- data_range_30p = np .ptp (minmax ) * 0.4
524
+ data_range_40p = np .ptp (minmax ) * 0.4
517
525
518
526
minmax_slider = FloatRangeSlider (
519
527
value = minmax ,
520
- min = minmax [0 ] - data_range_30p ,
521
- max = minmax [1 ] + data_range_30p ,
528
+ min = minmax [0 ] - data_range_40p ,
529
+ max = minmax [1 ] + data_range_40p ,
522
530
step = data_range / 150 ,
523
531
description = f"mm: { name_slider } " ,
524
532
readout = True ,
@@ -539,6 +547,7 @@ def __init__(
539
547
_kwargs = kwargs
540
548
541
549
frame = self ._process_indices (d , slice_indices = self ._current_index )
550
+ frame = self ._process_frame_apply (frame , data_ix )
542
551
ig = ImageGraphic (frame , name = "image" , ** _kwargs )
543
552
subplot .add_graphic (ig )
544
553
subplot .name = name
@@ -767,11 +776,17 @@ def _get_window_indices(self, data_ix, dim, indices_dim):
767
776
return indices_dim
768
777
769
778
def _process_frame_apply (self , array , data_ix ) -> np .ndarray :
779
+ if callable (self .frame_apply ):
780
+ return self .frame_apply (array )
781
+
770
782
if data_ix not in self .frame_apply .keys ():
771
783
return array
772
- if self .frame_apply [data_ix ] is not None :
784
+
785
+ elif self .frame_apply [data_ix ] is not None :
773
786
return self .frame_apply [data_ix ](array )
774
787
788
+ return array
789
+
775
790
def _slider_value_changed (
776
791
self ,
777
792
dimension : str ,
@@ -801,6 +816,32 @@ def _set_slider_layout(self, *args):
801
816
for mm in self .vmin_vmax_sliders :
802
817
mm .layout = Layout (width = f"{ w } px" )
803
818
819
+ def _get_vmin_vmax_range (self , data : np .ndarray ) -> Tuple [int , int ]:
820
+ minmax = quick_min_max (data )
821
+
822
+ data_range = np .ptp (minmax )
823
+ data_range_40p = np .ptp (minmax ) * 0.4
824
+
825
+ _range = (
826
+ minmax ,
827
+ data_range ,
828
+ minmax [0 ] - data_range_40p ,
829
+ minmax [1 ] + data_range_40p
830
+ )
831
+
832
+ return _range
833
+
834
+ def reset_vmin_vmax (self ):
835
+ """
836
+ Reset the vmin and vmax w.r.t. the currently displayed image(s)
837
+ """
838
+ for i , ig in enumerate (self .image_graphics ):
839
+ mm = self ._get_vmin_vmax_range (ig .data ())
840
+ self .vmin_vmax_sliders [i ].min = mm [2 ]
841
+ self .vmin_vmax_sliders [i ].max = mm [3 ]
842
+ self .vmin_vmax_sliders [i ].step = mm [1 ] / 150
843
+ self .vmin_vmax_sliders [i ].value = mm [0 ]
844
+
804
845
def show (self ):
805
846
"""
806
847
Show the widget
0 commit comments