Skip to content

API Reference — Whole Brain

swclib.whole_brain.tifreader.WBTReader

Parallel reader for large 3D image stacks stored as 2D TIFF slices. The reader recursively scans the slice directory and all subdirectories.

Constructor

WBTReader(slice_dir, slice_name_pattern, slice_ext=".tif")
Parameter Type Description
slice_dir str Directory containing 2D TIFF slice files; searched recursively
slice_name_pattern str Regex with one capture group matching the Z index in each file basename
slice_ext str File extension filter. Defaults to .tif; values without a leading dot are accepted

Example pattern: r"slice_(\d+)\.tif" matches slice_0042.tif with Z index 42.

Attributes

Attribute Type Description
slice_dir str Slice directory
start_z int Minimum Z index found
end_z int Maximum Z index found
height int Slice height (Y dimension)
width int Slice width (X dimension)
depth int Number of slices (Z dimension)
dtype dtype NumPy dtype of slice data

Methods

get_dimensions() → tuple

Returns (depth, height, width).

get_bbox() → tuple

Returns ((x1, y1, z1), (x2, y2, z2)) bounding box.

read_region(start, end, mode='raster', num_workers=32, parallel_backend='thread', padding=None) → ndarray

Read a 3D sub-region from the slice stack.

Parameter Type Default Description
start tuple[int, int, int] Inclusive start corner (z, y, x)
end tuple[int, int, int] Exclusive end corner (z, y, x)
mode str 'raster' Backend: 'raster' (rasterio) or 'tiff' (tifffile)
num_workers int 32 Number of parallel workers
parallel_backend str 'thread' 'thread' or 'process'
padding tuple or None None Optional padding (px, py, pz) added to each side

Returns: ndarray of shape (z2-z1, y2-y1, x2-x1).


swclib.whole_brain.swc_reader.SwcReader

Minimal SWC reader for large whole-brain coordinate files.

Constructor

SwcReader(path, rescale=(1.0, 1.0, 1.0))
Parameter Type Description
path str SWC file path
rescale tuple[float, float, float] Coordinate scale applied while loading (sx, sy, sz)

Methods

read_region(start, end, out_path=None, out_r=None) → Swc

Read nodes inside a whole-brain coordinate cube and return a local-coordinate Swc object. Nodes are reindexed to 1..N; nodes whose parent falls outside the region become roots.

Parameter Type Default Description
start tuple[float, float, float] Inclusive start corner (x, y, z)
end tuple[float, float, float] Exclusive end corner (x, y, z)
out_path str or None None Optional path to save the returned SWC
out_r float or None None Optional radius override for returned and saved nodes

Returns: Swc object containing the cropped region. Empty regions return an empty Swc.