Skip to content

Commit

Permalink
termset schema option
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Nov 15, 2023
1 parent 2aceed0 commit 8fe396a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class NWBContainer(NWBMixin, Container):

__nwbfields__ = tuple()

@register_class('NWBTermSetContainer', CORE_NAMESPACE)
class NWBTermSetContainer(NWBContainer):
def __init__(self, **kwargs):
termset_path = popargs('termset_path', kwargs)
super().__init__(**kwargs)
self.termset_path = termset_path

@register_class('NWBDataInterface', CORE_NAMESPACE)
class NWBDataInterface(NWBContainer):
Expand Down
4 changes: 4 additions & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Subject(NWBContainer):
{'name': 'date_of_birth', 'type': datetime, 'default': None,
'doc': 'The datetime of the date of birth. May be supplied instead of age.'},
{'name': 'strain', 'type': str, 'doc': 'The strain of the subject, e.g., "C57BL/6J"', 'default': None},
{'name': 'termset_path', 'type':str, 'doc': 'The path to the the TermSet', 'default': '...'}
)
def __init__(self, **kwargs):
keys_to_set = (
Expand All @@ -121,9 +122,12 @@ def __init__(self, **kwargs):
"date_of_birth",
"strain",
)
termset_path = popargs('termset_path', kwargs)
args_to_set = popargs_to_dict(keys_to_set, kwargs)
super().__init__(name="subject", **kwargs)

self.termset_path = termset_path

# NOTE when the Subject I/O mapper (see pynwb.io.file.py) reads an age__reference value of None from an
# NWB 2.0-2.5 file, it sets the value to "unspecified" so that when Subject.__init__ is called, the incoming
# age__reference value is NOT replaced by the default value ("birth") specified in the docval.
Expand Down
10 changes: 9 additions & 1 deletion src/pynwb/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .. import register_map

from pynwb.file import NWBFile
from pynwb.core import NWBData, NWBContainer, ScratchData
from pynwb.core import NWBData, NWBContainer, ScratchData, NWBTermSetContainer
from pynwb.misc import Units


Expand All @@ -26,6 +26,14 @@ def get_nwb_file(container):
class NWBContainerMapper(NWBBaseTypeMapper):
pass

@register_map(NWBTermSetContainer)
class NWBTermSetContainerMapper(ObjectMapper):

def __init__(self, spec):
super().__init__(spec)
termset_path_spec = spec.get_attribute('termset_path')
self.map_spec('termset_path', termset_path_spec)


@register_map(NWBData)
class NWBDataMap(NWBBaseTypeMapper):
Expand Down
8 changes: 7 additions & 1 deletion src/pynwb/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .. import register_map
from ..file import NWBFile, Subject
from ..core import ScratchData
from .core import NWBTermSetContainerMapper
from .utils import get_nwb_version


Expand Down Expand Up @@ -210,7 +211,12 @@ def publication_obj_attr(self, container, manager):


@register_map(Subject)
class SubjectMap(ObjectMapper):
class SubjectMap(NWBTermSetContainerMapper):

# def __init__(self, spec):
# super().__init__(spec)
# termset_path_spec = self.spec.get_attribute('termset_path')
# self.map_spec('termset_path', termset_path_spec)

@ObjectMapper.constructor_arg('date_of_birth')
def dateconversion(self, builder, manager):
Expand Down
1 change: 0 additions & 1 deletion tests/integration/hdf5/test_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ def addContainer(self, nwbfile):
group=self.group,
group_name='tetrode1'
)

self.container = nwbfile.electrodes # override self.container which has the placeholder

def getContainer(self, nwbfile):
Expand Down

0 comments on commit 8fe396a

Please sign in to comment.