neu_vol.piece¶
Read a box out of any source as a neu_lib.Piece, and write one back.
A piece carries its array with the frame saying where it is (voxel size and origin in nm), so a crop cannot lose its position on the way through:
piece = read_piece("crops.h5:/crop_01") # frame from the file
image = read_piece("s3://bucket/em", level=2, crop=piece) # the SAME physical box
write_piece(cleaned, "crops_cleaned.h5") # ...and back out again
A crop given as another piece, or in nm, is converted through the target level’s own voxel
size and origin, so it transfers between levels and between volumes. write_piece()
writes an in-memory piece in the same layout pack_hdf5() uses, so
neu-vol write can place either with no arguments.
Attributes¶
Functions¶
|
What to call a piece read from |
|
The voxels at |
|
Write a |
Module Contents¶
- neu_vol.piece.piece_name(path: str, dataset: str | None = None) str¶
What to call a piece read from
path:stemorstem/dataset.Both halves, since crops from different files often share a dataset name and crops in one file share a stem, and a viewer keys layers by name.
- neu_vol.piece.read_piece(src: str | Mapping[str, Any], kind: str | None = None, *, level: int = 0, crop: Any = None, dataset: str | None = None, src_format: str | None = None, dtype: str | type | None = None, voxel_size: Sequence[float] | None = None, name: str | None = None, max_bytes: int | None = DEFAULT_MAX_BYTES, backend: Any = None)¶
The voxels at
src, with the frame that says where they are.srcisPATHorPATH:/DATASET, the second selecting an array inside an HDF5 container (only a leading slash after the last colon counts, sos3://is left alone). A spec mapping or an openbackend=is accepted too.cropis a box in whole voxels of the level read (((lo), (hi))or the flat six), anything carryingbounds_nmsuch as anotherPiece, or{"nm": (lo, hi)}. A physical box is converted with this level’s own voxel size and origin and grown outward to whole voxels.kindoverrides what the source records; unrecorded, it staysNonerather than being guessed from the dtype.voxel_sizeoverrides the recorded scale and is required for a source that records none.dtypecasts after the read, warning on a narrowing cast, which would silently wrap label ids.The piece is named
stemorstem/datasetafter its source (piece_name()), unlessnameis given.max_bytesrefuses a read larger than the cap, naming the size and a level that would fit;Nonelifts it. Store logging is filtered for the call.
- neu_vol.piece.write_piece(piece, out: str, *, dataset: str | None = None, dtype: Any = None, truncate: bool = False, chunk: Sequence[int] | None = None, compression: str | None = 'gzip', overwrite: bool = False, dry_run: bool = False, voxel_size_field: str | None = None, offset_field: str | None = None, block_bytes: int | None = None) dict¶
Write a
neu_lib.Pieceto an HDF5 file, frame and position included.The inverse of
read_piece():piece = read_piece("crops.h5:/crop_01") cleaned = piece.apply(dust).apply(dilate) write_piece(cleaned, "crops_cleaned.h5") # -> /crop_01, same frame
The piece supplies the voxel size, the voxel offset (
piece.origin_voxel, which raises rather than rounding a non-whole origin),axes="zyx",units="nm"and itskind.datasetdefaults to the last component ofpiece.namewhen it has one ("crops/crop_01"->/crop_01), elseDEFAULT_DATASET.An existing file is added to when its recorded frame matches; a frame that disagrees, or a dataset name already in use without
overwrite, is refused (check_hdf5_target()). Writing is blocked, so a lazy array streams.dry_runreturns the plan without writing. Adtypetoo narrow for the values is refused unlesstruncate(check_fits()).outmust be a local path with an HDF5 extension: h5py has no object-store driver, and HDF5 files are recognised by name.neu-vol write <volume> --src <file>then places the piece with no offset argument.
- neu_vol.piece.DEFAULT_MAX_BYTES = 4294967296¶
- neu_vol.piece.logger¶