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 WSIReader objects 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_mapper

Change the colour mapper for the overlay.

change_overlay

Change the overlay.

change_prop

Change the property to colour annotations by.

change_secondary_cmap

Change the type-specific colour mapper for the overlay.

change_slide

Change the slide.

commit_db

Commit changes to the current store.

decode_safe_name

Decode a URL-safe name.

get_ann_layer

Get the annotation layer for a session_id.

get_annotations

Get the annotations in the specified bounds.

get_color_prop

Get the property used to color annotations from renderer.

get_mapper

Get the mapper used to color annotations from renderer.

get_overlay

Get the overlay info.

get_properties

Get all the properties of the annotations in the store.

get_property_values

Get all the values of a property in the store.

get_renderer

Get the requested property from the renderer.

get_secondary_cmap

Get the secondary cmap from the renderer.

get_slide

Get the slide metadata.

index

Serve the index page.

load_annotations

Load annotations from a dat file.

prop_range

Set the range which the color mapper will map to.

reset

Reset the tileserver.

session_id

Set up a new session.

shutdown

Shutdown the tileserver.

tap_query

Query for annotations at a point.

update_renderer

Update a property in the renderer.

update_types

Get the available types from the store.

zoomify

Serve a Zoomify tile for a particular layer.

Attributes

cli

The Click command group for registering CLI commands for this object.

instance_path

Holds the path to the instance folder.

config

The configuration dictionary as Config.

aborter

An instance of aborter_class created by make_aborter().

json

Provides access to JSON methods.

url_build_error_handlers

A list of functions that are called by handle_url_build_error() when url_for() raises a BuildError.

teardown_appcontext_funcs

A list of functions that are called when the application context is destroyed.

shell_context_processors

A list of shell context processor functions that should be run when a shell context is created.

blueprints

Maps registered blueprint names to blueprint objects.

extensions

a place where extensions can store application specific state.

url_map

The Map for this instance. You can use this to change the routing converters after the class was created but before any routes are connected. Example::.

import_name

The name of the package or module that this object belongs to.

template_folder

The path to the templates folder, relative to root_path, to add to the template loader.

root_path

Absolute path to the package on the filesystem.

view_functions

A dictionary mapping endpoint names to view functions.

error_handler_spec

A data structure of registered error handlers, in the format {scope: {code: {class: handler}}}.

before_request_funcs

A data structure of functions to call at the beginning of each request, in the format {scope: [functions]}.

after_request_funcs

A data structure of functions to call at the end of each request, in the format {scope: [functions]}.

teardown_request_funcs

A 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_processors

A data structure of functions to call to pass extra context values when rendering templates, in the format {scope: [functions]}.

url_value_preprocessors

A data structure of functions to call to modify the keyword arguments passed to the view function, in the format {scope: [functions]}.

url_default_functions

A 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:

str

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:

str

Parameters:

self (TileServer)

change_prop()[source]¶

Change the property to colour annotations by.

Parameters:

self (TileServer)

Return type:

str

change_secondary_cmap()[source]¶

Change the type-specific colour mapper for the overlay.

Parameters:

self (TileServer)

Return type:

str

change_slide()[source]¶

Change the slide.

Parameters:

self (TileServer)

Return type:

str

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:

str

static decode_safe_name(name)[source]¶

Decode a URL-safe name.

Parameters:

name (str)

Return type:

Path

get_ann_layer(session_id)[source]¶

Get the annotation layer for a session_id.

Parameters:
Return type:

AnnotationTileGenerator | ValueError

get_annotations()[source]¶

Get the annotations in the specified bounds.

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:

str

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:

str

get_renderer(prop)[source]¶

Get the requested property from the renderer.

Parameters:
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

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:

str

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:

str

reset(session_id)[source]¶

Reset the tileserver.

Parameters:
Return type:

str

session_id()[source]¶

Set up a new session.

Parameters:

self (TileServer)

Return type:

Response

static shutdown()[source]¶

Shutdown the tileserver.

Return type:

None

tap_query(x, y)[source]¶

Query for annotations at a point.

Parameters:
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:
Return type:

str

static update_types(sq)[source]¶

Get the available types from the store.

Parameters:

sq (SQLiteStore)

Return type:

tuple

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