uwmadison-chm / bioread

Utilities to work with files from BIOPAC's AcqKnowlege software
MIT License
65 stars 23 forks source link

error: unpack requires a buffer of 154 bytes #22

Closed ZhuYuqicheng closed 4 years ago

ZhuYuqicheng commented 5 years ago

Hallo,

I can't read *.acq with bioread.

Code: import bioread

data = bioread.read_file('demo.acq')

Traceback: Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/ZYH7ABT/Desktop/4_Koretz/converter.py', wdir='C:/Users/ZYH7ABT/Desktop/4_Koretz')

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/ZYH7ABT/Desktop/4_Koretz/converter.py", line 10, in data = bioread.read_file('demo.acq')

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread__init__.py", line 26, in read return reader.Reader.read(filelike, channel_indexes).datafile

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\reader.py", line 74, in read reader._read_headers()

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\reader.py", line 114, in _read_headers ch_start, ChannelHeader)

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\reader.py", line 219, in __multi_headers h.unpack_from_file(self.acq_file, h_offset)

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\headers.py", line 33, in unpack_from_file self.__unpack_data()

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\headers.py", line 47, in __unpack_data self.data = self.struct_dict.unpack(self.raw_data)

File "C:\Users\ZYH7ABT\AppData\Local\conda\conda\envs\auswerten\lib\site-packages\bioread\struct_dict.py", line 54, in unpack unpacked = struct.unpack(self.format_string, data)

error: unpack requires a buffer of 154 bytes

njvack commented 5 years ago

Thanks for the bug report — is there any chance you can post the .acq file so I can take a look at it?

DominiqueMakowski commented 4 years ago

@ZhuYuqicheng This error happened to me just now when I downloaded an acqknowledge file from gihtub using right-click -> save as. In fact the size of the acq file was super small (and thus likely not complete). When I redownloaded the file by clicking on it and then clicking on "view raw", I downloaded a bigger file and managed to read it.

njvack commented 4 years ago

Yes, if you have incomplete .acq data, you'll see errors like this. Error handling in bioread could be better, though I don't always know if it's the code or the data that has the problem — incorrectly reading a length on a valid file can cause Bioread to try and read beyond the end of the file, for example.

If you have a file that opens in AcqKnowledge but not in Bioread and can share it, feel free to upload it and reopen this ticket. For now, I'm gonna close it.