added binning for 2D images
This commit is contained in:
@ -32,10 +32,12 @@ class Actor:
|
||||
|
||||
if isinstance(cfg, ConfigDialog2D): #TODO
|
||||
cfg.sel_cmap.value = plt.palette
|
||||
cfg.sp_binning.value = plt.binning
|
||||
|
||||
cfg.sel_cmap.on_change("value", cb(plt.change_cmap))
|
||||
cfg.sp_vmin.on_change("value", cb(plt.change_vmin))
|
||||
cfg.sp_vmax.on_change("value", cb(plt.change_vmax))
|
||||
cfg.sp_binning.on_change("value", cb(plt.change_binning))
|
||||
|
||||
|
||||
def delete(self):
|
||||
|
@ -18,16 +18,17 @@ class ConfigDialog2D(Column):
|
||||
self.sel_cmap = sel_cmap = Select(title="Colormap", options=CMAPS)
|
||||
self.sp_vmin = sp_vmin = Spinner(title="Minimum Value")
|
||||
self.sp_vmax = sp_vmax = Spinner(title="Maximum Value")
|
||||
self.sp_binning = sp_binning = Spinner(title="Binning", low=1)
|
||||
super().__init__(
|
||||
sp_cache_size,
|
||||
sel_cmap,
|
||||
Row(sp_vmin, sp_vmax)
|
||||
Row(sp_vmin, sp_vmax),
|
||||
sp_binning
|
||||
)
|
||||
|
||||
|
||||
|
||||
#TODO:
|
||||
#- binning
|
||||
#- log z
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@ class Plot2D(Object):
|
||||
|
||||
self.source = source = ColumnDataSource(data=data)
|
||||
|
||||
self.binning = 1
|
||||
|
||||
self.cmap = cmap = LinearColorMapper()
|
||||
self.change_cmap("Viridis")
|
||||
cbar = ColorBar(color_mapper=cmap)
|
||||
@ -32,6 +34,7 @@ class Plot2D(Object):
|
||||
|
||||
def set(self, _times, values):
|
||||
image = values[-1]
|
||||
image = rebin(image, self.binning)
|
||||
self.source.data.update(image=[image])
|
||||
|
||||
|
||||
@ -45,5 +48,31 @@ class Plot2D(Object):
|
||||
def change_vmax(self, value):
|
||||
self.cmap.high = value
|
||||
|
||||
def change_binning(self, value):
|
||||
self.binning = value
|
||||
|
||||
|
||||
|
||||
def rebin(img, binning):
|
||||
if binning == 1:
|
||||
return img
|
||||
|
||||
old_shape = np.array(img.shape)
|
||||
new_ny, new_nx = new_shape = old_shape // binning
|
||||
cut_shape = new_shape * binning
|
||||
|
||||
left_ny, left_nx = offsets = (old_shape - cut_shape) // 2
|
||||
right_ny, right_nx = cut_shape + offsets
|
||||
|
||||
meaning_shape = (
|
||||
new_ny, binning,
|
||||
new_nx, binning
|
||||
)
|
||||
|
||||
img = img[left_ny:right_ny, left_nx:right_nx]
|
||||
img.shape = meaning_shape
|
||||
img = img.mean(axis=(1, 3))
|
||||
return img
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user