G-Node / python-neo

Fork of python-neo for maintaining the NIX IO.
https://github.com/NeuralEnsemble/python-neo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error when saving spiketrain with left_sweep attribute #11

Open JuliaSprenger opened 7 years ago

JuliaSprenger commented 7 years ago

On the 'nixio-object-names' branch, when trying to save a spiketrain like this one

    st = neo.SpikeTrain([1, 2, 3]*pq.s, t_start=0*pq.s,
                        t_stop=10*pq.s, sampling_rate=1*pq.Hz,
                        left_sweep=-2.0*pq.s)
    waveforms = np.arange(3*16).reshape((3,-1))*pq.V
    st.waveforms = waveforms

this results in a TypeError

[...] File "python-neo/neo/io/nixio.py", line 741, in write_spiketrain self._write_object(sptr, loc) File "python-neo/neo/io/nixio.py", line 555, in _write_object self._write_data(nixobj, attr, objpath) File "python-neo/neo/io/nixio.py", line 964, in _write_data attr["left_sweep"]) File "python-neo/neo/io/nixio.py", line 1076, in _write_property for item in v: TypeError: iteration over a 0-d array

The underlying problem is that a scalar quantity object like -2.0*pq.s is evaluated as being an Iterable, but actually can not be iterated. I think this case should needs to be explicitly checked somewhere within the nixio.

JuliaSprenger commented 7 years ago

A simple workaround to avoid this problem would be to save only spiketrains, for which the left_sweep attributes contain data like [-2.0]*pq.s.

achilleas-k commented 7 years ago

I should add a special case for 0d/scalar quantities. The _write_property() method needs to make some assumptions about the structure of properties based on their type and for now one of the assumptions is that Quantity types are iterable. Of course this isn't true when it's a 0d array, so we should check for that.