Source code for ndx_hed.hed_tags

from hdmf.common import VectorData
from hdmf.utils import docval, get_docval, getargs
from pynwb import register_class


[docs] @register_class("HedTags", "ndx-hed") class HedTags(VectorData): """ Column storing HED (Hierarchical Event Descriptors) annotations for a row. A HED string is a comma-separated, and possibly parenthesized list of HED tags selected from a valid HED vocabulary as specified by the NWBFile field HedVersion. A HedTags column must be named "HED" (enforced by the constructor). There is at most one HedTags column per DynamicTable (a consequence of the fixed name). HED-aware code also identifies HED columns by their neurodata type (``isinstance(col, HedTags)``). """ # __nwbfields__ = ('_hed_schema', 'hed_version')
[docs] @docval( { "name": "name", "type": str, "doc": "The name of this column. Must be 'HED' (the default).", "default": "HED", }, { "name": "description", "type": str, "doc": "a description for this column", "default": "Column that stores HED tags as text annotating their respective row.", }, *get_docval(VectorData.__init__, "data"), ) def __init__(self, **kwargs): if kwargs.get("name", "HED") != "HED": raise ValueError(f"The 'name' for HedTags must be 'HED', but '{kwargs['name']}' was given.") super().__init__(**kwargs)
# def _init_internal(self): # """ # This calls the tokenizer # """ # self._hed_schema = load_schema_version(self.hed_version) # issues = [] # if issues: # issue_str = "\n".join(issues) # raise ValueError(f"InvalidHEDData {issue_str}")
[docs] @docval({ "name": "val", "type": str, "doc": "the value to add to this column. Should be a valid HED string -- just forces string.", }) def add_row(self, **kwargs): """Append a data value to this column.""" val = getargs("val", kwargs) if not isinstance(val, str): raise TypeError(f"Value {val} is of incorrect type {type(val)}. Must be a string.") super().append(val)
# def get_hed_version(self): # return self.hed_version # def get_hed_schema(self): # return self._hed_schema
[docs] @register_class("HedValueVector", "ndx-hed") class HedValueVector(VectorData): """ Column storing values and a single HED annotation that applies to all values in the column. A HED string is a comma-separated, and possibly parenthesized list of HED tags selected from a valid HED vocabulary as specified by the NWBFile field HedVersion. A HedValueVector column may have any name. HED-aware code identifies these columns by their neurodata type (``isinstance(col, HedValueVector)``), not by the column name. """ __nwbfields__ = ("_hed",)
[docs] @docval( *get_docval(VectorData.__init__, "name", "description", "data"), {"name": "hed", "type": str, "doc": "HED annotation template for all values in the column"}, ) def __init__(self, **kwargs): hed_annotation = kwargs.pop("hed", None) super().__init__(**kwargs) # Check that the template contains exactly one # placeholder placeholder_count = hed_annotation.count("#") if placeholder_count != 1: raise ValueError( f"HedValueVector '{self.name}' template must contain exactly one '#' placeholder, " f"found {placeholder_count} in: {hed_annotation}" ) self._hed = hed_annotation
@property def hed(self): """Return the HED annotation template for this column.""" return self._hed