HDF5FileHandlerο
- class btrack.io.HDF5FileHandler(filename: PathLike, read_write: str = 'r', *, obj_type: str = 'obj_type_1')ο
Bases:
object
Generic HDF5 file hander for reading and writing datasets. This is inter-operable between segmentation, tracking and analysis code.
- Parameters:
- filenamestr
The filename of the hdf5 file to be used.
- read_writestr
A read/write mode for the file, e.g. w, r, a etc.
- obj_typestr
The name of the object type. Defaults to obj_type_1. The object type name must start with obj_type_
Notes
Basic format of the HDF file is:
data.h5/ ββ segmentation/ β ββ images (J x (d) x h x w) uint16 segmentation ββ objects/ β ββ obj_type_1/ β β ββ coords (I x 5) [t, x, y, z, object_type] β β ββ labels (I x D) [label, (softmax scores ...)] β β ββ map (J x 2) [start_index, end_index] -> coords array β β ββ properties / β β β ββ area (I x 1) first named property (e.g. `area`) β β β ββ ... β ββ obj_type_2/ β ββ ... ββ tracks/ β ββ obj_type_1/ β β ββ tracks (I x 1) [index into coords] β β ββ dummies similar to objects/coords, but for dummy objects β β ββ map (K x 2) [start_index, end_index] -> tracks array β β ββ LBEPRG (K x 6) [L, B, E, P, R, G] β β ββ fates (K x n) [fate_from_tracker, ...future_expansion] β ββ obj_type_2/ β ββ ...
Where
I
is the number of objects,J
is the number of frames andK
is number of tracks. LBEPR is a modification of the LBEP format to also include the root node of the tree.Examples
Read objects from a file:
>>> with HDF5FileHandler('file.h5', 'r') as handler: ... objects = handler.objects
Use filtering by property for object retrieval:
>>> obj = handler.filtered_objects('flag==1') ... obj = handler.filtered_objects('area>100')
Write tracks directly to a file:
>>> handler.write_tracks(tracks)
- Attributes:
- segmentationnpt.NDArray
A numpy array representing the segmentation data. TZYX
objects
list [PyTrackObject]Return the objects in the file.
filtered_objects
npt.NDArrayA filtered list of objects based on metadata.
tracks
list [Tracklet]Return the tracks in the file.
lbep
npt.NDArrayReturn the LBEP data.
Attributes Summary
Return the LBEP data.
Return the objects in the file.
Return the tracks in the file.
Methods Summary
close
()filtered_objects
([f_expr,Β ...])A filtered list of objects based on metadata.
tree
()Recursively iterate over the H5 file to reveal the tree structure and number of elements within.
write_objects
(data)Write objects to HDF file.
write_properties
(data,Β *[,Β allow_overwrite])Write object properties to HDF file.
write_segmentation
(segmentation)Write out the segmentation to an HDF file.
write_tracks
(data,Β *[,Β f_expr])Write tracks to HDF file.
Attributes Documentation
- lbepο
Return the LBEP data.
- object_typeο
- object_typesο
- objectsο
Return the objects in the file.
- segmentationο
- tracksο
Return the tracks in the file.
Methods Documentation
- close()ο
- filtered_objects(f_expr: str | None = None, *, lazy_load_properties: bool = True, exclude_properties: list[str] | None = None) list[PyTrackObject] ο
A filtered list of objects based on metadata.
- Parameters:
- f_exprstr
A string representing a filtering option. For example, area>100 would filter objects by a property key area where the numerical value of area was greater than 100.
- lazy_load_propertiesbool
For future expansion. To allow lazy loading of large datasets.
- exclude_propertieslist or None
A list of properties keys to exclude when loading from disk.
- Returns:
- objectslist
A list of
btrack.btypes.PyTrackObject
objects.
- tree() None ο
Recursively iterate over the H5 file to reveal the tree structure and number of elements within.
- write_objects(data: list[btypes.PyTrackObject] | BayesianTracker) None ο
Write objects to HDF file.
- Parameters:
- datalist or BayesianTracker instance
Either a list of PyTrackObject to be written, or an instance of BayesianTracker with a .objects property.
- write_properties(data: dict[str, Any], *, allow_overwrite: bool = False) None ο
Write object properties to HDF file.
- Parameters:
- datadict {key: (N, D)}
A dictionary of key-value pairs of properties to be written. The values should be an array equal in length to the number of objects and with D dimensions.
- allow_overwritebool
Allow to delete the existing property keys from the HDF5 file and overwrite with new values from the data dict. Defaults to False.
- write_segmentation(segmentation: ndarray[Any, dtype[_ScalarType_co]]) None ο
Write out the segmentation to an HDF file.
- Parameters:
- segmentationnpt.NDArray
A numpy array representing the segmentation data. T(Z)YX, uint16
- write_tracks(data: list[btypes.Tracklet] | BayesianTracker, *, f_expr: str | None = None) None ο
Write tracks to HDF file.
- Parameters:
- datalist of Tracklets or an instance of BayesianTracker
A list of tracklets or an instance of BayesianTracker.
- f_exprstr
An expression which represents how the objects have been filtered prior to tracking, e.g. area>100.0