Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open czi line-scan kymographs - missing raw frame(t) pixel data #31

Open
cudmore opened this issue Dec 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@cudmore
Copy link

cudmore commented Dec 13, 2023

First, thanks for working on this critical package. I understand and appreciate how complex opening proprietary binary file formats can be. I followed the package from aicsimageio to its new home at bioio and am excited to get this working!

Describe the Bug

I would like to open 'line scan' czi files using bioio. When I do this, some image data is missing, it does not include the correct number of frames(t). In both cases below, I get only one (1) frame whereas I expect 1000 and 10000 in my two example files (see below).

Background. Lines scans are where you perform, well, a line scan over and over. With something like 1000 or 10000 repeated scans of a line. You then make a 2D image of all the pixel data by constructing a 2D image where each line scan is one row in the image. What results is referred to as a kymograph or space/time image. For example, each line scan might be 1024 pixels and it is repeatedly acquired 1000 times. You then make a kymograph image from all the raw pixel data and it has a pixel size/shape of 1000 x 1024 (or visa-versa).

Problem is, when I open with bioio, I am only getting one line-scan, e.g. one frame(t), rather than the expected 1000 or 10000.

Expected Behavior

I would expect all the raw pixel data would be available and it is not. It seems to be missing frames(t), with 1 when I expect 1000 or 1000

Reproduction

Here are two sample files

  • CO2.czi with 512 pixels per line and 10000 repeated line scans.
  • Image 14.czi with 1024 pixels per line and 1000 repeated line scans.

In this example, bioio got the pixels per line correct (e.g. 1024) but there is no raw pixel data corresponding to the repeated line-scans. In all case frames(T) is just 1. I expect some dimension to represent the repeated line scans, e.g. 1000.

import os
from bioio import BioImage
#from aicspylibczi import CziFile  # tried this too but same bug/behavior

path = 'path/to/my/example/file/Image 14.czi'
print(f'loading {os.path.split(path)[1]}')

img = BioImage(path)

print('img.data.shape:', img.data.shape)  # (1, 2, 1, 1, 1024)

print('=== xarray_data:')
print(img.xarray_data)  # <xarray.DataArray (T: 1, C: 2, Z: 1, Y: 1, X: 1024)>

print('dims:', img.dims)  # <Dimensions [T: 1, C: 2, Z: 1, Y: 1, X: 1024]>
print('dims.order:', img.dims.order)  # TCZYX
print('dims.X:', img.dims.X)  # 1024
print('dims.Y:', img.dims.Y)  # 1
print('dims.T:', img.dims.T)  # 1
print('img.shape:', img.shape)  # (1, 2, 1, 1, 1024)

# returns the X dimension pixel size as found in the metadata
print('physical_pixel_sizes.X:', img.physical_pixel_sizes.X) 

Results in this output

loading Image 14.czi
img.data.shape: (1, 2, 1, 1, 1024)
=== xarray_data:
<xarray.DataArray (T: 1, C: 2, Z: 1, Y: 1, X: 1024)>
array([[[[[ 0,  0,  0, ...,  0,  0,  0]]],
        [[[39, 66,  0, ...,  0,  0,  0]]]]], dtype=uint8)
Coordinates:
  * C        (C) <U6 'NDD R1' 'NDD R4'
  * Z        (Z) float64 0.0
  * Y        (Y) float64 0.0
  * X        (X) float64 0.0 0.06599 0.132 0.198 ... 67.31 67.37 67.44 67.5
Dimensions without coordinates: T
Attributes:
    unprocessed:  <Element 'ImageDocument' at 0x14fe8ae80>
dims: <Dimensions [T: 1, C: 2, Z: 1, Y: 1, X: 1024]>
dims.order: TCZYX
dims.X: 1024
dims.Y: 1
dims.T: 1
img.shape: (1, 2, 1, 1, 1024)

physical_pixel_sizes.X: 0.06598669529504321

Ideas

Idea 1) There are recent updates from Zeiss on a different/newer package called pylibCZIrw

I see bioio is using aicspylibczi which is a fork of elhuhdron/pylibczi.

I also see another version of pylibczi coming directly from zeiss (no github) but can download source from PyPi pylibCZIrw. This has very recent updates (Dec 4, 2023). I am not able to install this because I haven't been able to build the wheels on a macOS machine with apple silicon (M2) CPU (afaik). The email contact there is [email protected].

Idea 2) I can open these czi files using Fiji/Bio-Formats importer and get all the pixel data

Fiji environment is

Fiji: 2.14.0/1.54f (2023-07-07)
Bio-Formats Plugins for ImageJ 7.0.1 (2023-10-16)

File image 14.czi
Each line (image) is (1024, 1)
Channels (c): 2
Slices(z): 1
Frames(t): 1000
physical pixel size: 0.066

manually saved as tif and openend with tifffile yields a good shape of (1000, 1, 1024)

File CO2.czi

Each line (image) is (512,1)
Channels (c): 2
Slices(z): 1
Frames(t): 10000
physical pixel size: 0.0175789

manually saved as tif and openend with tifffile yields a good shape of (10000, 1, 512)

Environment

macOS 13.3.1 (a)
Python 3.11.5
bioio 1.0.1.dev2+gf594aa5
bioio-base 1.0.1.dev1+g1003511
bioio-czi 1.0.1.dev0+gcb2ed27.d20231212

p.s. I am actually using the bioio branch `fix/resolution-level from a recent issue and pull request.

@cudmore cudmore added the bug Something isn't working label Dec 13, 2023
@toloudis
Copy link
Contributor

Thank you for the thorough issue writeup!! And thanks for trying bioio so early. #30 has now been merged to main.
We'll look into this CZI issue but many people are on vacation soon so it may not be till 2024. Also we might want to move this ticket into bioio-czi since it may be specific to that reader.

Making a new czi reader to use pylibCZIrw is a longer project which we won't take on in the near term. More likely we can see if there are changes to aicspylibczi that would fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants