Skip to content

Annotation handling when grouping signals #740

Open
@JuliaSprenger

Description

@JuliaSprenger

This is a follow up of #625.

When loading information using the rawio framework, annotations are handled differently depending on the grouping modes of the signals. When splitting signal into individual Neo objects, all channel-wise annotations are loaded and attached to the objects. However, when grouping the signals according to common aspects, some channel-wise annotations might be lost if they can not be converted into an array_annotation.

Here is an example using the NixIO Raw implementation for loading

# writing block with two AnalogSignal traces and individual annotations
with NixIO(filename,'ow') as io:
    bl0 = Block(my_custom_annotation='hello block')
    bl0.segments.append(neo.Segment())
    bl0.segments[0].analogsignals.append(neo.AnalogSignal([1,2,3]*pq.V, sampling_rate=1*pq.Hz, anno1 = 'myfirstannotation'))
    bl0.segments[0].analogsignals.append(neo.AnalogSignal([1,2,3]*pq.V, sampling_rate=1*pq.Hz, anno2 = 'mysecondannotation'))
    io.write_block(bl0)

# test for signal_group_mode='split-all'
with NixIOFr(filename) as io:
    bl1 = io.read_block(signal_group_mode='split-all')
    assert len(bl0.annotations) == len(bl1.annotations)
    assert len(bl1.segments[0].analogsignals) == len(bl0.segments[0].analogsignals)
    for aid in range(len(bl0.segments[0].analogsignals)):
        for k,v in bl0.segments[0].analogsignals[aid].annotations.items():
            assert bl1.segments[0].analogsignals[aid].annotations[k] == v

# test for signal_group_mode='group-by-same-units'
with NixIOFr(filename) as io:
    bl1 = io.read_block(signal_group_mode='group-by-same-units')
    assert len(bl0.annotations) == len(bl1.annotations)
    assert len(bl1.segments[0].analogsignals) == 1
    for anasig in bl0.segments[0].analogsignals:
        for k,v in anasig.annotations.items():
            # these assertion fail due to grouping of AnalogSignals leading to missing annotation information
            assert k in bl1.segments[0].analogsignals[0].array_annotations
            assert bl1.segments[0].analogsignals[0].annotations[k] == v

Here, since both objects have different annotations keys, the annotation is not handled as an array_annotation, but ignored during loading. Maybe annotation of this type should be expanded to be represented as array_annotations to not be lost during the loading of the data?
@samuelgarcia: What do you think?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions