cellmap_flow.viewer.raw

The raw data’s neuroglancer layer, and the shaders of the viewer’s layers.

get_raw_layer shows a zarr, N5 or precomputed volume. By default it is served from this process: a multiscale pyramid (an OME-Zarr group’s levels, a precomputed volume’s scales) as one ScalePyramid (each level a LocalVolume, served as a power-of-two downsampling of the finest; a level that is not one is left out), a single array as a LocalVolume, both opened with worldarray (io.raw.open_raw) and indexed through LazyNormalization so that the input chain applies to what is drawn (never to a segmentation’s ids), and placed by a source transform that puts voxel 0’s lower corner where the metadata says. With wrap_raw=False neuroglancer reads the files itself. RAW_SHADER and prediction_shader are the layers’ shaders, their contrast windows sampled from the data where it can be read.

ScalePyramid is adapted from funlib.show.neuroglancer’s scale_pyramid.py (https://github.com/funkelab/funlib.show.neuroglancer).

Attributes

logger

RAW_SHADER

PREDICTION_SHADER

PREDICTION_COLORS

FLOW_SHADER

VIEW_HALF_WIDTH_PX

MAX_VIEW_REACH

Classes

LazyNormalization

A worldarray array seen through the input chain, for neuroglancer to index.

View

Where the viewer looks: center in nm by axis name, and the size in

ScalePyramid

One neuroglancer volume served from a LocalVolume per pyramid level.

Functions

prediction_shader(color[, value_range, dtype])

Shader for a model output layer, over the range the chain produces.

flow_shader(color, value_range, flow_y, flow_x[, ...])

FLOW_SHADER over channels flow_y and flow_x, dimmed by channel

view_of(state)

state's View (a neuroglancer ViewerState), or None when it does

neuroglancer_source(dataset_path)

The source neuroglancer reads dataset_path from itself, in the

get_raw_layer(dataset_path[, normalize, wrap_raw, ...])

A neuroglancer layer showing a zarr, n5 or precomputed volume.

Module Contents

cellmap_flow.viewer.raw.logger
class cellmap_flow.viewer.raw.LazyNormalization(array, normalize=True)

A worldarray array seen through the input chain, for neuroglancer to index.

The channel and the normalizers are looked up on every access rather than fixed when the layer was made: a layer that has already served chunks must still follow a ChannelSelector or a normalizer changed in the dashboard afterwards. Follows the process’s chain (process_chain().input_norms); normalize=False selects the channel but applies no normalizer (a segmentation’s ids, or sampling the stored values).

array
normalize = True
selected()

The array’s tensorstore (unnormalized) with its channel axis pinned to the channel the chain selects; all of it when it has spatial axes only.

property dtype

the last step of the chain that declares one decides, and steps without one (ChannelSelector) pass their input’s through; the stored dtype with normalize=False.

Type:

The dtype indexing gives

cellmap_flow.viewer.raw.RAW_SHADER = Multiline-String
Show Value
"""#uicontrol invlerp normalized({bounds});
#uicontrol vec3 color color(default="white");
void main(){{emitRGB(color * normalized());}}"""
cellmap_flow.viewer.raw.PREDICTION_SHADER = Multiline-String
Show Value
"""#uicontrol invlerp normalized({bounds});
#uicontrol vec3 color color(default="{color}");
void main(){{emitRGB(color * normalized());}}"""
cellmap_flow.viewer.raw.PREDICTION_COLORS = ['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'cyan', 'magenta']
cellmap_flow.viewer.raw.prediction_shader(color, value_range=None, dtype=None)

Shader for a model output layer, over the range the chain produces.

Falls back to [0, 1] when the range is undetermined. That is a guess, but the previous default was range=[0.5, 0.5] – lo == hi makes invlerp a step function rather than a ramp, so every value above 0.5 rendered as solid colour. After a DefaultPostprocessor (0-255) that is the entire prediction. dtype is the output’s, when known: see _invlerp_bounds.

cellmap_flow.viewer.raw.FLOW_SHADER = Multiline-String
Show Value
"""#uicontrol bool flows checkbox(default=true);
#uicontrol float flow_length slider(min=0.5, max=10, default=5);
{cell_control}#uicontrol vec3 color color(default="{color}");
void main(){{
  float shown = {cell};
  if (!flows) {{ emitRGB(color * shown); return; }}
  vec2 flow = vec2(toNormalized(getDataValue({flow_x})), toNormalized(getDataValue({flow_y})));
  float len = length(flow);
  vec2 dir = flow / max(len, 1e-6);
  // cos(angle + 0, -120, 120 degrees), from the direction without atan.
  vec3 hue = 0.5 + 0.5 * (dir.x * vec3(1.0, -0.5, -0.5) - dir.y * vec3(0.0, -0.866, 0.866));
  emitRGB(hue * clamp(len / flow_length, 0.0, 1.0) * shown);
}}"""
cellmap_flow.viewer.raw.flow_shader(color, value_range, flow_y, flow_x, display_channel=None, dtype=None)

FLOW_SHADER over channels flow_y and flow_x, dimmed by channel display_channel over value_range (as prediction_shader’s), or not dimmed without one.

cellmap_flow.viewer.raw.VIEW_HALF_WIDTH_PX = 512
cellmap_flow.viewer.raw.MAX_VIEW_REACH = 256
class cellmap_flow.viewer.raw.View

Where the viewer looks: center in nm by axis name, and the size in nm of one screen pixel there.

center: dict
pixel_nm: float
cellmap_flow.viewer.raw.view_of(state)

state’s View (a neuroglancer ViewerState), or None when it does not have one yet (no position or zoom: the browser has not reported them), or its units are not all lengths (a dimensionless or time axis).

The position is in voxels of the viewer’s coordinate space, whose scales neuroglancer reports in SI units (8 nm as 8e-9 m; the unit table is worldarray’s, io.metadata._NM_PER_UNIT). Its crossSectionScale is how many of the smallest display dimension’s voxels one screen pixel spans.

cellmap_flow.viewer.raw.neuroglancer_source(dataset_path)

The source neuroglancer reads dataset_path from itself, in the browser (wrap_raw=False): its location with the format in front, as neuroglancer names its data sources – zarr:// (v2 or v3, which neuroglancer tells apart), n5:// or precomputed://, followed by a local path or an http(s)://, s3:// or gs:// URL. The format is what worldarray finds there (wa.detect), not what the path’s suffix says.

A precomputed volume is named whole: neuroglancer opens a volume, never one of its scales (…/s2 has no info of its own).

cellmap_flow.viewer.raw.get_raw_layer(dataset_path, normalize=True, wrap_raw=True, segmentation=False, disable_meshes=False, view=None)

A neuroglancer layer showing a zarr, n5 or precomputed volume.

A multiscale pyramid, or any of its levels, is shown as the whole pyramid (see _pyramid for what its levels are). segmentation gives a SegmentationLayer over the same source, placed the same way, for a label volume; its ids are served as stored, never through the input normalizers. disable_meshes then turns off its meshes subsource (see _layer). An image’s contrast is sampled at view (a View, see view_of) when given, as neuroglancer’s 1-99% button would there; else over the whole volume.

class cellmap_flow.viewer.raw.ScalePyramid(volume_layers)

One neuroglancer volume served from a LocalVolume per pyramid level. Mimics a LocalVolume: neuroglancer sees the finest level.

neuroglancer’s python data source asks only for power-of-two downsamplings of the volume it sees (a scale_key such as “2,2,2”). Each level is kept under its downsampling factor, its voxel size over the finest’s per axis ((1, 1, 1) for the finest). A request is served by the level at or below it on every axis that leaves the smallest factor on any one axis (in a pyramid whose levels are each coarser than the last on every axis, the coarsest such level), and that level’s LocalVolume downsamples the rest of the way, up to its own limit; neuroglancer is told to ask no further (_max_downsampling).

A level that is not a power-of-two multiple of the finest on every axis (1.5×, 3×) could never answer a request exactly, so it is left out, as is a second level at a factor already kept; one warning names them. The finest level is always kept, so the pyramid is never empty.

Parameters:

volume_layers (list of LocalVolume) – One LocalVolume per level.

dims
volume_layers
property volume_type
property token
info()
get_encoded_subvolume(data_format, start, end, scale_key=None)
get_object_mesh(object_id)
invalidate()

Mark the data invalidated. Clients will refetch the volume.