added binning for 2D images

This commit is contained in:
2021-06-09 15:53:49 +02:00
parent 35ccbe8764
commit 3a311c070f
3 changed files with 41 additions and 9 deletions

View File

@ -20,10 +20,10 @@ class Actor:
cfg.sp_cache_size.on_change("value", cb(self.do_update_cache_size)) cfg.sp_cache_size.on_change("value", cb(self.do_update_cache_size))
if isinstance(cfg, ConfigDialog1D): #TODO if isinstance(cfg, ConfigDialog1D): #TODO
cfg.curves_latest.active = plt.line_latest.visible cfg.curves_latest.active = plt.line_latest.visible
cfg.curves_average.active = plt.line_average.visible cfg.curves_average.active = plt.line_average.visible
cfg.error_bands.active = plt.errband_latest.visible cfg.error_bands.active = plt.errband_latest.visible
cfg.error_bars.active = plt.errbars_latest.visible cfg.error_bars.active = plt.errbars_latest.visible
cfg.curves_latest.on_click(plt.show_curve_latest) cfg.curves_latest.on_click(plt.show_curve_latest)
cfg.curves_average.on_click(plt.show_curve_average) cfg.curves_average.on_click(plt.show_curve_average)
@ -31,11 +31,13 @@ class Actor:
cfg.error_bars.on_click(plt.show_error_bars) cfg.error_bars.on_click(plt.show_error_bars)
if isinstance(cfg, ConfigDialog2D): #TODO if isinstance(cfg, ConfigDialog2D): #TODO
cfg.sel_cmap.value = plt.palette cfg.sel_cmap.value = plt.palette
cfg.sp_binning.value = plt.binning
cfg.sel_cmap.on_change("value", cb(plt.change_cmap)) cfg.sel_cmap.on_change("value", cb(plt.change_cmap))
cfg.sp_vmin.on_change("value", cb(plt.change_vmin)) cfg.sp_vmin.on_change("value", cb(plt.change_vmin))
cfg.sp_vmax.on_change("value", cb(plt.change_vmax)) cfg.sp_vmax.on_change("value", cb(plt.change_vmax))
cfg.sp_binning.on_change("value", cb(plt.change_binning))
def delete(self): def delete(self):

View File

@ -18,16 +18,17 @@ class ConfigDialog2D(Column):
self.sel_cmap = sel_cmap = Select(title="Colormap", options=CMAPS) self.sel_cmap = sel_cmap = Select(title="Colormap", options=CMAPS)
self.sp_vmin = sp_vmin = Spinner(title="Minimum Value") self.sp_vmin = sp_vmin = Spinner(title="Minimum Value")
self.sp_vmax = sp_vmax = Spinner(title="Maximum Value") self.sp_vmax = sp_vmax = Spinner(title="Maximum Value")
self.sp_binning = sp_binning = Spinner(title="Binning", low=1)
super().__init__( super().__init__(
sp_cache_size, sp_cache_size,
sel_cmap, sel_cmap,
Row(sp_vmin, sp_vmax) Row(sp_vmin, sp_vmax),
sp_binning
) )
#TODO: #TODO:
#- binning
#- log z #- log z

View File

@ -16,6 +16,8 @@ class Plot2D(Object):
self.source = source = ColumnDataSource(data=data) self.source = source = ColumnDataSource(data=data)
self.binning = 1
self.cmap = cmap = LinearColorMapper() self.cmap = cmap = LinearColorMapper()
self.change_cmap("Viridis") self.change_cmap("Viridis")
cbar = ColorBar(color_mapper=cmap) cbar = ColorBar(color_mapper=cmap)
@ -32,6 +34,7 @@ class Plot2D(Object):
def set(self, _times, values): def set(self, _times, values):
image = values[-1] image = values[-1]
image = rebin(image, self.binning)
self.source.data.update(image=[image]) self.source.data.update(image=[image])
@ -45,5 +48,31 @@ class Plot2D(Object):
def change_vmax(self, value): def change_vmax(self, value):
self.cmap.high = 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