mhe / pynrrd

Simple pure-python module for reading and writing nrrd files.
https://pynrrd.readthedocs.io/
MIT License
116 stars 51 forks source link

Impossible to read data #66

Closed scholi closed 6 years ago

scholi commented 6 years ago

I have some data GaAs. Saving them in nrrd format works, but I cannot restore them properly!

import nrrd
import numpy as np
GaAs = np.random.randint(0,255,(264, 104, 123), dtype=np.uint8)
print(type(GaAs), GaAs.shape)
nrrd.write("A.nrrd", GaAs)
nrrd.read("A.nrrd")

<class 'numpy.ndarray'> (264, 104, 123)

error Traceback (most recent call last)

in () 2 print(type(GaAs), GaAs.shape) 3 nrrd.write("A.nrrd", GaAs) ----> 4 nrrd.read("A.nrrd") c:\users\ols\appdata\local\programs\python\python36\lib\site-packages\nrrd.py in read(filename) 390 with open(filename,'rb') as filehandle: 391 header = read_header(filehandle) --> 392 data = read_data(header, filehandle, filename) 393 return (data, header) 394 c:\users\ols\appdata\local\programs\python\python36\lib\site-packages\nrrd.py in read_data(fields, filehandle, filename, seek_past_header) 278 if not chunk: 279 break --> 280 decompressed_data += decompobj.decompress(chunk) 281 # byteskip applies to the _decompressed_ byte stream 282 data = np.fromstring(decompressed_data[byteskip:], dtype) error: Error -3 while decompressing data: incorrect data check

Am I doing something wrong or is this a bug with the library?

Thank you for your help and kind regards

addisonElliott commented 6 years ago

Just tested on my machine and your code ran fine to me. So I'm not entirely sure what the issue may be.

Here is the checksum for my A.nrrd file:

CRC32: FCEA06F2
CRC64: 9DBD195614BEA86E
SHA256: 416D87BB4A97C6C5D0990D3F60218EDE33A155EE0029B9FB9F4E68727D12D1C4
SHA1: 653AE35266C67D7E161DB98507B6687F1C275FFA

Here is a link to my A.nrrd. You can download it and do a diff if you want to see if there are any differences. https://addielli.com/A.nrrd

I did this on Windows 10 using Python 3.5.4. If you're on Linux, the line-endings are probably different and there will be differences there. (In which case the checksum will be different).

Once we can confirm that your writing process is the same, meaning my A.nrrd and your A.nrrd have the same data, then we should move on to your reading process. Since it's essentially using the zlib library in Python, I'm not sure it's any bug in the library but we can work on what the issue may be.

Can you give me more information on your machine: OS, Python version, library version (hopefully 0.3.2), etc.

In addition, here are some things to try to further debug the issue:

scholi commented 6 years ago

I have just noticed that I had an outdated version (v 0.2.1). It works fine with 0.3.2 I'm even able to read file that was written with the previous version. Still not sure why the old version couldn't open certain files correctly...

Anyway thank you for your help