MouseLand / suite2p

cell detection in calcium imaging recordings
http://www.suite2p.org
GNU General Public License v3.0
334 stars 239 forks source link

BUG: An error occurred while trying to save to mat by using GUI #1026

Closed chunyueli closed 8 months ago

chunyueli commented 11 months ago

Describe the issue:

An error occurred while trying to save to mat by using GUI

Reproduce the code example:

click GUI

Error message:

saving to mat
Traceback (most recent call last):
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/gui/menus.py", line 48, in <lambda>
    parent.saveMat.triggered.connect(lambda: io.save_mat(parent))
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/gui/io.py", line 427, in save_mat
    scipy.io.savemat(
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio.py", line 300, in savemat
    MW.put_variables(mdict)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 892, in put_variables
    self._matrix_writer.write_top(var, name.encode('latin1'), is_global)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 633, in write_top
    self.write(arr)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 662, in write
    self.write_struct(narr)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 781, in write_struct
    self._write_items(arr)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 798, in _write_items
    self.write(el[f])
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 651, in write
    narr = to_writeable(arr)
  File "/home/chunyue/anaconda3/envs/suite2p/lib/python3.8/site-packages/scipy/io/matlab/_mio5.py", line 493, in to_writeable
    narr = np.asanyarray(source)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

Version information:

suite2p 0.14.2

Context for the issue:

system:ubuntu 22.04

chriski777 commented 8 months ago

Hi @chunyueli, sorry for the late response. I'm unable to reproduce this error on an Ubuntu 22.04 machine. Can you try re-installing the latest version of suite2p and make sure that your scipy version is greater than 1.9.0? I'll close this for now but feel free to reopen if the issue persists!

wisamreid commented 6 months ago

I am also experiencing this error. Has there been any resolution for this?

I just updated to the latest version of suite2p to no avail. My scipy version is 1.10.1 I am running on Windows 10

Mysteriously, this only fails on one of my data blocks and not others.

Here is my stack trace:

saving to mat
Traceback (most recent call last):
  File "C:\Users\reidw\Documents\Github\suite2p\suite2p\gui\menus.py", line 48, in <lambda>
    parent.saveMat.triggered.connect(lambda: io.save_mat(parent))
  File "C:\Users\reidw\Documents\Github\suite2p\suite2p\gui\io.py", line 428, in save_mat
    scipy.io.savemat(
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio.py", line 300, in savemat
    MW.put_variables(mdict)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 892, in put_variables
    self._matrix_writer.write_top(var, name.encode('latin1'), is_global)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 633, in write_top
    self.write(arr)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 662, in write
    self.write_struct(narr)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 781, in write_struct
    self._write_items(arr)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 798, in _write_items
    self.write(el[f])
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 651, in write
    narr = to_writeable(arr)
  File "C:\Users\reidw\Anaconda3\envs\suite2p-current\lib\site-packages\scipy\io\matlab\_mio5.py", line 493, in to_writeable
    narr = np.asanyarray(source)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part
wisamreid commented 6 months ago

I was able to resolve this. I have injected quite a bit of code into the pipeline, so I can't speak to whether this can come up when using the pipeline through the GUI or why this may have come up for @chunyueli. In my case, ops["date_proc"] is a datetime.datetime object that cannot be saved by scipy(or hdf5storage, in my case). I needed to convert the object to a string before saving the ops file. Otherwise, when the GUI attempts to save a Fall file, it fails.