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

TermSet Config #1789

Closed
wants to merge 6 commits into from
Closed
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
19 changes: 17 additions & 2 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import numpy as np

from hdmf import Container, Data
import yaml

from hdmf import Container, Data, TermSet, TermSetWrapper
from hdmf.container import AbstractContainer, MultiContainerInterface as hdmf_MultiContainerInterface, Table
from hdmf.common import DynamicTable, DynamicTableRegion # noqa: F401
from hdmf.common import VectorData, VectorIndex, ElementIdentifiers # noqa: F401
from hdmf.utils import docval, popargs
from hdmf.utils import docval, popargs, get_docval
from hdmf.utils import LabelledDict # noqa: F401

from . import CORE_NAMESPACE, register_class
Expand Down Expand Up @@ -54,6 +56,19 @@ class NWBContainer(NWBMixin, Container):

__nwbfields__ = tuple()

def init_validation(self, kwargs):
# Before calling super().__init__() and before setting fields, check for termset_config.yaml.
# This file will be stored within nwb-schema
with open('src/pynwb/nwb-schema/termset_config/termset_config.yaml', 'r') as config:
termset_config = yaml.safe_load(config)
object_name = self.__class__.__name__ # the name field is not set yet
if object_name in termset_config:
for field in termset_config[object_name]:
if field in kwargs: # make sure any custom fields are not handled (i.e., make an extension)
termset_path = termset_config[object_name][field]
termset = TermSet(term_schema_path=termset_path)
kwargs[field] = TermSetWrapper(value=kwargs[field], termset=termset)


@register_class('NWBDataInterface', CORE_NAMESPACE)
class NWBDataInterface(NWBContainer):
Expand Down
5 changes: 3 additions & 2 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Subject(NWBContainer):
{'name': 'strain', 'type': str, 'doc': 'The strain of the subject, e.g., "C57BL/6J"', 'default': None},
)
def __init__(self, **kwargs):
self.init_validation(kwargs)
keys_to_set = (
"age",
"age__reference",
Expand All @@ -122,8 +123,8 @@ def __init__(self, **kwargs):
"strain",
)
args_to_set = popargs_to_dict(keys_to_set, kwargs)
super().__init__(name="subject", **kwargs)

kwargs['name'] = 'subject'
super().__init__(**kwargs)
# 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
Loading