NeuralEnsemble / python-neo

Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats
http://neo.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
322 stars 247 forks source link

Make attribute and annotation handling more consistent between NixIO and NixIOFr #1211

Open JuliaSprenger opened 1 year ago

JuliaSprenger commented 1 year ago

Describe the bug Depending on the IO used to load a nix file the loaded neo objects have different attribute values and annotations. This is confusing for the user and leads to inconsistencies.

To Reproduce One example demonstrating the descrepancies is the file_origin attributes, as can be demonstrated via

from neo import Block, Segment, AnalogSignal
import quantities as pq

asig = AnalogSignal([1,2,3]*pq.V, sampling_rate=1*pq.Hz, file_origin='mydir/anasig_data.txt', array_annotations={'file_origin': ['mydir/single_channel_data.txt']})
bl = Block(file_origin='mydir/block_data.txt')
bl.segments.append(Segment(file_origin='mydir/segment_data.txt'))
bl.segments[0].analogsignals.append(asig)

from neo import NixIO
nio = NixIO('test.nix', 'ow')
nio.write_block(bl)

# reading attributes via NixIO
bl2 = nio.read_block()
print('Attributes read by NixIO')
print(bl2.file_origin)
print(bl2.segments[0].file_origin)
print(bl2.segments[0].analogsignals[0].file_origin)
print(bl2.segments[0].analogsignals[0].array_annotations)
nio.close()

# reading attributes via NixIOfr
from neo.io import NixIOFr
nio = NixIOFr('test.nix')
bl2 = nio.read_block()
print('Attributes read by NixIOFr')
print(bl2.file_origin)
print(bl2.segments[0].file_origin)
print(bl2.segments[0].analogsignals[0].file_origin)
print(bl2.segments[0].analogsignals[0].array_annotations)

This returns

None
None
None
{'file_origin': array(['mydir/single_channel_data.txt'], dtype='<U29')}
Attributes read by NixIOFr
test.nix
test.nix
test.nix
{'channel_names': array([''], dtype='<U1'), 'channel_ids': array(['0'], dtype='<U1')}

Expected behaviour Both IOs should yield neo objects with the same attributes and values

Environment:

JuliaSprenger commented 1 year ago

This is issue is related to https://github.com/NeuralEnsemble/python-neo/issues/903