Skip to content

Commit

Permalink
Merge pull request #13 from VisLab/main
Browse files Browse the repository at this point in the history
Problem with proposed validation strategy proposed in #10
  • Loading branch information
VisLab authored Jul 8, 2024
2 parents 20b9f41 + 8ff816a commit 755c434
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 602 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ keywords = [
'ndx-extension',
]
dependencies = [
"pynwb>=2.5.0",
"hdmf>=3.10.0",
"hedtools>=0.4.0"
"pynwb>=2.8.0",
"hdmf>=3.14.1",
"hedtools>=0.5.0"
]

# TODO: add URLs before release
Expand Down Expand Up @@ -77,7 +77,7 @@ include = [
exclude = []

[tool.pytest.ini_options]
addopts = "--cov --cov-report html"
# addopts = "--cov --cov-report html"

[tool.codespell]
skip = "htmlcov,.git,.mypy_cache,.pytest_cache,.coverage,*.pdf,*.svg,venvs,.tox,hdmf-common-schema,./docs/_build/*,*.ipynb"
Expand Down
20 changes: 10 additions & 10 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# pinned dependencies to reproduce an entire development environment to
# run tests, check code style, and generate documentation
black==23.9.1
codespell==2.2.6
coverage==7.3.2
hdmf==3.10.0
hdmf-docutils==0.4.6
hedtools==0.4.0
black==24.4.2
codespell==2.3.0
coverage==7.5.3
hdmf==3.14.1
hdmf-docutils==0.4.7
hedtools==0.5.0
pre-commit==3.4.0
pynwb==2.5.0
pytest==7.4.2
pynwb==2.8.0
pytest==8.2.2
pytest-cov==4.1.0
python-dateutil==2.8.2
pytest-subtests==0.6.0
ruff==0.0.292
tox==4.11.3
ruff==0.4.10
tox==4.15.1
6 changes: 3 additions & 3 deletions requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# minimum versions of package dependencies for installation
# these should match the minimum versions specified in pyproject.toml
# NOTE: it may be possible to relax these minimum requirements
pynwb==2.5.0
hdmf==3.10.0
hedtools==0.4.0
pynwb==2.8.0
hdmf==3.14.1
hedtools==0.5.0
25 changes: 3 additions & 22 deletions spec/ndx-hed.extensions.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
datasets:
- neurodata_type_def: HedTags
neurodata_type_inc: VectorData
name: HED
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: HedVersionAttr
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
- name: hed_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.
- 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.
datasets:
- name: version
dtype: text
doc: HED schema version to use for this dataset
quantity: '?'
doc: "The version of the HED schema used to validate the HED tags, e.g., '8.2.0'.
(Required). "
1 change: 0 additions & 1 deletion spec/ndx-hed.namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespaces:
schema:
- namespace: core
neurodata_types:
- LabMetaData
- VectorData
- source: ndx-hed.extensions.yaml
version: 0.1.0
41 changes: 40 additions & 1 deletion src/pynwb/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
## ndx_hed NWB extension
## ndx_hed Extension for NWB

This is an NWB extension for adding Hierarchical Event Descriptor (HED) tags to NWB data.
HED is a system for

The latest version is 0.1.0. This is the first release of ndx-hed.


This extension was developed by Kay Robbins, Ryan Ly, Oliver Rübel, and the HED Working Group.
The documentation for this extension can be found at

## Installation
Python:
```bash
pip install -U ndx-hed
```

## Developer installation
In a Python 3.8-3.12 environment:
```bash
pip install -r requirements-dev.txt
pip install -e .
```

Run tests:
```bash
pytest
```

Install pre-commit hooks:
```bash
pre-commit install
```

Style and other checks:
```bash
black .
ruff .
codespell .
```
2 changes: 0 additions & 2 deletions src/pynwb/ndx_hed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@
# # Remove these functions from the package
del load_namespaces, get_class

from .hed_version_attr import HedVersionAttr
from .hed_tags import HedTags
from .hed_version import HedVersion
85 changes: 25 additions & 60 deletions src/pynwb/ndx_hed/hed_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from hed.models import HedString
from pynwb import register_class
from pynwb.file import LabMetaData, NWBFile
from ndx_hed import HedVersionAttr


@register_class('HedTags', 'ndx-hed')
Expand All @@ -18,81 +17,47 @@ class HedTags(VectorData):
"""

__nwbfields__ = ('_hed_schema')
__nwbfields__ = ('_hed_schema', 'hed_version')

@docval({'name': 'name', 'type': 'str', 'doc': 'Must be HED', 'default': 'HED'},
{'name': 'description', 'type': 'str', 'doc': 'Description of the HED annotations',
'default': 'Hierarchical Event Descriptors (HED) annotations'},
*get_docval(VectorData.__init__, 'data'))
@docval({'name': 'hed_version', 'type': 'str', 'doc': 'The version of HED used by this data.'},
{'name': 'name', 'type': str, 'doc': 'The name of this VectorData', '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):
kwargs['name'] = 'HED'
hed_version = popargs('hed_version', kwargs)
super().__init__(**kwargs)
self.hed_version = hed_version
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?
This loads (a private pointer to) the HED schema and validates the HED data.
"""
self._hed_schema = None
self._hed_schema = load_schema_version(self.hed_version)
issues = []
for index in range(len(self.data)):
hed_obj = HedString(self.get(index), self._hed_schema)
these_issues = hed_obj.validate()
if these_issues:
issues.append(f"line {str(index)}: {get_printable_issue_string(these_issues)}")
if issues:
raise HedFileError("InvalidHEDData", "\n".join(issues), "")

@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)
hed_obj = HedString(val, self._hed_schema)
these_issues = hed_obj.validate()
if these_issues:
raise HedFileError("InvalidHEDValue",
f"{str(val)} issues: {get_printable_issue_string(these_issues)}", "")
super().append(val)

# @docval({'name': 'schema', 'type': (HedSchema, None), 'doc': 'HedSchema to use to validate.', 'default': None},
# {'name': 'return', 'type': 'list', 'doc': 'list of issues or none'})
def validate(self, schema):
"""Validate this VectorData. This is assuming a list --- where is the general iterator."""
if not schema:
raise HedFileError('HedSchemaMissing', "Must provide a valid HedSchema", "")
issues = []
for index in range(len(self.data)):
hed_obj = HedString(self.get(index), schema)
these_issues = hed_obj.validate()
if these_issues:
issues.append(f"line {str(index)}: {get_printable_issue_string(these_issues)}")
return "\n".join(issues)
def get_hed_version(self):
return self.hed_version

def get_hed_schema(self):
if not self._hed_schema:
root = self._get_root()
if isinstance(root, NWBFile):
self._hed_schema = root.get_lab_meta_data("hed_version").get_schema()
return self._hed_schema

def _get_root(self):
root = self
while hasattr(root, 'parent') and root.parent:
root = root.parent
if root == self:
return None
return root


# root = parent
# parent = root.parent
# if parent:
# hed_version = parent.get_lab_meta_data("HedVersion")
# else:
# hed_version = None
# if hed_version:
# self.hed_schema = hed_version.get_schema()

# root = self
# parent = root.parent
# while parent is not None:
# root = parent
# parent = root.parent
# if parent:
# hed_version = parent.get_lab_meta_data("HedVersion")
# else:
# hed_version = None
# if hed_version:
# self.hed_schema = hed_version.get_schema()

34 changes: 0 additions & 34 deletions src/pynwb/ndx_hed/hed_version.py

This file was deleted.

37 changes: 0 additions & 37 deletions src/pynwb/ndx_hed/hed_version_attr.py

This file was deleted.

Loading

0 comments on commit 755c434

Please sign in to comment.