Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Empty Array Annotations in NixIO #806

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions neo/io/nixio.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def _write_analogsignal(self, anasig, nixblock, nixgroup):
if anasig.array_annotations:
for k, v in anasig.array_annotations.items():
p = self._write_property(metadata, k, v)
p.definition = ARRAYANNOTATION
p.type = ARRAYANNOTATION

self._signal_map[nix_name] = nixdas

Expand Down Expand Up @@ -992,7 +992,7 @@ def _write_irregularlysampledsignal(self, irsig, nixblock, nixgroup):
if irsig.array_annotations:
for k, v in irsig.array_annotations.items():
p = self._write_property(metadata, k, v)
p.definition = ARRAYANNOTATION
p.type = ARRAYANNOTATION

self._signal_map[nix_name] = nixdas

Expand Down Expand Up @@ -1047,7 +1047,7 @@ def _write_event(self, event, nixblock, nixgroup):
if event.array_annotations:
for k, v in event.array_annotations.items():
p = self._write_property(metadata, k, v)
p.definition = ARRAYANNOTATION
p.type = ARRAYANNOTATION

nixgroup.multi_tags.append(nixmt)

Expand Down Expand Up @@ -1115,7 +1115,7 @@ def _write_epoch(self, epoch, nixblock, nixgroup):
if epoch.array_annotations:
for k, v in epoch.array_annotations.items():
p = self._write_property(metadata, k, v)
p.definition = ARRAYANNOTATION
p.type = ARRAYANNOTATION

nixgroup.multi_tags.append(nixmt)

Expand Down Expand Up @@ -1177,7 +1177,7 @@ def _write_spiketrain(self, spiketrain, nixblock, nixgroup):
if spiketrain.array_annotations:
for k, v in spiketrain.array_annotations.items():
p = self._write_property(metadata, k, v)
p.definition = ARRAYANNOTATION
p.type = ARRAYANNOTATION

if nixgroup:
nixgroup.multi_tags.append(nixmt)
Expand Down Expand Up @@ -1390,7 +1390,7 @@ def _nix_attr_to_neo(nix_obj):
if prop.definition in (DATEANNOTATION, TIMEANNOTATION,
DATETIMEANNOTATION):
values = dt_from_nix(values, prop.definition)
if prop.definition == ARRAYANNOTATION:
if prop.type == ARRAYANNOTATION:
if 'array_annotations' in neo_attrs:
neo_attrs['array_annotations'][prop.name] = values
else:
Expand Down
30 changes: 24 additions & 6 deletions neo/test/iotest/test_nixio.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def create_full_nix_file(cls, filename):
asig_md.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
asig_md.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
asig_md.props[arr_ann_name].definition = 'ARRAYANNOTATION'
asig_md.props[arr_ann_name].type = 'ARRAYANNOTATION'

for idx in range(10):
da_asig = blk.create_data_array(
Expand Down Expand Up @@ -452,7 +452,7 @@ def create_full_nix_file(cls, filename):
imgseq_md.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
imgseq_md.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
imgseq_md.props[arr_ann_name].definition = 'ARRAYANNOTATION'
imgseq_md.props[arr_ann_name].type = 'ARRAYANNOTATION'

for idx in range(10):
da_imgseq = blk.create_data_array(
Expand Down Expand Up @@ -485,7 +485,7 @@ def create_full_nix_file(cls, filename):
isig_md.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
isig_md.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
isig_md.props[arr_ann_name].definition = 'ARRAYANNOTATION'
isig_md.props[arr_ann_name].type = 'ARRAYANNOTATION'
for idx in range(7):
da_isig = blk.create_data_array(
"{}.{}".format(isig_name, idx),
Expand Down Expand Up @@ -527,7 +527,7 @@ def create_full_nix_file(cls, filename):
mtag_st_md.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
mtag_st_md.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
mtag_st_md.props[arr_ann_name].definition = 'ARRAYANNOTATION'
mtag_st_md.props[arr_ann_name].type = 'ARRAYANNOTATION'

waveforms = cls.rquant((10, 8, 5), 1)
wfname = "{}.waveforms".format(mtag_st.name)
Expand Down Expand Up @@ -579,7 +579,7 @@ def create_full_nix_file(cls, filename):
mtag_ep.metadata.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
mtag_ep.metadata.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
mtag_ep.metadata.props[arr_ann_name].definition = 'ARRAYANNOTATION'
mtag_ep.metadata.props[arr_ann_name].type = 'ARRAYANNOTATION'

label_dim = mtag_ep.positions.append_set_dimension()
label_dim.labels = cls.rsentence(5).split(" ")
Expand Down Expand Up @@ -612,7 +612,7 @@ def create_full_nix_file(cls, filename):
mtag_ev.metadata.create_property(arr_ann_name,
arr_ann_val.magnitude.flatten())
mtag_ev.metadata.props[arr_ann_name].unit = str(arr_ann_val.dimensionality)
mtag_ev.metadata.props[arr_ann_name].definition = 'ARRAYANNOTATION'
mtag_ev.metadata.props[arr_ann_name].type = 'ARRAYANNOTATION'

label_dim = mtag_ev.positions.append_set_dimension()
label_dim.labels = cls.rsentence(5).split(" ")
Expand Down Expand Up @@ -1486,6 +1486,24 @@ def test_annotations_special_cases(self):

# TODO: multi dimensional value (GH Issue #501)

def test_empty_array_annotations(self):
wblock = Block("block with spiketrain")
wseg = Segment()
wseg.spiketrains = [SpikeTrain(times=[] * pq.s, t_stop=1 * pq.s,
array_annotations={'empty': []})]
wblock.segments = [wseg]
self.writer.write_block(wblock)
try:
rblock = self.writer.read_block(neoname="block with spiketrain")
except Exception as exc:
self.fail('The following exception was raised when'
+ ' reading the block with an empty array annotation:\n'
+ str(exc))
rst = rblock.segments[0].spiketrains[0]
self.assertEqual(len(rst.array_annotations), 1)
self.assertIn('empty', rst.array_annotations.keys())
self.assertEqual(len(rst.array_annotations['empty']), 0)

def test_write_proxyobjects(self):

def generate_complete_block():
Expand Down