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() and prediction_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.

  • raw_layer(): the raw data, with the user’s shader put back.

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

logger

CHUNKMIRAGE

CHUNKMIRAGE_FORMAT

FLOW_CHANNELS

Functions

prediction_voxel_override(host, dataset_path[, info, ...])

The voxel size (nm, z, y, x) to draw a model's output at, or None to

prediction_url(host, model, url_blob[, engine])

The URL of model's zarr on host, with url_blob

prediction_source(host, model, url_blob[, ...])

The source of model's layer: its zarr on host, with url_blob

flow_channels(info, postprocess)

The indices of a flow model's flow_y and flow_x channels, as its

prediction_shader_for(model, host, postprocess[, ...])

A shader for model's layer over the range postprocess produces.

prediction_layer(model, host, url_blob, *, ...[, ...])

model's layer, overlaid on the raw at dataset_path.

display_channel(info, postprocess)

The channel a model's layer opens on: the one its server names

raw_layer(dataset_path, *[, wrap_raw, shader, ...])

The raw data's layer (viewer.raw.get_raw_layer), with the user's

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_size worked 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"], else fallback_output_voxel_size (for a server too old to say).

cellmap_flow.viewer.layers.CHUNKMIRAGE = 'chunkmirage'
cellmap_flow.viewer.layers.CHUNKMIRAGE_FORMAT = 'zarr'
cellmap_flow.viewer.layers.prediction_url(host, model, url_blob, engine=None)

The URL of model’s zarr on host, with url_blob (PipelineSpec.to_url_blob) in it: what the layer’s source points at. engine: the server’s model_info “engine”.

cellmap_flow.viewer.layers.prediction_source(host, model, url_blob, override_scales=None, has_channel=True, channels_shaded=False, engine=None)

The source of model’s layer: its zarr on host, with url_blob (PipelineSpec.to_url_blob) in the URL; engine as prediction_url takes it.

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 (the last, has_channel) keeps it as a unit-less c^.

Neuroglancer reads a served channel axis as c', a slider that shows one channel at a time. channels_shaded renames it c^, 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_y and flow_x channels, 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 range postprocess produces.

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_shader if it has one, so a recomputed range does not also change the colours the user navigates by; else color; 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; unticking flows shows 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)

model’s layer, overlaid on the raw at dataset_path.

A SegmentationLayer when postprocess ends in labels. Otherwise an ImageLayer with shader_controls and shader, the user’s; without one, prediction_shader_for’s in previous_shader’s colour or color.

cellmap_flow.viewer.layers.display_channel(info, postprocess)

The channel a model’s layer opens on: the one its server names (display_channel, Cellpose’s cell probability rather than flow_y), while the chain keeps the model’s channels; None otherwise (the first).

cellmap_flow.viewer.layers.raw_layer(dataset_path, *, wrap_raw=True, shader=None, shader_controls=None)

The raw data’s layer (viewer.raw.get_raw_layer), with the user’s shader and shader_controls in place of the default contrast.

A layer with no shader reports the string “None”, which is not one.