tlambert03 / nd2

Full-featured nd2 (Nikon NIS Elements) file reader for python. Outputs to numpy, dask, and xarray. Exhaustive metadata extraction
https://tlambert03.github.io/nd2
BSD 3-Clause "New" or "Revised" License
53 stars 15 forks source link

ND2 files saved with lossless compression do not open correctly. #72

Closed kthorn closed 2 years ago

kthorn commented 2 years ago

Description

Files acquired by NIS Elements JOBS can be saved as ND2 files with either no compression or lossless compression. When saved with no compression, the nd2 library opens these files correctly. When saved with lossless compression, nd2 returns incorrect data.

What I Did

I acquired two images of background (no sample) using JOBS, with and without saving with compression. You can see the results below - the version with no compression returns values close to 100 as expected for a background image; the version with compression returns nonsense values.

dir = r'C:\Users\kthorn\ArrePath, Inc\ArrePath Science - Documents\Imaging experiments\062322 Format Tests/'
with nd2.ND2File(dir+'NoCompression.nd2') as nd2_file:
    nd2_image = nd2_file.asarray()
    imdims = nd2_image.shape

nd2_image[1,0,0:10,0]
array([124, 108, 131, 113, 148, 131, 120, 127, 121, 129], dtype=uint16)

with nd2.ND2File(dir+'LosslessCompression.nd2') as nd2_file:
    nd2_image = nd2_file.asarray()
    imdims = nd2_image.shape

nd2_image[1,0,0:10,0]
with nd2.ND2File(dir+'LosslessCompression.nd2') as nd2_file:
    nd2_image = nd2_file.asarray()
    imdims = nd2_image.shape

nd2_image[1,0,0:10,0]
with nd2.ND2File(dir+'LosslessCompression.nd2') as nd2_file:
    nd2_image = nd2_file.asarray()
    imdims = nd2_image.shape
​
nd2_image[1,0,0:10,0]
array([40056, 11979, 13782, 37643,  2349, 20231,  1135, 16315, 57624,
       54800], dtype=uint16)

I can provide the example files that reproduce this problem.

tlambert03 commented 2 years ago

howdie @kthorn! yeah some files would be great. I suspect this will be pretty easy to fix

kthorn commented 2 years ago

Want me to just send them to your email (they're <1MB)? I don't have a good place to host them.

tlambert03 commented 2 years ago

yep that works great.

tlambert03 commented 2 years ago

should be fixed in main. Just pushed a new release tag, should be built and on pypi in an hour or so