Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

LifImage.as_array() fails for 4D image #59

Description

@lanery

Main issue

Trying to load a 4D (X, Y, Λ, t) LIF image as a numpy array failed.

Code that produced the issue

The file in question is 6 GB, so it's too large to upload here, but it was read in via:

from pathlib import Path
from readlif.reader import LifFile

lif_file = LifFile("filepath/to/4d_image.lif")
lif_image = lif_file.get_image_by_name("Lambda_time_series")

Check the number of "planes" in each dimension:

>>> lif_image.dims_n
{1: 512, 2: 512, 9: 60, 4: 99}

Try to get image data as a numpy array:

>>> lif_image.as_array()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[70], line 1
----> 1 lif_image.as_array()

File ~/Repositories/readlif/readlif/reader.py:484, in LifImage.as_array(self, dims)
    479 # multichannel image -- get planes recursively for each dimension
    480 array = [
    481     [self.get_plane(requested_dims={dim: i}) for i in range(self.dims_n[dim])]
    482     for dim in dims
    483 ]
--> 484 return np.array(array).squeeze()

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

It fails because the as_array() method does not properly iterate over multiple dimensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions