Skip to content

Commit

Permalink
Merge pull request #4 from VisLab/main
Browse files Browse the repository at this point in the history
Did some renaming of classes
  • Loading branch information
VisLab authored Dec 1, 2023
2 parents 3a4711d + f881867 commit eb4b231
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 204 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ __pycache__/

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
Expand Down Expand Up @@ -164,7 +166,8 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
/venv/

# Mac finder
.DS_Store
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ codespell==2.2.6
coverage==7.3.2
hdmf==3.10.0
hdmf-docutils==0.4.6
hedtools==0.4.0
pre-commit==3.4.0
pynwb==2.5.0
pytest==7.4.2
Expand Down
1 change: 1 addition & 0 deletions requirements-min.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# NOTE: it may be possible to relax these minimum requirements
pynwb==2.5.0
hdmf==3.10.0
hedtools==0.4.0
46 changes: 27 additions & 19 deletions spec/ndx-hed.extensions.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
datasets:
- neurodata_type_def: HedAnnotations
neurodata_type_inc: VectorData
dtype: text
doc: An extension of VectorData for Hierarchical Event Descriptor (HED) tags. If
HED tags are used, the HED schema version must be specified in the NWB file using
the HedMetadata type.
groups:
- neurodata_type_def: HedMetadata
neurodata_type_inc: LabMetaData
name: HedMetadata
doc: An extension of LabMetaData to store the Hierarchical Event Descriptor (HED)
schema version. TODO When merged with core, this will no longer inherit from LabMetaData
but from NWBContainer and be placed optionally in /general.
attributes:
- name: hed_schema_version
dtype: text
doc: The version of the HED schema used to validate the HED tags, e.g., '8.2.0'.
Required if HED tags are used in the NWB file.
datasets:
- neurodata_type_def: HedAnnotations
neurodata_type_inc: VectorData
dtype: text
doc: An extension of VectorData for Hierarchical Event Descriptor (HED) tags. If
HED tags are used, the HED schema version must be specified in the NWB file using
the HedVersion type.
attributes:
- name: sub_name
dtype: text
doc: The smallest possible difference between two event times. Usually 1 divided
by the event time sampling rate on the data acquisition system.
required: false
groups:
- neurodata_type_def: HedVersion
neurodata_type_inc: LabMetaData
name: hed_version
doc: An extension of LabMetaData to store the Hierarchical Event Descriptor (HED)
schema version. TODO When merged with core, this will no longer inherit from LabMetaData
but from NWBContainer and be placed optionally in /general.
attributes:
- name: version
dtype: text
shape:
- null
doc: The version of the HED schema used to validate the HED tags, e.g., '8.2.0'.
Required if HED tags are used in the NWB file.
34 changes: 17 additions & 17 deletions spec/ndx-hed.namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespaces:
- author:
- Ryan Ly
- Oliver Ruebel
- Kay Robbins
- Ian Callanan
contact:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
doc: NWB extension for HED data
name: ndx-hed
schema:
- namespace: core
- source: ndx-hed.extensions.yaml
version: 0.1.0
namespaces:
- author:
- Ryan Ly
- Oliver Ruebel
- Kay Robbins
- Ian Callanan
contact:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
doc: NWB extension for HED data
name: ndx-hed
schema:
- namespace: core
- source: ndx-hed.extensions.yaml
version: 0.1.0
5 changes: 3 additions & 2 deletions src/pynwb/ndx_hed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
# Either have PyNWB generate a class from the spec using `get_class` as shown
# below or write a custom class and register it using the class decorator
# `@register_class("TetrodeSeries", "ndx-hed")`
HedAnnotations = get_class("HedAnnotations", "ndx-hed")
HedMetadata = get_class("HedMetadata", "ndx-hed")
# HedAnnotations = get_class("HedAnnotations", "ndx-hed")
# HedVersion = get_class("HedVersion", "ndx-hed")

# Remove these functions from the package
del load_namespaces, get_class
from .hed_annotations import HedVersion, HedAnnotations
104 changes: 104 additions & 0 deletions src/pynwb/ndx_hed/hed_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from collections.abc import Iterable
from hdmf.common import VectorData
from hdmf.utils import docval, getargs, get_docval, popargs
from hed.schema import HedSchema, HedSchemaGroup, load_schema_version
from pynwb import register_class
from pynwb.file import LabMetaData


@register_class('HedAnnotations', 'ndx-hed')
class HedAnnotations(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.
"""

__nwbfields__ = ('sub_name')

@docval(*get_docval(VectorData.__init__))
def __init__(self, **kwargs):
# kwargs['name'] = 'HED'
super().__init__(**kwargs)
self._init_internal()

def _init_internal(self):
"""
This finds the HED schema object of use in this NWBFile.
TODO: How should errors be handled if this file doesn't have a HedVersion object in the LabMetaData?
"""
self.sub_name = "HED"
root = self
# parent = root.parent
# while parent is not None:
# root = parent
# parent = root.parent
# hed_version = parent.get_lab_meta_data("HedVersion")
# if hed_version:
# self.hed_schema = hed_version.get_schema()

@docval({'name': 'val', 'type': str,
'doc': 'the value to add to this column. Should be a valid HED string.'})
def add_row(self, **kwargs):
"""Append a data value to this column."""
val = getargs('val', kwargs)
# val.check_types()
# TODO how to validate
#
# if val is not None and self.validate(val):
# if self.term_set.validate(term=val):
# self.append(val)
# else:
# msg = ("%s is not in the term set." % val)
# raise ValueError(msg)
#
# else:
# self.append(val)
super().append(val)

@docval({'name': 'key', 'type': 'str', 'doc': 'the value to add to this column'})
def get(self, key):
"""
Retrieve elements from this object.
"""
# TODO: Can key be more than a single value? Do we need to check validity of anything?
vals = super().get(key)
return vals

@docval({'name': 'val', 'type': 'str', 'doc': 'the value to validate'},
{'name': 'return', 'type': 'list', 'doc': 'list of issues or none'})
def validate(self, **kwargs):
"""Validate this HED string"""
val = getargs('val', kwargs)
return True


@register_class("HedVersion", "ndx-hed")
class HedVersion(LabMetaData):
"""
The class containing the HED versions and HED schema used in this data file.
"""

__nwbfields__ = ('name', 'description', 'version')

@docval({'name': 'version', 'type': (str, list), 'doc': 'HED strings of type str'})
def __init__(self, version):
kwargs = {'name': 'hed_version'}
super().__init__(**kwargs)
self.version = version
self._init_internal()

def _init_internal(self):
"""
Create a HedSchema or HedSchemaGroup object from the HED Versions
"""
self._hed_schema = load_schema_version(self.version)

@docval(returns='The HED schema or schema group object for this version', rtype=(HedSchema, HedSchemaGroup))
def get_hed_schema(self):
return self._hed_schema
Loading

0 comments on commit eb4b231

Please sign in to comment.