Skip to content
Merged
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
43 changes: 4 additions & 39 deletions hed/tools/analysis/events_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def _initialize(self, hed_schema, file, sidecar, name):
self.checker = EventsChecker(hed_schema, self.input_data, name)
self.issues = self.checker.validate_event_tags()
self.error_lines = EventsChecker.get_error_lines(self.issues)


def extract_tag_summary(self):
""" Extract a summary of the tags in a given tabular input file.
Expand All @@ -72,7 +71,7 @@ def extract_tag_summary(self):

group_dict = {key: set() for key in self.MATCH_TYPES}
other = set()
group_error_lines = self.error_lines.get(TagQualityErrors.IMPROPER_EVENT_GROUPS)
group_error_lines = self.error_lines.get(TagQualityErrors.IMPROPER_EVENT_GROUPS, [])
for index, hed_obj in enumerate(self.checker.hed_objs):
if not hed_obj or index in group_error_lines:
continue
Expand Down Expand Up @@ -111,9 +110,9 @@ def update_tags(self, tag_set, all_tags):
def summarize_tags(schema, tsv, sidecar, name):
""" Summarize the tags in a given tabular input file.

Args:
hed_schema: The HED schema to use for validation.
file: The path to the input file.
Parameters:
schema: The HED schema to use for validation.
tsv: The path to the input file.
sidecar: The path to the sidecar file (optional).
name: The name of the dataset (optional).

Expand All @@ -127,37 +126,3 @@ def summarize_tags(schema, tsv, sidecar, name):
summary, others = events_summary.extract_tag_summary()
return summary


if __name__ == '__main__':
schema = load_schema_version('8.4.0')

# # Wakeman Henson example
root_dir = 'g:/HEDExamples/hed-examples/datasets/eeg_ds003645s_hed'
sidecar_path = os.path.join(root_dir, 'task-FacePerception_events.json')
tsv_path = os.path.join(root_dir, 'sub-002/eeg/sub-002_task-FacePerception_run-1_events.tsv')
data_name = 'eeg_ds003645s_hed'

# # Attention shift example
# root_dir = 'g:/HEDExamples/hed-examples/datasets/eeg_ds002893s_hed_attention_shift'
# sidecar_path = os.path.join(root_dir, 'task-AuditoryVisualShift_events.json')
# tsv_path = os.path.join(root_dir, 'sub-002/eeg/sub-002_task-AuditoryVisualShift_run-01_events.tsv')
# data_name = 'eeg_ds002893s_hed_attention_shift'

# Sternberg example
# root_dir = 'g:/HEDExamples/hed-examples/datasets/eeg_ds004117s_hed_sternberg'
# sidecar_path = os.path.join(root_dir, 'task-WorkingMemory_events.json')
# tsv_path = os.path.join(root_dir, 'sub-001/ses-01/eeg/sub-001_ses-01_task-WorkingMemory_run-1_events.tsv')
# data_name = 'eeg_ds004117s_hed_sternberg'

# Create the event summary
summary = summarize_tags(schema, tsv_path, sidecar=sidecar_path, name=data_name)
if summary is None:
print("Fatal errors in the input file. Cannot summarize tags.")
exit(1)

for the_key, the_item in summary.items():
if not the_item:
continue
print(f"{the_key}:")
for the_tag in the_item:
print(f" {the_tag}")