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

Error loading nd2 from N-SIM #39

Closed dpshepherd closed 2 years ago

dpshepherd commented 2 years ago

Description

Load N-SIM data stored in nd2 file. The data is interesting, all of the angles/phases for a channel are in one image when I load via bioformats. I'm not sure if the nd2 sdk is trying to crop these into individual images?

What I Did

Try to load data using

import nd2
import numpy as np

my_array = nd2.imread('test_sim.nd2')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-14-d50f1da17a57>](https://localhost:8080/#) in <module>()
----> 1 my_array = nd2.imread('test_sim.nd2')

3 frames
[/usr/local/lib/python3.7/dist-packages/nd2/_sdk/__init__.py](https://localhost:8080/#) in <module>()
----> 1 from . import latest
      2 
      3 __all__ = ["latest"]

src/nd2/_sdk/latest.pyx in init nd2._sdk.latest()

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
dpshepherd commented 2 years ago

I can send a link to example via email if helpful.

tlambert03 commented 2 years ago

A link would be great. I do actually have a couple examples of sim data in my test suite, so if you have a failing example that'd be helpful

dpshepherd commented 2 years ago

Emailed!

tlambert03 commented 2 years ago

ok, it worked for me:

In [3]: nd2.imread('/Users/talley/Downloads/test_sim.nd2').shape
Out[3]: (3, 3072, 3072)

so it must have something to do with environment (and... I should have looked earlier, the line numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject indicates as much). This library is compiled with cython, so does require a specific numpy abi, and it's likely that i need to do a better job declaring that in my dependencies.

can you tell me your numpy version and preferably installation method?

tlambert03 commented 2 years ago

also, just curious, is this the first file you tried? i.e. have any files worked for you?

dpshepherd commented 2 years ago

On my laptop, nd2 loads this image and other images just fine.

I am hoping to also use this on Google Colab as part of tutorial, which is where I ran into this error. I haven't tried loading any other images on Colab.

Installation method: pip install nd2 Numpy version: 1.19.5

dpshepherd commented 2 years ago

Ok, upgrading numpy worked! Thanks!

Should of thought of that myself...

tlambert03 commented 2 years ago

good to know that that's how that error will manifest :) thanks for posting