slideflow.studio¶
This module contains the Slideflow Studio visualization tool. See Slideflow Studio: Live Visualization for more information.
- class Sidebar(viz: Studio)[source]¶
Sidebar for Studio, rendering a navigation bar and widgets.
- add_widgets(widgets)[source]¶
Add widget extension(s).
Add widgets to the navigation sidebar. The
.tag
property is used as a unique identifier for the widget. The.icon
property should be a path to an image file used for rendering the sidebar navigation icon..icon_highlighted
property should be a path to an image file used for rendering a hovered navigation icon.The widget should implement
__call__()
and.close()
methods for rendering the imgui GUI and cleanup, respectively.- Parameters:
widgets (list(
slideflow.studio.widgets.Widget
)) – List of widgets to add as extensions. These should be classes, not instantiated objects.
- property content_width¶
Widget width.
- full_button(text, width=None, **kwargs)[source]¶
Render a button that spans the full width of the sidebar.
The color of the button is determined through the loaded theme,
bright_button
properties.
- full_button2(text, width=None, **kwargs)[source]¶
Render a button that spans the full width of the sidebar.
The color of the button is determined through the loaded theme,
bright_button2
properties.
- property full_width¶
Width of the expanded sidebar, including navigation and widgets.
- large_image_button(image_name, size=None)[source]¶
Render a small button for the sidebar.
- Parameters:
- Returns:
If the button was clicked.
- Return type:
- remove_widget(tag)[source]¶
Remove a widget from Studio.
- Parameters:
widget (
slideflow.studio.widgets.Widget
) – Widget to remove. This should be a class, not an instantiated object.
- property theme¶
Active Studio theme.
- class Studio(low_memory: bool = False, widgets: List[Any] | None = None, skip_tk_init: bool = False, theme: StudioTheme | None = None)[source]¶
Create the main Studio window.
Slideflow Studio is started by running the studio module.
python -m slideflow.studio
- Parameters:
- property P¶
Slideflow project currently in use.
- __init__(low_memory: bool = False, widgets: List[Any] | None = None, skip_tk_init: bool = False, theme: StudioTheme | None = None) None [source]¶
Create the main Studio window.
Slideflow Studio is started by running the studio module.
python -m slideflow.studio
- add_to_render_pipeline(renderer: Any, name: str | None = None) None [source]¶
Add a renderer to the rendering pipeline.
- add_widgets(widgets: Widget) None [source]¶
Add widget extension(s).
Add widgets to Studio and the sidebar. The
.tag
property is used as a unique identifier for the widget. The.icon
property should be a path to an image file used for rendering the sidebar navigation icon..icon_highlighted
property should be a path to an image file used for rendering a hovered navigation icon.The widget should implement
__call__()
and.close()
methods for rendering the imgui GUI and cleanup, respectively.- Parameters:
widgets (list(
slideflow.studio.widgets.Widget
)) – List of widgets to add as extensions. These should be classes, not instantiated objects.
- autoload(path, ignore_errors=False)[source]¶
Automatically load a path, detecting the type of object to load.
Supports slides, models, projects, and other items supported by widgets if the widget has implemented a .drag_and_drop_hook function.
- clear_message(msg: str | None = None) bool [source]¶
Clear a specific message from display, if the message is being shown.
- close_model(now: bool = False) None [source]¶
Close the currently loaded model.
- Parameters:
now (bool) – Close the model now, instead of at the end of the frame. Defaults to False (closes model at frame end).
- close_slide(now: bool = False) None [source]¶
Close the currently loaded slide.
- Parameters:
now (bool) – Close the slide now, instead of at the end of the frame. Defaults to False (closes slide at frame end).
- collapsing_header(text, **kwargs)[source]¶
Render a collapsing header using the active theme.
- Examples
Render a collapsing header that is open by default.
if viz.collapsing_header("Header", default=True): imgui.text("Text underneath")
- Parameters:
text (str) – Header text.
- collapsing_header2(text, **kwargs)[source]¶
Render a second-level collapsing header using the active theme.
- Examples
Render a collapsing header that is open by default.
if viz.collapsing_header("Header", default=True): imgui.text("Text underneath")
- Parameters:
text (str) – Header text.
- dim_text(dim=True)[source]¶
Render dim text.
- Examples
Render dim text.
with studio.dim_text(): imgui.text('This is dim')
- static get_default_widgets() List[Any] [source]¶
Returns a list of the default non-mandatory extension widgets.
- get_extension(tag: str) Widget | None [source]¶
Returns a given widget (extension) by tag.
- Parameters:
tag (str) – Tag of the widget to search for.
- Returns:
slideflow.studio.widgets.Widget if found, else None
- get_renderer(name: str | None = None) Renderer | None [source]¶
Check for the given additional renderer in the rendering pipeline.
- Parameters:
name (str) – Name of the renderer to check for. If None, returns the main renderer.
- Returns:
Renderer if name is a recognized renderer, otherwise None
- get_widget(name: str) Widget [source]¶
Returns a given widget by class name.
- Parameters:
name (str) – Name of the widget to search for.
- Returns:
slideflow.studio.widgets.Widget
- Raises:
ValueError – If the widget could not be found.
- header(text)[source]¶
Render a header using the active theme.
- Parameters:
text (str) – Text for the header. Text will be rendered in uppercase.
- header_with_buttons(text)[source]¶
Render a widget header with ability to add buttons.
- Examples
Render a header with a gear icon.
with studio.header_with_buttons('Button'): # Right align the button x_width = imgui.get_content_region_max()[0] imgui.same_line(x_width - 30) cx, cy = imgui.get_cursor_pos() imgui.set_cursor_position((cx, cy-5)) # Render the button if sidebar.small_button('gear'): do_something()
- Parameters:
text (str) – Text for the header. Text will be rendered in uppercase.
- highlighted(enable: bool = True)[source]¶
Render highlighted text.
- Parameters:
enable (bool) – Whether to enable highlighting.
- Examples
Render highlighted text.
with studio.highlighted(True): imgui.text('This is highlighted')
- load_heatmap(path: str | Heatmap) None [source]¶
Load a saved heatmap (*.npz).
- Parameters:
path (str) – Path to exported heatmap in *.npz format, as generated by Heatmap.save() or Heatmap.save_npz().
- property model¶
Tensorflow/PyTorch model currently in use.
- property mouse_is_over_viewer¶
Mouse is currently over the main viewer.
- property offset_x¶
Main window offset (x), in points.
- property offset_x_pixels¶
Main window offset (x), in pixels.
- property offset_y¶
Main window offset (y), in points.
- property offset_y_pixels¶
Main window offset (y), in pixels.
- reload_wsi(slide: str | WSI | None = None, stride: int | None = None, use_rois: bool = True, tile_px: int | None = None, tile_um: str | int | None = None, **kwargs) bool [source]¶
Reload the currently loaded Whole-Slide Image.
- Parameters:
path (str or sf.WSI, optional) – Slide to reload. May be a path or a sf.WSI object. If not provided, will reload the currently loaded slide.
stride (int, optional) – Stride to use for the loaded slide. If not provided, will use the stride value from the currently loaded slide.
use_rois (bool) – Use ROIs from the loaded project, if available.
- Returns:
True if slide loaded successfully, False otherwise.
- Return type:
- remove_from_render_pipeline(name: str)[source]¶
Remove a renderer from the render pipeline.
Remove a renderer added with
.add_to_render_pipeline()
.- Parameters:
name (str) – Name of the renderer to remove.
- remove_widget(widget: Widget) None [source]¶
Remove a widget from Studio.
- Parameters:
widget (
slideflow.studio.widgets.Widget
) – Widget to remove. This should be a class, not an instantiated object.
- set_grid_overlay(grid: ndarray, *, tile_um: int | None = None, stride_div: int | None = None, mpp: float | None = None, original: ndarray | None = None) None [source]¶
Set the grid overlay to the given grid.
- Parameters:
grid (np.ndarray) – Grid to render as an overlay.
- Keyword Arguments:
tile_um (int, optional) – Tile size, in microns. If None, uses the tile size of the currently loaded slide.
stride_div (int, optional) – Stride divisor. If None, uses the stride divisor of the currently loaded slide.
mpp (float, optional) – Microns per pixel. If None, uses the MPP of the currently loaded slide.
original (np.ndarray, optional) – Original grid values before any colorization or other modifications. Used for displaying the tooltip when alt-hovering. Defaults to None.
- set_overlay(overlay: ndarray, method: int, *, original: ndarray | None = None) None [source]¶
Configure the overlay to be applied to the current view screen.
Overlay is a numpy array, and method is a flag indicating the method to use when showing the overlay.
If
method
issf.studio.OVERLAY_WSI
, the array will be mapped to the entire whole-slide image, without offsets.If
method
issf.studio.OVERLAY_GRID
, the array is interpreted as having been generated from the slide’s grid, meaning that an offset will be applied to ensure that the overlay is aligned properly.If
method
issf.studio.OVERLAY_VIEW
, the array is interpreted as an overlay that is applied only to the area of the slide currently in view.- Parameters:
overlay (np.ndarray) – Overlay to render.
method (int) – Mapping method for linking the overlay to the whole-slide image.
- Keyword Arguments:
original (np.ndarray, optional) – Original grid values before any colorization or other modifications. Used for displaying the tooltip when alt-hovering. Defaults to None.
- set_prediction_message(msg: str) None [source]¶
Set the prediction message to display under the tile outline.
- set_status_message(message: str, description: str | None = None, *, color: Tuple[float, float, float] | None = (0.7, 0, 0, 1), text_color: Tuple[float, float, float, float] = (1, 1, 1, 1), rounding: int = 0) None [source]¶
Set the status message to display in the status bar.
- set_viewer(viewer: Any) None [source]¶
Set the main viewer.
- Parameters:
viewer (
slideflow.studio.gui.viewer.Viewer
) – Viewer to use.
- property show_overlay¶
An overlay (e.g. tile filter or heatmap) is currently being shown over the main view.
- property tile_preview_enabled¶
Show a tile preview when right clicking.