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

Extending Subject with a group results in Orphaned Group #589

Closed
4 tasks done
bendichter opened this issue Aug 9, 2018 · 5 comments
Closed
4 tasks done

Extending Subject with a group results in Orphaned Group #589

bendichter opened this issue Aug 9, 2018 · 5 comments
Assignees
Milestone

Comments

@bendichter
Copy link
Contributor

Bug

Steps to Reproduce

from pynwb.spec import NWBNamespaceBuilder, NWBGroupSpec, NWBAttributeSpec


from pynwb import register_class, load_namespaces, get_class
from pynwb.form.utils import docval, get_docval
from pynwb.file import Subject as CoreSubject
from pynwb import NWBFile, NWBHDF5IO

from datetime import datetime

ext_source = "test.extensions.yaml"
ns_path = 'test.namespace.yaml'

extra_subject = NWBGroupSpec(
    neurodata_type_def='ExtraSubject',
    neurodata_type_inc='Subject',
    name='subject',
    doc='subject',
    groups=[NWBGroupSpec(name='extra', doc='extra arg',
                         neurodata_type_inc='NWBDataInterface',
                         neurodata_type_def='MyGroup')]
)

ns_builder = NWBNamespaceBuilder('test extensions', 'test')
ns_builder.add_spec(ext_source, extra_subject)
ns_builder.export(ns_path)

load_namespaces(ns_path)


MyGroup = get_class('MyGroup', 'test')


@register_class('ExtraSubject', 'test')
class ExtraSubject(CoreSubject):
    __nwbfields__ = ('extra',)

    @docval(*get_docval(CoreSubject.__init__) + ({'name': 'extra', 'type': MyGroup,
                                                  'doc': 'extra arg'},))
    def __init__(self, **kwargs):
        extra = kwargs.pop('extra')
        super(ExtraSubject, self).__init__(**kwargs)
        self.extra = extra


subject = ExtraSubject(age='unknown', description='unknown', genotype='NA',
                       sex='unknown', species='Homo sapiens', subject_id='123',
                       weight='unknown', source='source',
                       extra=MyGroup(name='mygroup', source='source'))


nwbfile = NWBFile('a', 'b', 'c', datetime.now())
nwbfile.subject = subject

with NWBHDF5IO('test_subject_ext.nwb', 'w') as io:
    io.write(nwbfile)
/Users/bendichter/dev/pynwb/src/pynwb/form/build/map.py:759: OrphanContainerWarning: 'mygroup' (MyGroup) for 'subject' (ExtraSubject)
  warnings.warn(msg, OrphanContainerWarning)

Checklist

  • Have you ensured the feature or change was not already reported ?
  • Have you included a brief and descriptive title?
  • Have you included a clear description of the problem you are trying to solve?
  • Have you included a minimal code snippet that reproduces the issue you are encountering?
@ajtritt ajtritt added this to the NWB 2.0 Full milestone Aug 20, 2018
@ajtritt
Copy link
Member

ajtritt commented Aug 22, 2018

Change the following on line 36

    __nwbfields__ = ('extra',)

to

    __nwbfields__ = ({'name': 'extra', 'child': True},)

@ajtritt ajtritt closed this as completed Aug 22, 2018
@bendichter
Copy link
Contributor Author

@ajtritt thanks for this. I think I'm going to add some documentation about this. So to be clear, is it the case that you need to do this for any NWBGroupSpec that is within another NWBGroupSpec?

@ajtritt
Copy link
Member

ajtritt commented Aug 23, 2018

Almost... any NWBGroupSpec that has a neurodata_type_def or neurodata_type_inc.

The reason for this is to distinguish between subcontainers "owned" by a container and subcontainers linked to by a container. A subgroup that has no neurodata_type is treated as just another field/attribute of the container.

@bendichter
Copy link
Contributor Author

@ajtritt Can you give me a counterexample?

@ajtritt
Copy link
Member

ajtritt commented Aug 24, 2018

For example, /acquisition is not a child of NWBFile. The TimeSeries defined in /acquisition/timeseries are children of NWBFile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants