liffile¶
Read Leica image files (LIF, LOF, XLIF, XLCF, XLEF, and LIFEXT).
Liffile is a Python library to read image and metadata from Leica image files: LIF (Leica Image File), LOF (Leica Object File), XLIF (XML Image File), XLCF (XML Collection File), XLEF (XML Experiment File), and LIFEXT (Leica Image File Extension). These files are written by LAS X software to store collections of images and metadata from microscopy experiments.
- Author:
- License:
BSD-3-Clause
- Version:
2026.4.11
- DOI:
Quickstart¶
Install the liffile package and all dependencies from the Python Package Index:
python -m pip install -U liffile[all]
See Examples for using the programming interface.
Source code and support are available on GitHub.
Requirements¶
This revision was tested with the following requirements and dependencies (other versions may work):
CPython 3.12.10, 3.13.13, 3.14.4 64-bit
NumPy 2.4.4
Imagecodecs 2026.3.6 (required for decoding TIFF, JPEG, PNG, and BMP)
Tifffile 2026.3.3 (required for reading multi-page TIFF)
Xarray 2026.2.0 (recommended)
Matplotlib 3.10.8 (optional)
Revisions¶
2026.4.11
Add channel name resolution to LifImage via coords[‘C’] and coords[‘S’].
Drop support for Python 3.11.
2026.2.16
Change timestamps to None if not present (breaking).
Fix inefficient timestamp parsing.
Fix inefficient LifFile.close().
Add tilescan property to LifImage.
2026.2.15
Add experimental frame-based interface to LifImage.
Fix code review issues.
2026.1.22
Fix reading sequence of LifMemoryBlocks.
Change unknown axis code to ‘?’.
2026.1.14
Improve code quality.
2025.12.12
Remove deprecated LifFile.series and xml_element_smd properties (breaking).
Improve code quality.
2025.11.8
Add option to find other LifImageSeries attributes than path.
Return UniqueID in LifImage.attrs.
Factor out BinaryFile base class.
2025.9.28
Derive LifFileError from ValueError.
Minor fixes.
Drop support for Python 3.10.
2025.5.10
Support Python 3.14.
2025.4.12
Improve case_sensitive_path function.
2025.3.8
Support LOF files without LMSDataContainerHeader XML element.
2025.3.6
Support stride-aligned RGB images.
2025.2.20
…
Refer to the CHANGES file for older revisions.
Notes¶
The API is not stable yet and might change between revisions.
Leica Microsystems GmbH is a manufacturer of microscopes and scientific instruments. Leica image files are proprietary formats written by Leica acquisition software such as LAS X and LAS AF to store microscopy images and metadata.
The Leica Image File (LIF) begins with a magic number followed by a UTF-16 XML header that describes images and metadata, then stores the raw pixel data for each image in contiguous data blocks. Images may be multi-dimensional (X, Y, Z, T, C, …) with multiple channels, and a single file can contain many independent image series. Related formats include LOF (single-object variant), XLIF, XLEF, and XLCF (XML-based containers), XLLF (folder-view), and LIFEXT (optional image data extensions).
This library is not feature-complete. Unsupported features currently include XLLF, image mosaics and pyramids, bit increments, and non-image data such as raw FLIM/TCSPC histogram data.
The library has been tested with only a limited number of version 2 files.
The Leica image file formats are documented in:
Leica Image File Formats - LIF, XLEF, XLLF, LOF. Version 3.2. Leica Microsystems GmbH. 21 September 2016.
Annotations to Leica Image File Formats for LAS X Version 3.x. Version 1.4. Leica Microsystems GmbH. 24 August 2016.
TSC SP8 FALCON File Format Description. LAS X Version 3.5.0.
Other implementations for reading Leica image files are readlif and Bio-Formats.
Examples¶
Read a FLIM lifetime image and metadata from a LIF file:
>>> with LifFile('tests/data/FLIM.lif') as lif:
... for image in lif.images:
... _ = image.name
... image = lif.images['Fast Flim'] # by name
... assert image.dtype == 'float16'
... assert image.sizes == {'Y': 1024, 'X': 1024}
... lifetimes = image.asxarray()
...
>>> lifetimes
<xarray.DataArray 'Fast Flim' (Y: 1024, X: 1024)> Size: 2MB
array([[...]],
shape=(1024, 1024), dtype=float16)
Coordinates:
* Y (Y) float64... 0.0005564
* X (X) float64... 0.0005564
Attributes...
path: FLIM_testdata.lif/sample1_slice1/FLIM Compressed/Fast Flim
UniqueID: 694efd02-95a9-436e-0fa6-f146120b1e15
F16: {'Name': 'F16',...
TileScanInfo: {'Tile': {'FieldX': 0,...
ViewerScaling: {'ChannelScalingInfo': {...
Iterate over selected XLEF image frames in ZTM dimension order:
>>> with LifFile('tests/data/XYZCST/XYZCST.xlef') as lif:
... image = lif.images[0] # by index
... image.sizes
... frames = image.frames(C=1, Z=slice(1, 3), T=[1, 0], M=None)
... frames.sizes
... for index, frame in frames.items():
... index, frame.shape
...
{'T': 2, 'M': 4, 'C': 3, 'Z': 5, 'Y': 1200, 'X': 1600}
{'Z': 2, 'T': 2, 'M': 4, 'Y': 1200, 'X': 1600}
((0, 0, 0), (1200, 1600))
((0, 0, 1), (1200, 1600))
...
((1, 1, 2), (1200, 1600))
((1, 1, 3), (1200, 1600))
View image and metadata in a LIF file from the console:
$ python -m liffile tests/data/FLIM.lif
License¶
Copyright (c) 2023-2026, Christoph Gohlke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
liffile module¶
- liffile.__version__ = '2026.4.11'¶
Liffile version string.
- final class liffile.LifFile(file, /, *, squeeze=True, mode=None, _parent=None)¶
Bases:
BinaryFileLeica image file (LIF, LOF, XLIF, XLEF, XLCF, or LIFEXT).
LifFileinstances are not thread-safe. All attributes are read-only.LifFileinstances must be closed withLifFile.close(), which is automatically called when using the ‘with’ context manager.- Parameters:
file (str | os.PathLike[Any] | IO[bytes]) – Name of Leica image file or seekable binary stream.
mode (Literal['r', 'r+'] | None) – File open mode if file is file name. The default is ‘r’. Files are always opened in binary mode.
squeeze (bool) – Remove dimensions of length one from images.
_parent (LifFile | None) – Parent file, if any.
- Raises:
LifFileError – File is not a Leica image file or is corrupted.
- __init__(file, /, *, squeeze=True, mode=None, _parent=None)¶
- Parameters:
file (str | os.PathLike[Any] | IO[bytes])
squeeze (bool)
mode (Literal['r', 'r+'] | None)
_parent (LifFile | None)
- Return type:
None
- type: LifFileType¶
Type of Leica image file.
- version: int¶
File version.
- uuid: str | None¶
Unique identifier of file, if any.
- memory_blocks: dict[str, LifMemoryBlock]¶
Object memory blocks.
- xml_element: ElementTree.Element¶
XML header root element.
- property datetime: datetime | None¶
File creation date from XML header.
- property images: LifImageSeries¶
Sequence of images in file.
- xml_header()¶
Return XML object description from file.
- Return type:
str
- close()¶
Close file handle and free resources.
- Return type:
None
- __str__()¶
Return str(self).
- Return type:
str
- class liffile.LifFileError¶
Bases:
ValueErrorException to indicate invalid Leica Image File structure.
- __weakref__¶
list of weak references to the object
- class liffile.LifFileType(*values)¶
Bases:
EnumLeica image file type.
- LIF = 'LIF'¶
Leica image file.
- LOF = 'LOF'¶
Leica object file containing single image.
- XLIF = 'XLIF'¶
XML file containing image metadata.
- XLEF = 'XLEF'¶
XML file containing experiment metadata.
- XLLF = 'XLLF'¶
XML file containing folder-view metadata.
- XLCF = 'XLCF'¶
XML file containing collection metadata.
- LIFEXT = 'LIFEXT'¶
File containing optional image data for LIF.
- final class liffile.LifFlimImage(parent, xml_element, path, /)¶
Bases:
LifImageABCFLIM/TCSPC histogram image.
Defined by XML Element with Data/SingleMoleculeDetection child.
- Parameters:
parent (LifFile)
xml_element (Element)
path (str)
- property dtype: numpy.dtype[Any]¶
Numpy data type of image array.
- property sizes: dict[str, int]¶
Map dimension names to lengths.
- property coords: dict[str, NDArray[Any]]¶
Mapping of image dimension names to coordinate variables.
- property attrs: dict[str, Any]¶
Image metadata from XML elements.
- property global_resolution: float¶
Resolution of time tags in s.
- property tcspc_resolution: float¶
Resolution of TCSPC in s.
- property number_bins_in_period: int¶
Delay time in one period.
- property pixel_time: float¶
Time per pixel in s.
- property frequency: float¶
Repetition frequency in MHz.
- property is_bidirectional: bool¶
Bidirectional scan mode.
- property is_sinusoidal: bool¶
Sinusoidal scan mode.
- asarray(*, dtype=None, frame=None, channel=None, dtime=None, out=None)¶
Return image data as array.
Dimensions are returned in order stored in file.
- Parameters:
dtype (DTypeLike | None) – Unsigned integer type of image histogram array. The default is
uint16. Increase the bit depth to avoid overflows when integrating.frame (int | None) – If < 0, integrate time axis, else return specified frame.
channel (int | None) – If < 0, integrate channel axis, else return specified channel.
dtime (int | None) – Specifies number of bins in image histogram. If 0, return
number_bins_in_periodbins. If < 0, integrate delay time axis. If > 0, return up to specified bin.out (OutputType) – Specifies where to copy image data. If
None, create a new NumPy array in main memory. If'memmap', create a memory-mapped array in a temporary file. If anumpy.ndarray, a writable, initialized array ofshapeanddtype. If afile nameoropen file, create a memory-mapped array in the specified file.
- Returns:
Image data as numpy array.
- Return type:
NDArray[Any]
- final class liffile.LifImage(parent, xml_element, path, /)¶
Bases:
LifImageABCRegular image.
Defined by XML Element with Data/Image child.
- Parameters:
parent (LifFile)
xml_element (Element)
path (str)
- property dtype: numpy.dtype[Any]¶
Numpy data type of image array.
- property sizes: dict[str, int]¶
Map dimension names to lengths.
- property coords: dict[str, NDArray[Any]]¶
Mapping of image dimension names to coordinate variables.
- property attrs: dict[str, Any]¶
Image metadata from XML elements.
- property timestamps: NDArray[numpy.datetime64] | None¶
Time stamps of frames from TimeStampList XML element, if any.
- property tilescan: LifTileScanInfo | None¶
Tile scan information from TileScanInfo XML element, if any.
- frame(*, out=None, **indices)¶
Return single frame from image.
A frame consists of the innermost two contiguous dimensions (typically Y and X) and an optional sample dimension (S for RGB).
- Parameters:
out (OutputType) – Specifies where to copy frame data. If
None, create a new NumPy array in main memory. If'memmap', create a memory-mapped array in a temporary file. If anumpy.ndarray, a writable, initialized array of compatible shape and dtype. If afile nameoropen file, create a memory-mapped array in the specified file.**indices (int) – Global dimension indices using case-sensitive dimension codes. Unspecified dimensions default to index 0. Example:
C=1, Z=2, T=0for channel 1, Z-plane 2, time 0.
- Returns:
Frame data as numpy array.
- Raises:
KeyError – If unknown dimension specified.
IndexError – If index is out of bounds.
- Return type:
NDArray[Any]
- property frames: LifImageFrames¶
Interface for accessing individual image frames.
The
LifImageFramesinstance provides a mapping and sequence-like interface for memory-efficient, frame-level access to higher dimensional image data with per-dimension selection.Examples
Access single frame using global indices:
frame = image.frames[0] # first frame frame = image.frame(C=1, Z=2, T=0) # specific indices
Create selection and iterate:
selected = image.frames(C=1, Z=slice(1, 3)) for index, frame in selected.items(): process(frame)
- asarray(*, mode='r', out=None)¶
Return image data as array.
Dimensions are returned in order stored in file.
- Parameters:
mode (str) – Memmap file open mode. The default is read-only.
out (OutputType) – Specifies where to copy image data. If
None, create a new NumPy array in main memory. If'memmap', directly memory-map the image data in the file if possible; else create a memory-mapped array in a temporary file. If anumpy.ndarray, a writable, initialized array ofshapeanddtype. If afile nameoropen file, create a memory-mapped array in the specified file.
- Returns:
Image data as numpy array. RGB samples may not be contiguous.
- Return type:
NDArray[Any]
Notes
For advanced use cases, use the
framesinterface, which supports per-dimension selections, heterogeneous channel data types, and discontiguous storage.
- class liffile.LifImageABC(parent, xml_element, path, /)¶
Bases:
ABCBase class for
LifImageandLifFlimImage.All attributes are read-only.
- Parameters:
parent (LifFile) – Underlying LIF file.
xml_element (Element) – XML element of image.
path (str) – Path of image in image tree.
Notes
LIF images may have the following dimensions in almost any order:
'H': TCSPC histogram'S': Sample/color component'C': Channel'X': Width'Y': Height'Z': Depth'T': Time'λ': Emission wavelength'A': Rotation'N': XT slices'Q': T slices'Λ': Excitation wavelength'M': Mosaic ('S'in LAS X)'L': Loop
- __init__(parent, xml_element, path, /)¶
- Parameters:
parent (LifFile)
xml_element (Element)
path (str)
- Return type:
None
- xml_element: Element¶
XML element of image.
- path: str¶
Path of image in image tree.
- property is_flim: bool¶
Image contains FLIM/TCSPC histogram.
- property name: str¶
Name of image.
- property uuid: str | None¶
Unique identifier of image, if any.
- property dtype: numpy.dtype[Any]¶
Numpy data type of image array.
- property sizes: dict[str, int]¶
Map dimension names to lengths.
- property shape: tuple[int, ...]¶
Shape of image.
- property dims: tuple[str, ...]¶
Character codes of dimensions in image.
- property ndim: int¶
Number of image dimensions.
- property nbytes: int¶
Number of bytes consumed by image.
- property size: int¶
Number of elements in image.
- property itemsize: int¶
Length of one array element in bytes.
- property frames: LifImageFrames¶
Interface for accessing individual image frames.
- property coords: dict[str, NDArray[Any]]¶
Mapping of image dimension names to coordinate variables.
- property attrs: dict[str, Any]¶
Image metadata from XML elements.
- property parent_image: LifImageABC | None¶
Parent image, if any.
- property child_images: tuple[LifImageABC, ...]¶
Child images.
- property memory_block: LifMemoryBlock¶
Memory block containing image data.
- property timestamps: NDArray[numpy.datetime64] | None¶
Time stamps of frames from TimeStampList XML element, if any.
- property tilescan: LifTileScanInfo | None¶
Tile scan information from TileScanInfo XML element, if any.
- abstractmethod asarray(*, out=None)¶
Return image data as array.
Dimensions are returned in order stored in file.
- Parameters:
out (OutputType) – Specifies where to copy image data. If
None, create a new NumPy array in main memory. If'memmap', directly memory-map the image data in the file if possible; else create a memory-mapped array in a temporary file. If anumpy.ndarray, a writable, initialized array ofshapeanddtype. If afile nameoropen file, create a memory-mapped array in the specified file.- Returns:
Image data as numpy array.
- Return type:
NDArray[Any]
- asxarray(**kwargs)¶
Return image data as xarray.
Dimensions are returned in order stored in file.
- Parameters:
**kwargs (Any) – Optional arguments to
asarray().- Returns:
Image data and select metadata as xarray DataArray.
- Return type:
DataArray
- __repr__()¶
Return repr(self).
- Return type:
str
- __str__()¶
Return str(self).
- Return type:
str
- __weakref__¶
list of weak references to the object
- final class liffile.LifImageFrames(image, /, **selection)¶
Bases:
objectInterface for accessing individual image frames in LifImage.
A mapping and sequence-like interface providing memory-efficient, frame-level access to higher dimensional image data with per-dimension selection.
A frame consists of the innermost two contiguous dimensions of the image (typically Y and X) and an optional sample dimension (S for RGB).
Instances are usually obtained via the
LifImage.framesproperty.- Parameters:
image (LifImage) – Parent LifImage instance.
**selection (SelectionValue) –
Per-dimension selection using case-sensitive codes.
int: Fixed index (dimension not iterated).slice: Range of indices to iterate.Sequence[int]: Specific indices to iterate.None: Iterate all indices.
- Raises:
KeyError – If unknown dimension specified.
ValueError – If frame dimension (for example, Y, X, S) specified.
- __init__(image, /, **selection)¶
- Parameters:
image (LifImage)
selection (SelectionValue)
- Return type:
None
- __call__(**selection)¶
Create new instance with selection.
- Parameters:
**selection (SelectionValue) –
Per-dimension selection using case-sensitive codes.
int: Fixed index (dimension not iterated).slice: Range of indices to iterate.Sequence[int]: Specific indices to iterate.None: Iterate all indices.
- Returns:
New LifImageFrames instance.
- Raises:
ValueError – If called on instance with existing selection.
- Return type:
- property frame_sizes: dict[str, int]¶
Dimension sizes of single frame.
- property frame_shape: tuple[int, ...]¶
Shape of single frame.
- property frame_dims: tuple[str, ...]¶
Dimension names of single frame.
- property sizes: dict[str, int]¶
Map dimension names to lengths.
Including selected and frame dimensions.
- property shape: tuple[int, ...]¶
Shape including selected and frame dimensions.
- property dims: tuple[str, ...]¶
Dimension names including selected and frame dimensions.
- property ndim: int¶
Number of dimensions including selected and frame dimensions.
- property dtype: numpy.dtype[Any]¶
Data type resulting from NumPy type promotion rules.
- property coords: dict[str, NDArray[Any]]¶
Physical coordinates for selected and frame dimensions.
- keys()¶
Return iterator over ND indices (tuples).
- Yields:
ND index tuples for each frame in the selection.
- Return type:
Iterator[tuple[int, …]]
- values()¶
Return iterator over frames.
Equivalent to iterating over the sequence directly.
- Yields:
Frame data as numpy arrays.
- Return type:
Iterator[NDArray[Any]]
- items()¶
Return iterator over (ND index, frame) pairs.
- Yields:
Tuples of (index, frame) where index is an ND tuple and frame is the corresponding numpy array.
- Return type:
Iterator[tuple[tuple[int, …], NDArray[Any]]]
- get(key, default=None)¶
Return frame by local index, with default.
- Parameters:
key (int | tuple[int, ...]) – Linear index (int) or ND index (tuple).
default (NDArray[Any] | None) – Value to return if key not found.
- Returns:
Frame data or default.
- Return type:
NDArray[Any] | None
- asarray(*, out=None)¶
Return selected frames as single array.
- asxarray(**kwargs)¶
Return selected frames as xarray.
- Parameters:
**kwargs (Any) – Optional arguments to
asarray().- Returns:
Image data and metadata of selected frames as xarray DataArray.
- Return type:
DataArray
- unravel_index(linear_index, /, *, global_=False)¶
Convert linear index to ND index.
- Parameters:
linear_index (int) – Linear index (0 to len-1).
global – If True, return global (absolute) indices. If False, return local (selection-relative) indices.
global_ (bool)
- Returns:
ND index as tuple, excluding frame dimensions.
- Raises:
IndexError – If linear_index is out of bounds.
- Return type:
tuple[int, …]
- ravel_multi_index(nd_index, /, *, global_=False)¶
Convert ND index to linear index.
- Parameters:
nd_index (tuple[int, ...]) – ND index as tuple, excluding frame dimensions.
global – If True, nd_index contains global (absolute) indices. If False, nd_index contains local (selection-relative) indices.
global_ (bool)
- Returns:
Linear index.
- Raises:
ValueError – If nd_index has wrong length.
IndexError – If any index is out of bounds.
- Return type:
int
- __getitem__(key, /)¶
Get frame by local index.
- Parameters:
key (int | tuple[int, ...]) – Linear index (int) or ND index (tuple of int).
- Returns:
Frame data as numpy array.
- Raises:
IndexError – If key is out of bounds.
TypeError – If key has wrong type.
- Return type:
NDArray[Any]
- __len__()¶
Number of frames in selection.
- Return type:
int
- __iter__()¶
Iterate over selected frames.
- Return type:
Iterator[NDArray[Any]]
- __repr__()¶
Return repr(self).
- Return type:
str
- __weakref__¶
list of weak references to the object
- final class liffile.LifImageSeries(parent, /)¶
Bases:
Sequence[LifImageABC]Sequence of images in Leica image file.
- Parameters:
parent (LifFile)
- find(key, /, *, attr='path', flags=re.IGNORECASE, default=None)¶
Return first image with matching attribute pattern, if any.
- Parameters:
key (str) – Regular expression pattern to match str of LifImage attribute.
attr (str) – LifImage attribute to match against (default: ‘path’).
flags (int) – Regular expression flags.
default (Any) – Value to return if no image with matching attribute found.
- Return type:
LifImageABC | None
- findall(key, /, *, attr='path', flags=re.IGNORECASE)¶
Return all images with matching attribute pattern.
- Parameters:
key (str) – Regular expression pattern to match str of LifImage attribute.
attr (str) – LifImage attribute to match against (default: ‘path’).
flags (int) – Regular expression flags.
- Return type:
tuple[LifImageABC, …]
- __getitem__(key, /)¶
Return image at index or first image with path matching pattern.
- Raises:
IndexError – if integer index out of range.
KeyError – if no image with matching path pattern found.
- Parameters:
key (int | str)
- Return type:
- __repr__()¶
Return repr(self).
- Return type:
str
- __str__()¶
Return str(self).
- Return type:
str
- final class liffile.LifMemoryBlock(parent, /)¶
Bases:
objectObject memory block.
- Parameters:
parent (LifFile) – Underlying LIF file.
- frames: tuple[LifMemoryFrame, ...]¶
Frames in memory block.
- type: LifMemoryBlockType¶
Memory block type.
- id: str¶
Identity of memory block.
- offset: int¶
Byte offset of memory block in file.
- size: int¶
Size of memory block in bytes.
- read()¶
Return memory block from file.
- Return type:
bytes
- readinto(buffer, /)¶
Read memory block from file into contiguous ndarray.
- Parameters:
buffer (NDArray[Any])
- Return type:
None
- read_array(shape, dtype, *, mode='r', out=None)¶
Return NumPy array from file.
- Parameters:
shape (tuple[int, ...]) – Shape of array to read.
dtype (DTypeLike) – Data type of array to read.
mode (str) – Memmap file open mode. The default is read-only.
out (OutputType) – Specifies where to copy image data. If
None, create a new NumPy array in main memory. If'memmap', directly memory-map the image data in the file if possible; else create a memory-mapped array in a temporary file. If anumpy.ndarray, a writable, initialized array of shape and dtype. If afile nameoropen file, create a memory-mapped array in the specified file.
- Return type:
NDArray[Any]
- __repr__()¶
Return repr(self).
- Return type:
str
- class liffile.LifMemoryBlockType(*values)¶
Bases:
IntEnumLeica image file memory block type.
- UNKNOWN = -1¶
Unknown memory block type.
- MEM = 0¶
Memory block embedded in LIF.
- LOF = 1¶
Memory block in single LOF file.
- TIF = 2¶
Memory blocks in TIF files.
- OME = 3¶
Memory blocks in OME TIF files.
- AIVIA = 4¶
Memory blocks in Aivia TIF files.
- JPG = 5¶
Memory blocks in JPG files.
- PNG = 6¶
Memory blocks in PNG files.
- BMP = 7¶
Memory blocks in BMP files.
- __format__(format_spec, /)¶
Convert to a string according to format_spec.
- __new__(value)¶
- class liffile.LifTileScanInfo(flip_x, flip_y, swap_xy, tiles)¶
Bases:
objectTile scan information from TileScanInfo XML element.
- Parameters:
flip_x (bool)
flip_y (bool)
swap_xy (bool)
tiles (NDArray[numpy.void])
- __delattr__(name)¶
Implement delattr(self, name).
- __eq__(other)¶
Return self==value.
- __getstate__()¶
Helper for pickle.
- __hash__()¶
Return hash(self).
- __init__(flip_x, flip_y, swap_xy, tiles)¶
- Parameters:
flip_x (bool)
flip_y (bool)
swap_xy (bool)
tiles (NDArray[numpy.void])
- Return type:
None
- __repr__()¶
Return repr(self).
- __setattr__(name, value)¶
Implement setattr(self, name, value).
- flip_x: bool¶
X stage direction is flipped.
- flip_y: bool¶
Y stage direction is flipped.
- swap_xy: bool¶
XY dimensions are swapped.
- tiles: NDArray[numpy.void]¶
field_y, field_x, pos_z, pos_y, pos_x.
- Type:
Tile indices and positions
- __len__()¶
Return number of tiles.
- Return type:
int
- __getitem__(key)¶
Return field indices and positions.
- Parameters:
key (int | str)
- Return type:
NDArray[Any]
- liffile.imread(file: str | os.PathLike[Any] | IO[bytes], /, image: int | str = 0, *, selection: SelectionType | None = None, squeeze: bool = True, asxarray: Literal[False] = False, out: OutputType = None, **kwargs: Any) NDArray[Any]¶
- liffile.imread(file: str | os.PathLike[Any] | IO[bytes], /, image: int | str = 0, *, selection: SelectionType | None = None, squeeze: bool = True, asxarray: Literal[True] = False, out: OutputType = None, **kwargs: Any) DataArray
Return image from file.
Dimensions are returned in order stored in file.
- Parameters:
file (str | os.PathLike[Any] | IO[bytes]) – Name of Leica image file or seekable binary stream.
image (int | str) – Index or name of image to return. By default, the first image in the file is returned.
selection (SelectionType | None) –
Per-dimension selection using case-sensitive dimension codes. If
None, return entire image. Otherwise, a dict mapping dimension names to selection values:int: Fixed index.slice: Range of indices.Sequence[int]: Specific indices.None: All indices.
Not supported with RAW FLIM images.
squeeze (bool) – Remove dimensions of length one from images.
asxarray (bool) – Return image data as xarray.DataArray instead of numpy.ndarray.
out (OutputType) – Specifies where to copy image data. If
None, create a new NumPy array in main memory. If'memmap', directly memory-map the image data in the file. If anumpy.ndarray, a writable, initialized array of compatible shape and dtype. If afile nameoropen file, create a memory-mapped array in the specified file.**kwargs (Any) – Optional arguments to
LifImageABC.asarray(),LifImageABC.asxarray(), orLifImage.frames().
- Returns:
Image data as numpy array or xarray DataArray.
- Return type:
NDArray[Any] | DataArray
- liffile.xml2dict(xml_element, /, *, sanitize=True, prefix=None, exclude=None, sep=',')¶
Return XML as dictionary.
- Parameters:
xml_element (ElementTree.Element) – XML element to convert.
sanitize (bool) – Remove prefix from etree Element.
prefix (tuple[str, str] | None) – Prefixes for dictionary keys.
exclude (Container[str] | None) – Ignore element tags.
sep (str) – Sequence separator.
- Returns:
Dictionary representation of XML element.
- Return type:
dict
- liffile.FILE_EXTENSIONS¶