-
Notifications
You must be signed in to change notification settings - Fork 86
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
writing to MultiContainerInterface extension results in orphaned container #556
Comments
When I run this and open the file in HDFView (v. 2.14), I do see an
There are no other contents called |
I see the same thing @ageorgou sees. The autogenerated class Grouper is not making the Elems children (i.e. not setting parent), hence the OrphanContainerWarning. When the parent of a child (in our case None) does not match the container holding reference to said child, it is assumed to be an external child, so a link is set. In this case, a link is made to something that doesn't exist. The Elem instance (i.e. |
The fix for this is to detect the inclusion of multiple Elems in Grouper, and set include pynwb/src/pynwb/form/build/map.py Line 989 in 6d2cc9f
The "work around" would be to define your own class. This is not just a work around, but it's the recommended way for extending. Writing your own classes is the safest way to extend NWB. |
I was able to get it working by building my own class from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec
from pynwb import load_namespaces, NWBFile, NWBHDF5IO, get_class
from pynwb.file import MultiContainerInterface, register_class
ext_name = 'test_ext'
ns_path = ext_name + ".namespace.yaml"
ext_source = ext_name + ".extensions.yaml"
elem = NWBGroupSpec(neurodata_type_inc='NWBDataInterface',
neurodata_type_def='Elem',
quantity='+',
doc='doc',
attributes=[NWBAttributeSpec(name='data', doc='data',
dtype='double', required=True)])
grouper = NWBGroupSpec(neurodata_type_inc='NWBDataInterface',
neurodata_type_def='Grouper',
quantity='?',
doc='doc',
groups=[elem])
ns_builder = NWBNamespaceBuilder(ext_name + ' extensions', ext_name)
ns_builder.add_spec(ext_source, grouper)
ns_builder.export(ns_path)
load_namespaces(ns_path)
Elem = get_class('Elem', ext_name)
@register_class('Grouper', ext_name)
class Grouper(MultiContainerInterface):
__clsconf__ = {
'attr': 'elems',
'type': Elem,
'add': 'add_elem',
'get': 'get_elem',
'create': 'create_elem',
}
__help = 'test grouper'
elem1 = Elem(data=2.0, name='elem', source='source')
elem2 = Elem(data=3.0, name='elem2', source='source')
group = Grouper(name='group', source='source')
group.add_elem(elem1)
group.add_elem(elem2)
nwbfile = NWBFile("source", "a file with header data", "NB123A", '2018-06-01T00:00:00')
mod = nwbfile.create_processing_module(name='module', source='source',
description='description')
mod.add_container(group)
with NWBHDF5IO('test_group', 'w') as io:
io.write(nwbfile) I think the best approach here would be to correct |
Am I doing this wrong? I may be doing this wrong. Here's the minimal example:
Using HDFView, there is no
elem
, and noelem.data
. Same issue if I write theGrouper
class myself.The text was updated successfully, but these errors were encountered: