dvpio.read.image.read_metadata#
- dvpio.read.image.read_metadata(path, image_type, parse_metadata=True)#
Parse relevant microscopy metadata of dvp-io supported image file
Currently only supports
czifiles andopenslide-compatible files.- Parameters:
- Return type:
- Returns:
Metadata as dictionary
If
parse_metadatais true, returns a dict with the following keys and associated values- image_type: str | None
Name of original type: czi for Carl Zeiss, vendor name for openslide
- objective_nominal_magnification: float | None
Nominal magnification of objective, not considering additional optical setups
- mpp_x: float | None
Resolution in
meters per pixelin x-dimension
- mpp_x: float | None
Resolution in
meters per pixelin y-dimension
- mpp_x: float | None
Resolution in
meters per pixelin z-dimension
- channel_id: list[int] | None
List of indices of microscopy channels
- channel_names: list[str] | None
List of channel names
Example
import spatialdata as sd from dvpio.read.image import read_czi, parse_metadata img_path = "./data/kabatnik2023_20211129_C1.czi" # Initialize spatialdata sdata = sd.SpatialData() # Assign image sdata.images["image"] = read_czi(img_path) # Get controlled attributes from metadata image_metadata = parse_metadata(img_path, image_type="czi", parse_metadata=True) image_metadata > { 'channel_id': [0], 'channel_names': ['TL Brightfield'], 'image_type': 'czi', 'mpp_x': 2.1999999999999998e-07, 'mpp_y': 2.1999999999999998e-07, 'mpp_z': 1.5e-06, 'objective_nominal_magnification': 20.0 } # Get the full metadata document image_metadata = parse_metadata(img_path, image_type="czi", parse_metadata=False) > { 'ImageDocument': {'Metadata': ... } ... } ... } # Assign it to spatialdata.SpatialData.attrs slot for future reference # It is recommended to use the same name as the image sdata.attrs["metadata"] = { "image": image_metadata } # Write # sdata.write("/path/to/sdata.zarr")