Skip to content

Commit

Permalink
Merge pull request #604 from VisLab/develop
Browse files Browse the repository at this point in the history
Minor updates to remodeling formats
  • Loading branch information
VisLab authored Feb 11, 2023
2 parents d5f43b3 + c9e4344 commit 14b2db1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
11 changes: 6 additions & 5 deletions hed/tools/remodeling/cli/run_remodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 3 additions & 12 deletions hed/tools/remodeling/operations/summarize_hed_tags_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions hed/tools/remodeling/operations/summarize_hed_type_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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 = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 14b2db1

Please sign in to comment.