TileServer¶
- class TileServer(title, layers, renderer=None)[source]¶
A Flask app to display Zoomify tiles as a slippery map.
- Parameters:
title (str) – The title of the tile server, displayed in the browser as the page title.
layers (Dict[str, WSIReader | str] | List[WSIReader | str]) – A dictionary mapping layer names to image paths, annotation paths, or
WSIReaderobjects to display. The dictionary should have a ‘slide’ key which is the base slide for the visualization. May also be a list, in which case generic names ‘slide’, ‘layer-1’, ‘layer-2’ etc. will be used. First entry in list will be assumed to be the base slide. If a layer is a single-channel low-res overlay, it will be colourized using the ‘viridis’ colourmap.renderer (AnnotationRenderer | None)
Examples
>>> from tiatoolbox.wsicore.wsireader import WSIReader >>> from tiatoolbox.visualization.tileserver import TileServer >>> wsi = WSIReader.open("CMU-1.svs") >>> app = TileServer( ... title="Testing TileServer", ... layers={ ... "My SVS": wsi, ... }, ... ) >>> app.run()
Initialize
TileServer.Methods
Change the colour mapper for the overlay.
Change the overlay.
Change the property to colour annotations by.
Change the type-specific colour mapper for the overlay.
Change the slide.
Commit changes to the current store.
Decode a URL-safe name.
Get the annotation layer for a session_id.
Get the annotations in the specified bounds.
Get the channels of the slide.
Get the property used to color annotations from renderer.
Get the mapper used to color annotations from renderer.
Get the overlay info.
Get all the properties of the annotations in the store.
Get all the values of a property in the store.
Get the requested property from the renderer.
Get the secondary cmap from the renderer.
Get the slide metadata.
Simple health check endpoint to verify the server is running.
Serve the index page.
Load annotations from a dat file.
Set the range which the color mapper will map to.
Reset the tileserver.
Set up a new session.
Retrieve a mapping of session keys to their corresponding slide file paths.
Set the channels of the slide.
Set the enhance factor of the slide.
Shutdown the tileserver.
Query for annotations at a point.
Update a property in the renderer.
Get the available types from the store.
Serve a Zoomify tile for a particular layer.
Attributes
cliThe Click command group for registering CLI commands for this object.
instance_pathHolds the path to the instance folder.
configThe configuration dictionary as
Config.aborterAn instance of
aborter_classcreated bymake_aborter().jsonProvides access to JSON methods.
url_build_error_handlersA list of functions that are called by
handle_url_build_error()whenurl_for()raises aBuildError.teardown_appcontext_funcsA list of functions that are called when the application context is destroyed.
shell_context_processorsA list of shell context processor functions that should be run when a shell context is created.
blueprintsMaps registered blueprint names to blueprint objects.
extensionsa place where extensions can store application specific state.
url_mapThe
Mapfor this instance. You can use this to change the routing converters after the class was created but before any routes are connected. Example::.import_nameThe name of the package or module that this object belongs to.
template_folderThe path to the templates folder, relative to
root_path, to add to the template loader.root_pathAbsolute path to the package on the filesystem.
view_functionsA dictionary mapping endpoint names to view functions.
error_handler_specA data structure of registered error handlers, in the format
{scope: {code: {class: handler}}}.before_request_funcsA data structure of functions to call at the beginning of each request, in the format
{scope: [functions]}.after_request_funcsA data structure of functions to call at the end of each request, in the format
{scope: [functions]}.teardown_request_funcsA data structure of functions to call at the end of each request even if an exception is raised, in the format
{scope: [functions]}.template_context_processorsA data structure of functions to call to pass extra context values when rendering templates, in the format
{scope: [functions]}.url_value_preprocessorsA data structure of functions to call to modify the keyword arguments passed to the view function, in the format
{scope: [functions]}.url_default_functionsA data structure of functions to call to modify the keyword arguments when generating URLs, in the format
{scope: [functions]}.- change_mapper()[source]¶
Change the colour mapper for the overlay.
- Parameters:
self (TileServer)
- Return type:
- change_overlay()[source]¶
Change the overlay.
If the path points to some annotations, the current overlay is replaced with the new one. If the path points to an image, it is added as a new layer.
- Returns:
A jsonified list of types.
- Return type:
- Parameters:
self (TileServer)
- change_prop()[source]¶
Change the property to colour annotations by.
- Parameters:
self (TileServer)
- Return type:
- change_secondary_cmap()[source]¶
Change the type-specific colour mapper for the overlay.
- Parameters:
self (TileServer)
- Return type:
- change_slide()[source]¶
Change the slide.
- Parameters:
self (TileServer)
- Return type:
- commit_db()[source]¶
Commit changes to the current store.
If the store is not already associated with a .db file, the save_path is used to create a new .db file.
- Parameters:
self (TileServer)
- Return type:
- get_ann_layer(session_id)[source]¶
Get the annotation layer for a session_id.
- Parameters:
self (TileServer)
session_id (str)
- Return type:
- get_annotations()[source]¶
Get the annotations in the specified bounds.
- Parameters:
self (TileServer)
- Return type:
Response
- get_channels()[source]¶
Get the channels of the slide.
- Parameters:
self (TileServer)
- Return type:
Response
- get_color_prop()[source]¶
Get the property used to color annotations from renderer.
- Parameters:
self (TileServer)
- Return type:
Response
- get_mapper()[source]¶
Get the mapper used to color annotations from renderer.
- Parameters:
self (TileServer)
- Return type:
Response
- get_overlay()[source]¶
Get the overlay info.
- Parameters:
self (TileServer)
- Return type:
Response
- get_properties(ann_type)[source]¶
Get all the properties of the annotations in the store.
- Parameters:
ann_type (str) – The type of annotations to get the properties for.
self (TileServer)
- Returns:
A jsonified list of the properties.
- Return type:
- get_property_values(prop, ann_type)[source]¶
Get all the values of a property in the store.
- Parameters:
prop (str) – The property to get the values of.
ann_type (str) – The type of annotations to get the values for.
self (TileServer)
- Returns:
A jsonified list of the values of the property.
- Return type:
- get_renderer(prop)[source]¶
Get the requested property from the renderer.
- Parameters:
self (TileServer)
prop (str)
- Return type:
Response
- get_secondary_cmap()[source]¶
Get the secondary cmap from the renderer.
- Parameters:
self (TileServer)
- Return type:
Response
- get_slide()[source]¶
Get the slide metadata.
- Parameters:
self (TileServer)
- Return type:
Response
- static healthcheck()[source]¶
Simple health check endpoint to verify the server is running.
Useful for load balancers or uptime monitoring tools to check if the service is operational.
- Returns:
A JSON response with status “OK” and HTTP status code 200.
- Return type:
Response
- index()[source]¶
Serve the index page.
- Returns:
The index page.
- Return type:
flask.Response
- Parameters:
self (TileServer)
- load_annotations()[source]¶
Load annotations from a dat file.
Adds to an existing store if one is already present, otherwise creates a new store.
- Returns:
A jsonified list of types.
- Return type:
- Parameters:
self (TileServer)
- prop_range()[source]¶
Set the range which the color mapper will map to.
It will create an appropriate function to map the range to the range [0, 1], and set the renderers score_fn to this function.
- Parameters:
self (TileServer)
- Return type:
- reset(session_id)[source]¶
Reset the tileserver.
- Parameters:
self (TileServer)
session_id (str)
- Return type:
- session_id()[source]¶
Set up a new session.
- Parameters:
self (TileServer)
- Return type:
Response
- sessions()[source]¶
Retrieve a mapping of session keys to their corresponding slide file paths.
- Returns:
A JSON response containing a mapping of session keys and their respective slide file paths.
- Return type:
Response
- Parameters:
self (TileServer)
- set_channels()[source]¶
Set the channels of the slide.
- Parameters:
self (TileServer)
- Return type:
- set_enhance()[source]¶
Set the enhance factor of the slide.
- Parameters:
self (TileServer)
- Return type:
- tap_query(x, y)[source]¶
Query for annotations at a point.
- Parameters:
x (float) – The x coordinate.
y (float) – The y coordinate.
self (TileServer)
- Returns:
The jsonified dict of the properties of the smallest annotation returned from the query at the point.
- Return type:
Response
- update_renderer(prop)[source]¶
Update a property in the renderer.
- Parameters:
prop (str) – The property to update.
self (TileServer)
- Return type:
- static update_types(sq)[source]¶
Get the available types from the store.
- Parameters:
sq (SQLiteStore)
- Return type:
- zoomify(layer, session_id, tile_group, z, x, y, res)[source]¶
Serve a Zoomify tile for a particular layer.
Note that this should not be called directly, but will be called automatically by the Flask framework when a client requests a tile at the registered URL.
- Parameters:
layer (str) – The layer name.
session_id (str) – Session ID. Unique ID to disambiguate requests from different sessions.
tile_group (int) – The tile group. Currently unused.
z (int) – The zoom level.
x (int) – The x coordinate.
y (int) – The y coordinate.
res (int) – Resolution to save the tiles at. Helps to specify high resolution tiles. Valid options are 1 and 2.
self (TileServer)
- Returns:
The tile image response.
- Return type:
flask.Response