Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IndexedStackColorMapper for ImageStack glyph #13316

Closed

Conversation

ianthomas23
Copy link
Member

This is an early-stage WIP to add an IndexedStackColorMapper which is an alternative use of ImageStack glyph that color maps and displays a single 2D array of the 3D ImageStack data.

The data displayed is controlled by an index property, which will cause data[:, :, index] to be displayed. The actual colormapping is controlled by a contained single_color_mapper so that it can be linear, logarithmic or eq_hist. There is a boolean property map_all (maybe should be scan_all but I don't like either much) that controls whether the colormap limits/properties are calculated from the all of the 3D data or just the 2D data displayed.

Example script:

from bokeh.models import IndexedStackColorMapper, LinearColorMapper, Slider, Toggle
from bokeh.plotting import column, figure, row, show
import numpy as np

ny, nx, nstack = 5, 5, 4
rng = np.random.default_rng(22529)
data = rng.random((ny, ny, nstack))
for k in range(nstack):
    data[:, :, k] += k*0.2

p = figure(width=500, height=400,
           title=f"ImageStack of shape {data.shape} with IndexedStackColorMapper")

# Do not want palette on both LinearColorMapper and IndexedStackColorMapper as only one used ???
single = LinearColorMapper(palette='Spectral10')
color_mapper = IndexedStackColorMapper(single_color_mapper=single, palette='Spectral10')
im = p.image_stack(image=[data], x=0, y=0, dw=1, dh=1, color_mapper=color_mapper)

cbar = im.construct_color_bar()
p.add_layout(cbar, "right")

slider = Slider(start=0, end=nstack-1, value=0, step=1, title="Index")
slider.js_link("value", color_mapper, "index")

toggle = Toggle(label="map_all")
toggle.js_link("active", color_mapper, "map_all")

show(column(p, row(slider, toggle)))

and video of this:
https://github.com/bokeh/bokeh/assets/580326/ccfcc2cf-7c58-425e-9023-2019bf4bec9c

One problem with this approach is that both the LinearColorMapper and IndexedStackColorMapper must have a palette specified (None is not allowed for ColorMappers) but only one is used.

Also, I have had to reimplement part of ContinuousColorMapper._v_compute within IndexedStackColorMapper when it scans all of the data but only displays one 2D slice of it. Probably a better approach would be a refactor of the various _v_compute functions to accept the scanned data rather than scan it themselves.

@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Merging #13316 (1465975) into branch-3.3 (4544dbd) will increase coverage by 0.00%.
Report is 2 commits behind head on branch-3.3.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           branch-3.3   #13316   +/-   ##
===========================================
  Coverage       92.45%   92.45%           
===========================================
  Files             315      315           
  Lines           20150    20156    +6     
===========================================
+ Hits            18629    18635    +6     
  Misses           1521     1521           

@mattpap mattpap changed the base branch from branch-3.3 to branch-3.4 October 10, 2023 12:45
@mattpap mattpap changed the base branch from branch-3.4 to branch-3.5 March 14, 2024 16:52
@bryevdv
Copy link
Member

bryevdv commented May 15, 2024

@ianthomas23 just an FYI in case you were thinking of 3.5 for this work, it looks like that release will be late May/early June (I think this could be nice to show off at Scipy particularly, but understand if there is not time permitting)

@ianthomas23
Copy link
Member Author

@bryevdv I don't think it is likely that I'll ever finish this, so if someone else wants to take it over they are welcome to do so.

@bryevdv
Copy link
Member

bryevdv commented May 15, 2024

I'll keep the branch but close the PR, and open an issue for the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants