Downsampling advice needed (outside of server)

Our Bokeh app works well for small images but I need to add downsampling to support images greater than about 1.5K by 1.5K. Somewhere around this size chrome fails to load the app. This is being implemented outside of the Bokeh server. This is the case because the user starts Python does some data analysis and then launches our Bokeh app to interactively draw masks and execute Python analytics from the GUI (via websockets) and finally uses the results returned from the app invocation for further analysis (and perhaps doing more interactive mask drawing by starting the app). If this sort of interaction is supported by the Bokeh server, that would be useful to know… when I looked it didn’t seem like it was straight forward.

My plan was to downsample the whole image and display this downsampled image with X/Y indicating the original dimensions. As the user zooms, I planned to retrieve the indicated zoom region from disk and when the retrieved image is beneath the downsampling threshold just display the raw data.

To support downsampling, I derived a DownsampleBoxZoomTool from BoxZoomTool. This worked well and it was easy to have this generate an event which allows the downsampling implementation to be lifted from the tools into the app implementation. However, I ran into difficulties when I tried to use the standard Bokeh tick mark labeling implementation. The problem was attempting to change the X/Y ranges causes the image to zoom to the X/Y range based on the dimensions of original image (but after the update all of the data is the zoomed portion).

After this failure, I thought that perhaps there is a way to connect downsampling into the x_range/y_range events, but it seems like this will result in the same issue (i.e. changing the underlying data causes “zoomed” update in addition to the downsampling being done behind the scenes).

So I would appreciate any advice anyone can offer…

  1. Is there a reasonable path to tying in zooming (via websocket fetches) in response to range events in a way that allows for reuse of the native Bokeh axis labeling
  2. If not, is there a way to reuse the native Bokeh labeling updates (from a BoxZoomTool derived class) while still replacing the entire plot data (and avoiding having the labeling redone as a result of the data update)
  3. If none of this is possible, is there a way to reuse the Bokeh axis labeling machinery to generate labels to be used with y/xaxis.major_label_overrides

Thanks very much, in advance, for any help.