cellmap_flow.portable.volume
Where a new annotation volume lies and what holds its labels: the planning
of finetune/session/volume.py (its module docstring says what a volume
is), on numbers alone, so that the server and the browser plan a volume the
same way. The server reads the raw level and the model’s geometry
(open_raw, resolve_model_geometry) and the browser its
DatasetInfo and model manifest (web/src/finetune/volume.ts, through
volume_calls.py); both hand what they found to plan_volume here.
The grid. A model reads one level of the raw, the one select_level’s
“floor” picks for its input voxel size (or, with Resample, the raw resampled
to that size), and both servers serve its prediction on that level’s grid:
output voxel 0 starts at the level’s corner, and an output voxel is the
level’s voxel times the model’s ratio of output to input voxel size. The
volume lies on that grid, one chunk per model output block, so that a chunk
of paint is a block of the prediction it is painted over, and it covers the
level’s whole extent, a partial output voxel at the far end rounded up, then
padded to whole chunks.
A volume painted before any model (plan_paint_volume, a “paint-first”
volume) lies on the raw’s own grid instead, at a voxel size the user picks
(shown_level gives the default: the level the viewer shows), in chunks
PAINT_FIRST_CHUNK voxels a side. It is for no model (its model_name is
None), so it is not trained on (training_refusal): Which model to start
from ranks the models on its paint, and Use this model carries the paint onto
the chosen model’s grid (carry.py), into a volume that is trained on.
Attributes
Functions
|
The labels' dtype of a new volume for a model that trains on |
|
The world position of an annotation volume's voxel-0 lower corner, in nm. |
|
|
|
|
|
Where a new volume lies for |
|
The index in |
|
Where a new paint-first volume lies: over the raw |
|
Why |
|
Whether grids |
|
A grid (GRID_FIELDS) as the sentences name it: its input block to its |
|
What training's submit says, in both modes, when the session volume |
Module Contents
- cellmap_flow.portable.volume.INSTANCE_TARGETS = ('affinities', 'flows')
- cellmap_flow.portable.volume.WHOLE_VOXEL_TOLERANCE = 1e-06
- cellmap_flow.portable.volume.PAINT_FIRST_CHUNK = 64
- cellmap_flow.portable.volume.PAINT_FIRST_TRAINING = "This volume was painted before a model was chosen, so it is on no model's grid: under Which...
- cellmap_flow.portable.volume.annotation_dtype(output_type) str
The labels’ dtype of a new volume for a model that trains on
output_type.uint8 (ids up to 255) for a model trained on foreground and background; uint16 (up to 65535) for one trained on instances (affinities, Cellpose’s flows), whose seeds number each object: 282 of a Cellpose model’s masks in one box did not fit a uint8 volume.
- cellmap_flow.portable.volume.volume_corner_nm(dataset_offset_nm, output_voxel_size) numpy.ndarray
The world position of an annotation volume’s voxel-0 lower corner, in nm.
dataset_offset_nm(a root attr of every volume) is also written as the volume’s OME-NGFF translation, and a translation is voxel 0’s centre. Neuroglancer drew the volume that way while it was painted, so that is where the labels are: read as a corner, the value puts every label half an annotation voxel away from where it was drawn. None is an offset of 0.
- cellmap_flow.portable.volume.whole_voxels(values, what: str) list
values(a block size in voxels, as floats) as whole numbers.A ValueError names
whatwhen one is not whole: truncating a block of 177.6 voxels to 177 would make a volume whose chunks are not the model’s blocks.
- cellmap_flow.portable.volume.block_shapes(model) tuple
(input_size, output_size), a model’s blocks in voxels.model(a mapping, or an object with these attributes) hasinput_voxel_sizeandoutput_voxel_size, and eitherinput_shape/output_shapein voxels orread_shape/write_shapein nm, which is what a server reports.
- cellmap_flow.portable.volume.plan_volume(level, model) dict
Where a new volume lies for
modelover the rawlevelit reads.levelis that level as the model reads it, z, y, x:voxelits voxel size in nm,cornerits voxel-0 lower corner in nm (not the OME translation, which is the centre),shapeits voxels. On the server it is the levelselect_levelpicks for the model’s input voxel size, at its own voxel size, or the raw resampled to the model’s input voxel size when Resample is on; in the browser, the levelchooseRawLevelpicks.modelis asblock_shapestakes it.Answers the plan’s fields of
VolumeGeometry, as JSON-ready lists:input_voxel_sizethe level’s own,output_voxel_sizethe level’s times the model’s ratio of output to input voxel size (where both servers serve the prediction), the model’s own as the claimed sizes,chunk_sizethe model’s output block andinput_sizeits input block,dataset_offset_nmvoxel 0’s centre (the level’s corner plus half an output voxel) anddataset_shape_voxelsthe level’s extent in output voxels, rounded up, then padded to whole chunks.The ratio is the model’s: snapping the output voxel size to a raw level of its own could break it (on levels of 10, 20 and 40 nm, a model reading 8 nm and writing 16 read the 10 nm level and wrote a 10 nm volume, while its server serves the prediction at 20), and the volume’s chunks were then not the model’s blocks.
- cellmap_flow.portable.volume.SHOWN_LEVEL_SLACK = 1.01
- cellmap_flow.portable.volume.shown_level(voxel_sizes, pixel_nm=None) int
The index in
voxel_sizes(each a raw level’s voxel size in nm, finest first) of the level the viewer shows when one screen pixel spanspixel_nm: the coarsest whose finest axis is no coarser than a pixel, and the finest when zoomed in past it, as Neuroglancer picks the level to draw (viewer/raw.py’s _view_contrast_range reads it so). The finest when the zoom is not known (None: no viewer, or none that has reported one yet). A paint-first volume’s voxel size is this level’s unless the user picks another. A ValueError when there is no level.
- cellmap_flow.portable.volume.plan_paint_volume(level, voxel_size) dict
Where a new paint-first volume lies: over the raw
levelit is read from, on a grid ofvoxel_sizenm (z, y, x), for no model.levelis asplan_volumetakes it: on the server the levelraw_levelopens forvoxel_size(the level at that size, else the finest not coarser than it, at its own voxel size; with Resample on, the raw resampled to it), in the browser the onechooseRawLevelpicks. The grid starts at the level’s corner: at a level’s own voxel size its voxels are the level’s (a size within float noise of it is taken as it), and at another (one the user typed) the level’s extent is covered in voxels of that size, a partial voxel at the far end rounded up. The chunks are PAINT_FIRST_CHUNK voxels a side, as thin as the volume along an axis it is thinner along, and the extent is padded to whole chunks.Answers
plan_volume’s fields:output_voxel_sizethe grid’s,input_voxel_sizethe level’s (what the raw under the paint is read at: Which model to start from’s window of it), no claimed sizes (there is no model to claim any),chunk_size,input_sizea chunk in the level’s voxels, rounded up,dataset_offset_nmvoxel 0’s centre anddataset_shape_voxelsthe padded extent. A ValueError says what is wrong withlevelorvoxel_size.
- cellmap_flow.portable.volume.training_refusal(volume)
Why
volume(its record or root attrs: a mapping, or an object withmodel_name) is not trained on, or None when it can be: PAINT_FIRST_TRAINING for a paint-first volume, which names no model, so no model’s blocks are its chunks to train on.
- cellmap_flow.portable.volume.GRID_FIELDS = ('input_size', 'output_size', 'input_voxel_size', 'output_voxel_size')
- cellmap_flow.portable.volume.same_grid(a, b) bool
Whether grids
aandb(mappings of GRID_FIELDS) are one: the same blocks, voxel for voxel, at the same voxel sizes (float noise of nm aside). A volume made for a model is on the grid of that model, of its finetunes and of any model of the same sizes; a model on another grid took the volume’s 178^3 blocks at 8 nm for its own 1 x 556 x 556 at 16 and torch.export refused them.
- cellmap_flow.portable.volume.grid_text(grid) str
A grid (GRID_FIELDS) as the sentences name it: its input block to its output block, “178×178×178 → 56×56×56 at 8 nm”, each at its own voxel size when the two differ (“1×556×556 at 8 nm → 1×468×468 at 16 nm”).
- cellmap_flow.portable.volume.carried_note(from_model, from_grid, to_model, to_grid, kept) str
What training’s submit says, in both modes, when the session volume was on
from_model’s grid and the model to train,to_model, is on another: the paint carried onto that model’s grid, as Use this model carries it, both grids named (grid_text), and where the old volume is kept (kept, the mode’s words). The input normalization, the postprocessing and the channel stay what the user set: only the volume changed.