cellmap_flow.viewer.layers
The layers the viewer shows: a model’s predictions, and the raw data.
Every path that shows a model’s output builds its layer from these, so that they all place and shade it the same way:
prediction_voxel_override(): the voxel size to draw a model’s output at, when it is not the one its server declares.prediction_url()andprediction_source(): the layer’s URL, a zarr served by the model’s inference server with the chain in it, and its source, that URL with the override as its transform.prediction_shader_for(): a shader over the range the chain produces; for a flow model’s channels, one that shows them all at once.prediction_layer(): the layer itself, a segmentation when the chain ends in labels and an image otherwise, open on the channeldisplay_channel()gives, atchannel_position().raw_layer(): the raw data, with the user’s shader put back.replace_layer(): a layer drawn again in place of one of the same name, keeping what the user set on that one (carried_layer_json()).deleted_layers(): the layers gone from one viewer state to the next, a layer renamed aside.
A model’s info is its server’s model_info (serving.client). A
caller that already asked for it passes it in, so building a layer asks the
server once.
Attributes
Functions
|
The voxel size (nm, z, y, x) to draw a model's output at, or None to |
|
The URL of |
|
The source of |
|
The indices of a flow model's |
|
A shader for |
|
|
|
The channel a model's layer opens on: |
|
The local position an image layer of a model opens at: the channel |
|
The raw data's layer (viewer.raw.get_raw_layer), with the user's |
|
|
|
Put |
|
The names of the layers in |
Module Contents
- cellmap_flow.viewer.layers.logger
- cellmap_flow.viewer.layers.prediction_voxel_override(host, dataset_path, info=None, fallback_output_voxel_size=None)
The voxel size (nm, z, y, x) to draw a model’s output at, or None to draw it at the size its server declares.
A server reads the raw at the pyramid level closest to its model’s input voxel size and treats that level as if it were at the model’s size, so when the two differ its output is really at a proportionally different size than it declares: a model trained at 16 nm on raw at 6, 12, 24 nm reads 12 nm data, and its output lies at 12 nm, not 16.
A server that reports
effective_output_voxel_sizeworked that out from the level it read, so its answer is used. For an older server the override is a guess, the raw level closest to the declared output voxel size, which is right when the model’s input and output voxel sizes are equal.The declared size is
info["output_voxel_size"], elsefallback_output_voxel_size(for a server too old to say).
- cellmap_flow.viewer.layers.prediction_url(host, model, url_blob)
The URL of
model’s zarr onhost, withurl_blob(PipelineSpec.to_url_blob) in it: what the layer’s source points at. The server serves the name in the format after it (serving.protocol.FORMAT).
- cellmap_flow.viewer.layers.prediction_source(host, model, url_blob, override_scales=None, has_channel=True, channels_shaded=False)
The source of
model’s layer: its zarr onhost, withurl_blob(PipelineSpec.to_url_blob) in the URL.With
override_scales(z, y, x nm, as prediction_voxel_override gives them) it is a dict whose transform declares the array at those scales. Neuroglancer wants the same rank on both sides of a transform, so a served array with a channel axis (has_channel) keeps it as a unit-lessc^.Neuroglancer reads a served channel axis as
c', a slider that shows one channel at a time.channels_shadedrenames itc^, a channel axis, which the shader reads every channel of. A transform renames the source dimensions it names and passes the rest through.
- cellmap_flow.viewer.layers.FLOW_CHANNELS = ('flow_y', 'flow_x')
- cellmap_flow.viewer.layers.flow_channels(info, postprocess)
The indices of a flow model’s
flow_yandflow_xchannels, as its server names them, while the chain keeps its channels; None otherwise.A model that predicts flows towards each object’s centre (Cellpose) has channels that mean different things: one at a time, the y flow alone says little. prediction_layer shows them together instead.
- cellmap_flow.viewer.layers.prediction_shader_for(model, host, postprocess, previous_shader=None, color=None, info=None)
A shader for
model’s layer over the rangepostprocessproduces.Unlike the raw there is nothing to sample, since reading the output means running the model, but nothing needs sampling: the chain’s last step fixes the range (serving.probe.output_display_range). The colour is the one in
previous_shaderif it has one, so a recomputed range does not also change the colours the user navigates by; elsecolor; else the first prediction colour.For a flow model’s channels (flow_channels), the shader colours each voxel by its flow’s direction, dimmed by the channel the server names to display (
display_channel, Cellpose’s cell probability) over the range; untickingflowsshows that channel alone.
- cellmap_flow.viewer.layers.prediction_layer(model, host, url_blob, *, dataset_path, postprocess, shader=None, shader_controls=None, color=None, previous_shader=None, info=None, fallback_output_voxel_size=None, channel=None)
model’s layer, overlaid on the raw atdataset_path.A SegmentationLayer when
postprocessends in labels. Otherwise an ImageLayer withshader_controlsandshader, the user’s; without one, prediction_shader_for’s inprevious_shader’s colour orcolor. It opens onchannelwhen given (the one the Finetune tab picked to show, dashboard Session.shown_channel), else on the one its server names (channel_position).
- cellmap_flow.viewer.layers.display_channel(info, postprocess, shown=None)
The channel a model’s layer opens on:
shown, the one picked to show (the Finetune tab’s, mito of fly_organelles’ eight), else the one its server names (display_channel, Cellpose’s cell probability rather than flow_y), while the chain keeps the model’s channels and the model has that one; None otherwise (the first).
- cellmap_flow.viewer.layers.channel_position(info, postprocess, shown=None)
The local position an image layer of a model opens at: the channel display_channel gives, at its centre (neuroglancer’s channel axis is a local dimension, its position the channel shown). The served array’s OME translation is 0 on its channel axis, a voxel centre, so channel k lies over [k - 0.5, k + 0.5) and its centre is k: at k + 0.5, fly_organelles’ layer showed mito (2) with its channel box at 1, organelle. None, which leaves neuroglancer’s (the first), without one, and while a flow model’s channels are shown together (flow_channels), whose shader reads every one. prediction_layer opens a layer at it, and POST /api/finetune/channel moves a layer shown to it.
- cellmap_flow.viewer.layers.raw_layer(dataset_path, *, wrap_raw=True, shader=None, shader_controls=None, view=None)
The raw data’s layer (viewer.raw.get_raw_layer), with the user’s
shaderandshader_controlsin place of the default contrast; without them, the contrast is sampled atviewwhen given.A layer with no shader reports the string “None”, which is not one.
- cellmap_flow.viewer.layers.SOURCE_BOUND_LAYER_KEYS
- cellmap_flow.viewer.layers.carried_layer_json(old, new)
new, a layer’s JSON, as it takes the place ofold(or None), keeping what the user set onold.A redraw (Submit, a model coming up, a mark drawn) builds each layer anew, and neuroglancer shows the new one as built: the user’s blending (additive), opacity, resolution, volume rendering, segment colouring or tab were back at their defaults, and a layer they had switched off came back on. So the result is
newwith every property ofoldthatnewdoes not set: the dashboard’s own properties (the source, a new chain’s shader, the annotations drawn) win, the user’s other settings stay. When the source is another one, the properties tied to its data (SOURCE_BOUND_LAYER_KEYS) are not kept. A layer of another type (an image layer become a segmentation when the chain now ends in labels) has no settings this one would read, and keeps only being hidden. The browser’s viewer does the same (web/src/viewer/state.ts’s carriedLayer).
- cellmap_flow.viewer.layers.replace_layer(layers, name, layer, replacing=None)
Put
layerinlayers(a viewer state’s) asname, keeping what the user set on the layer it replaces (carried_layer_json).That is the layer
name, or, when there is none, the layerreplacingnames (a finetuned model’s previous iteration, whose successor takes its place in the list and its settings); that one is removed either way. Being hidden is the managed layer’s, not the layer’s, so it is set on the managed layer after the layer is in place.
- cellmap_flow.viewer.layers.deleted_layers(before, after)
The names of the layers in
beforethatafterhas not, each a viewer state’s list of layers as JSON: the layers deleted between the two.A layer whose name went while a layer new in
afterreads its source was renamed (neuroglancer’s layer panel edits a layer’s name), not deleted. A hidden layer is still in the state, so it is not deleted either. The browser’s viewer tells them by the same rule (web/src/viewer/state.ts’s deletedLayers).