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

Question #141

Open
smith6jt-cop opened this issue Feb 4, 2025 · 8 comments
Open

Question #141

smith6jt-cop opened this issue Feb 4, 2025 · 8 comments

Comments

@smith6jt-cop
Copy link

smith6jt-cop commented Feb 4, 2025

Why doesn't the slider_text update when using stackview.slice?

git-bob answer

Copy link

github-actions bot commented Feb 4, 2025

This message was generated by git-bob (version: 0.17.0, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Hi @smith6jt-cop,

thanks for reaching out! Unfortunately, I'm not allowed to respond to you directly.
I need approval from a person who has access.

Best,
git-bob

@haesleinhuepf
Copy link
Owner

git-bob answer

Copy link

github-actions bot commented Feb 4, 2025

This message was generated by git-bob (version: 0.17.0, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Hi @ smith6jt-cop,

The issue with slider_text not updating when using stackview.slice might be due to how the stackview library updates interface components. If slider_text is managed outside stackview's own UI functionality, ensure that it's correctly linked to stackview's slider events. Otherwise, consider using stackview's own UI elements to handle these updates, as it's designed for seamless integration. If you can share more details or code snippets, I'd be happy to take a closer look.

Best,
git-bob

@haesleinhuepf
Copy link
Owner

I second git-bob 😸 more details would be helpful. If I run this code, the slider_text is shown (the label could be wider though).

import stackview
import numpy as np
image = np.random.random((10,200, 200))
stackview.slice(image, slider_text="abc")

Image

@smith6jt-cop
Copy link
Author

Thanks for the response! Running stackview in a jupyter notebook in VS Code on Windows 10 in conda env (miniforge). Reading in
n=35 (9964 x 9486) registered 16-bit .tif images. As this is a QC step, I would like the user to be able to see the channel name as text while scrolling through the images.

`file_list = sorted(glob(os.path.join(sig_dir,'*.tif')), key=alphanumeric_key)
markers_col = imread_collection(file_list, conserve_memory=True)
markers = np.asarray(markers_col)
marker_names = sorted([os.path.basename(f).split('.')[0] for f in file_list], key=alphanumeric_key)
marker_dict = dict(zip(marker_names, [markers[i,:,:] for i in range(markers.shape[0])]))

stackview.slice(markers, zoom_factor=0.09, slider_text=marker_names)`

I can scroll through the images, but the slider text stays on the first element in marker_names.

So I use:

stackview.switch(marker_dict, zoom_factor=0.09)

Now although the buttons are too small to show the full marker name, hovering over the buttons shows them properly.

@haesleinhuepf
Copy link
Owner

haesleinhuepf commented Feb 4, 2025

I can scroll through the images, but the slider text stays on the first element in marker_names.

That's because the feature you are expecting was not implemented. The "slider_text" is intended as a label for the slider. E.g. if you slice through the Z dimension, you could set the slider_text to "Z" so that the user knows what they are scrolling through.

To have an additional label, which shows a custom text (e.g. a filename) depending on which slice is selected, you can use the observe function of the viewer, which allows you to register a function that is called once the user changes the slider.

I presume this code is close to your use-case:

import ipywidgets as widgets
from IPython.display import display
import stackview
import numpy as np
image = np.random.random((10,200, 200))

filenames = [f"image{i}.tif" for i in range(10)]

# Create the slice viewer
slice_viewer = stackview.slice(image)

# event handler, called when the user moves the slider.
def on_slice_change(event=None):
    label.value = f"You are viewing slice {filenames[slice_viewer.viewer.get_slice_index()[0]]}"

# Create label widget
label = widgets.Label()
on_slice_change()

# Connect the callback to slice changes
slice_viewer.viewer.observe(on_slice_change)

# Display widgets
display(slice_viewer)
display(label)

Image Image

Let me know if this solves the issue!

@smith6jt-cop
Copy link
Author

Aha I was wondering if that was the case. What threw me off was that the input to slider_text is documented as:

str = "[{}]"
slider_text: list or str, optional

So I though the list could be related to the slice. Thank you for your help. The code does now update the string, but the image is not changing with the slider. Probably something with how Jupyter is configured in VS Code (I've been working through this).

@haesleinhuepf
Copy link
Owner

So I though the list could be related to the slice.

It's related to multiple sliders. Thanks for your input! Thus does sound like a good feature request. So I'll keep this issue open for the time being.

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

No branches or pull requests

2 participants