From c9e4344462cd26cada8db7cdcfc167c92d893e8a Mon Sep 17 00:00:00 2001 From: Kay Robbins <1189050+VisLab@users.noreply.github.com> Date: Fri, 10 Feb 2023 19:08:37 -0600 Subject: [PATCH] Minor updates to remodeling formats --- hed/tools/remodeling/cli/run_remodel.py | 11 ++++++----- .../operations/summarize_column_names_op.py | 2 +- .../operations/summarize_column_values_op.py | 2 +- .../operations/summarize_hed_tags_op.py | 15 +++------------ .../operations/summarize_hed_type_op.py | 10 ++++++---- .../operations/summarize_hed_validation_op.py | 3 ++- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/hed/tools/remodeling/cli/run_remodel.py b/hed/tools/remodeling/cli/run_remodel.py index 0b58bc66a..345f6d377 100644 --- a/hed/tools/remodeling/cli/run_remodel.py +++ b/hed/tools/remodeling/cli/run_remodel.py @@ -148,11 +148,12 @@ def main(arg_list=None): args, operations = parse_arguments(arg_list) if not os.path.isdir(args.data_dir): raise HedFileError("DataDirectoryDoesNotExist", f"The root data directory {args.data_dir} does not exist", "") - backup_man = BackupManager(args.data_dir) - if not backup_man.get_backup(args.backup_name): - raise HedFileError("BackupDoesNotExist", f"Backup {args.backup_name} does not exist. " - f"Please run_remodel_backup first", "") - backup_man.restore_backup(args.backup_name, args.task_names, verbose=args.verbose) + if args.backup_name: + backup_man = BackupManager(args.data_dir) + if not backup_man.get_backup(args.backup_name): + raise HedFileError("BackupDoesNotExist", f"Backup {args.backup_name} does not exist. " + f"Please run_remodel_backup first", "") + backup_man.restore_backup(args.backup_name, args.task_names, verbose=args.verbose) dispatch = Dispatcher(operations, data_root=args.data_dir, backup_name=args.backup_name, hed_versions=args.hed_versions) if args.use_bids: diff --git a/hed/tools/remodeling/operations/summarize_column_names_op.py b/hed/tools/remodeling/operations/summarize_column_names_op.py index a0257c577..f8b2e55c6 100644 --- a/hed/tools/remodeling/operations/summarize_column_names_op.py +++ b/hed/tools/remodeling/operations/summarize_column_names_op.py @@ -97,7 +97,7 @@ def _get_result_string(self, name, result, indent=BaseContext.DISPLAY_INDENT): if name == "Dataset": return self._get_dataset_string(result, indent) columns = result["Columns"][0] - return f"{indent}{indent}{name}: {str(columns['Column names'])}" + return f"{indent}{str(columns['Column names'])}" @staticmethod def _get_dataset_string(result, indent=BaseContext.DISPLAY_INDENT): diff --git a/hed/tools/remodeling/operations/summarize_column_values_op.py b/hed/tools/remodeling/operations/summarize_column_values_op.py index 9a08b8769..ed0166dd5 100644 --- a/hed/tools/remodeling/operations/summarize_column_values_op.py +++ b/hed/tools/remodeling/operations/summarize_column_values_op.py @@ -122,7 +122,7 @@ def _get_dataset_string(result, indent=BaseContext.DISPLAY_INDENT): @staticmethod def _get_individual_string(name, result, indent=BaseContext.DISPLAY_INDENT): - sum_list = [f"{name}: {result.get('Total events', 0)} events"] + sum_list = [f"Total events={result.get('Total events', 0)}"] cat_cols = result.get("Categorical columns", {}) if cat_cols: sum_list.append(ColumnValueSummaryContext._get_categorical_string(cat_cols, offset=indent, indent=indent)) diff --git a/hed/tools/remodeling/operations/summarize_hed_tags_op.py b/hed/tools/remodeling/operations/summarize_hed_tags_op.py index 58c9b872b..5870dbd65 100644 --- a/hed/tools/remodeling/operations/summarize_hed_tags_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_tags_op.py @@ -116,15 +116,6 @@ def _get_result_string(self, name, result, indent=BaseContext.DISPLAY_INDENT): if name == 'Dataset': return self._get_dataset_string(result, indent=indent) return self._get_individual_string(name, result, indent=indent) - # sum_list = [f"\n{name}\n{indent}Main tags[events,files]:"] - # for category, tags in result['Main tags'].items(): - # sum_list.append(f"{indent}{indent}{category}:") - # if tags: - # sum_list.append(f"{indent}{indent}{indent}{' '.join(self._tag_details(tags))}") - # if result['Other tags']: - # sum_list.append(f"\tOther tags[events,files]:") - # sum_list.append(f"{indent}{indent}{' '.join(self._tag_details(result['Other tags']))}") - # return "\n".join(sum_list) def _merge_all(self): all_counts = HedTagCounts('Dataset') @@ -137,14 +128,14 @@ def _merge_all(self): @staticmethod def _get_dataset_string(result, indent=BaseContext.DISPLAY_INDENT): - sum_list = [f"Dataset: {len(result.get('files', []))} files with a total of " - f"{result.get('total_events', 0)} events"] + sum_list = [f"Dataset: Total events={result.get('total_events', 0)} " + f"Total files={len(result.get('files', []))}"] sum_list = sum_list + HedTagSummaryContext._get_tag_list(result, indent=indent) return "\n".join(sum_list) @staticmethod def _get_individual_string(name, result, indent=BaseContext.DISPLAY_INDENT): - sum_list = [f"{name}: {result.get('total_events', 0)} events"] + sum_list = [f"Total events={result.get('total_events', 0)}"] sum_list = sum_list + HedTagSummaryContext._get_tag_list(result, indent=indent) return "\n".join(sum_list) diff --git a/hed/tools/remodeling/operations/summarize_hed_type_op.py b/hed/tools/remodeling/operations/summarize_hed_type_op.py index 06e1e4475..e93a83069 100644 --- a/hed/tools/remodeling/operations/summarize_hed_type_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_type_op.py @@ -124,11 +124,11 @@ def _get_result_string(self, name, result, indent=BaseContext.DISPLAY_INDENT): @staticmethod def _get_dataset_string(result, indent=BaseContext.DISPLAY_INDENT): details = result.get('details', {}) - sum_list = [f"Dataset: {len(details)} {result['type_tag']} types in {len(result.get('files', []))} files" - f" with a total of {result.get('total_events', 0)}"] + sum_list = [f"Dataset: Type={result['type_tag']} Type values={len(details)} " + f"Total events={result.get('total_events', 0)} Total files={len(result.get('files', []))}"] for key, item in details.items(): - str1 = f"{item['events']} events out of {item['total_events']} total events in {len(item['files'])} files" + str1 = f"{item['events']} event(s) out of {item['total_events']} total events in {len(item['files'])} file(s)" if item['level_counts']: str1 = f"{len(item['level_counts'])} levels in " + str1 if item['direct_references']: @@ -142,8 +142,10 @@ def _get_dataset_string(result, indent=BaseContext.DISPLAY_INDENT): @staticmethod def _get_individual_string(name, result, indent=BaseContext.DISPLAY_INDENT): - sum_list = [f"{indent}{name}: Type={result['type_tag']} Total events={result.get('total_events', 0)} "] details = result.get('details', {}) + sum_list = [f"Type={result['type_tag']} Type values={len(details)} " + f"Total events={result.get('total_events', 0)}"] + for key, item in details.items(): sum_list.append(f"{indent*2}{key}: {item['levels']} levels in {item['events']} events") str1 = "" diff --git a/hed/tools/remodeling/operations/summarize_hed_validation_op.py b/hed/tools/remodeling/operations/summarize_hed_validation_op.py index 789c222ba..b3789236f 100644 --- a/hed/tools/remodeling/operations/summarize_hed_validation_op.py +++ b/hed/tools/remodeling/operations/summarize_hed_validation_op.py @@ -110,7 +110,8 @@ def update_context(self, new_context): sidecar = new_context.get('sidecar', None) filtered_issues = [] if sidecar: - sidecar = Sidecar(files=new_context['sidecar'], name=os.path.basename(sidecar)) + if not isinstance(sidecar, Sidecar): + sidecar = Sidecar(files=new_context['sidecar'], name=os.path.basename(sidecar)) results["sidecar_issues"][sidecar.name] = [] sidecar_issues = sidecar.validate_entries(validator, check_for_warnings=self.check_for_warnings) filtered_issues = ErrorHandler.filter_issues_by_severity(sidecar_issues, ErrorSeverity.ERROR)