Skip to content

Single time point exported from time series appears to have as many frames as original #53

@jni

Description

@jni

I have an nd2 from a collaborator that contains a single frame out of a longer time series. When I open it with nd2reader, it appears to have 193 time points, as the original time series did. However when I try to access any frame other than [0] I (understandably) get a KeyError. Is there any way for me to introspect this file to know that there is only one time frame within it?

example file

Script to reproduce the issue with the provided file:

from nd2reader import ND2Reader

f = ND2Reader('train_TR67_Inj7_fr50.nd2')
f.bundle_axes = 'zyx'
print(f'{len(f)=}')  # 193
print(f'{f.iter_axes=}')  # 't'
print(f'{f.sizes=}')  # 193 time points
print(f'{f[0].shape=}')  # 33 x 512 x 512
print(f'{f.frame_shape=}')  # 33 x 512 x 512
print(f'{f[1].shape=}')  # KeyError

Output on current master:

len(f)=193
f.iter_axes=['t']
f.sizes={'x': 512, 'y': 512, 'c': 4, 't': 193, 'z': 33}
f[0].shape=(33, 512, 512)
f.frame_shape=(33, 512, 512)
Traceback (most recent call last):
  File "/Users/jni/projects/useful-histories/nd2-single-frame.py", line 10, in <module>
    print(f'{f[1].shape=}')  # KeyError
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/slicerator/__init__.py", line 188, in __getitem__
    return self._get(indices)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/pims/base_frames.py", line 98, in __getitem__
    return self.get_frame(key)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/pims/base_frames.py", line 592, in get_frame
    result = self._get_frame_wrapped(**coords)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/pims/base_frames.py", line 265, in get_frame_bundled
    frame = get_frame(**ind)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/pims/base_frames.py", line 303, in get_frame_dropped
    result = get_frame(**ind)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/nd2reader/reader.py", line 88, in get_frame_2D
    return self._parser.get_image_by_attributes(t, v, c, z, y, x)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/nd2reader/parser.py", line 103, in get_image_by_attributes
    timestamp, raw_image_data = self._get_raw_image_data(image_group_number, channel,
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/nd2reader/parser.py", line 261, in _get_raw_image_data
    chunk = self._label_map.get_image_data_location(image_group_number)
  File "/Users/jni/conda/envs/napari-proofreading/lib/python3.9/site-packages/nd2reader/label_map.py", line 80, in get_image_data_location
    return self._image_data[index]
KeyError: 33

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions