Skip to content
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
29 changes: 14 additions & 15 deletions mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,28 +835,27 @@ def _update_hed_strings(self, hed_strings):
f"Number of HED strings ({len(hed_strings)}) must match the number of "
f"annotations ({len(self)})."
)
# validation of HED strings
# create HedString objects
schema = self.hed.load_schema_version(self.hed_version)
self._hed_strings = [self.hed.HedString(hs, schema) for hs in hed_strings]
# validation of HED strings
validator = HedValidator(schema)
error_handler = self.hed.errors.ErrorHandler(check_for_warnings=False)
error_strs = [
self._validate_one_hed_string(hs, schema, validator, error_handler)
for hs in hed_strings
issues = [
validator.validate(
hs, allow_placeholders=False, error_handler=error_handler
)
for hs in self._hed_strings
]
if any(map(len, error_strs)):
error_strings = [self.hed.get_printable_issue_string(issue) for issue in issues]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do:
error_string = self.hed.get_printable_issue_string(issues)

Also, do you want to add links to the error descriptions in the HED specification? If so, you could do:

error_string = self.hed.get_printable_issue_string(issues, add_link=True)

Are there setting in MNE for just reporting errors and not warnings?

if any(map(len, error_strings)):
raise ValueError(
"Some HED strings in your annotations failed to validate:\n - "
+ "\n - ".join(error_strs)
+ "\n - ".join(error_strings)
)
self.hed_strings = hed_strings

def _validate_one_hed_string(self, hed_string, schema, validator, error_handler):
"""Validate a user-provided HED string."""
hs = self.hed.HedString(hed_string, schema)
issues = validator.validate(
hs, allow_placeholders=False, error_handler=error_handler
self.hed_strings = tuple(
hs.get_original_hed_string() for hs in self._hed_strings
)
return self.hed.get_printable_issue_string(issues)

def __eq__(self, other):
"""Compare to another HEDAnnotations instance."""
Expand All @@ -868,7 +867,7 @@ def __eq__(self, other):

def __repr__(self):
"""Show a textual summary of the object."""
counter = Counter(self.hed_strings)
counter = Counter([hs.get_as_short() for hs in self._hed_strings])
kinds = ", ".join(["{} ({})".format(*k) for k in sorted(counter.items())])
kinds = (": " if len(kinds) > 0 else "") + kinds
ch_specific = ", channel-specific" if self._any_ch_names() else ""
Expand Down