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 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 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.
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.
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
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 bymake_aborter()
.json
Provides access to JSON methods.
url_build_error_handlers
A list of functions that are called by
handle_url_build_error()
whenurl_for()
raises aBuildError
.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:
- 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_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
- 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
- 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