Dispatcher

class Dispatcher(operation_list, data_root=None, backup_name='default_back', hed_versions=None)[source]

Controller for applying operations to tabular files and saving the results.

Methods

hed.tools.remodeling.dispatcher.Dispatcher.__init__(...)

Constructor for the dispatcher.

hed.tools.remodeling.dispatcher.Dispatcher.errors_to_str(...)

hed.tools.remodeling.dispatcher.Dispatcher.get_data_file(...)

Get the correct data file give the file designator.

hed.tools.remodeling.dispatcher.Dispatcher.get_schema(...)

hed.tools.remodeling.dispatcher.Dispatcher.get_summaries([...])

Return the summaries in a dictionary of strings suitable for saving or archiving.

hed.tools.remodeling.dispatcher.Dispatcher.get_summary_save_dir()

Return the directory in which to save the summaries.

hed.tools.remodeling.dispatcher.Dispatcher.parse_operations(...)

hed.tools.remodeling.dispatcher.Dispatcher.post_proc_data(df)

Replace all nan entries with 'n/a' for BIDS compliance

hed.tools.remodeling.dispatcher.Dispatcher.prep_data(df)

Make a copy and replace all n/a entries in the data frame by np.NaN for processing.

hed.tools.remodeling.dispatcher.Dispatcher.run_operations(...)

Run the dispatcher operations on a file.

hed.tools.remodeling.dispatcher.Dispatcher.save_summaries([...])

Save the summary files in the specified formats.

Attributes

hed.tools.remodeling.dispatcher.Dispatcher.REMODELING_SUMMARY_PATH

Dispatcher.__init__(operation_list, data_root=None, backup_name='default_back', hed_versions=None)[source]

Constructor for the dispatcher.

Parameters:
  • operation_list (list) – List of unparsed operations.

  • data_root (str or None) – Root directory for the dataset. If none, then backups are not made.

  • hed_versions (str, list, HedSchema, or HedSchemaGroup) – The HED schema.

Raises:
  • HedFileError

    • If the specified backup does not exist.

  • ValueError

    • If any of the operations cannot be parsed correctly.

static Dispatcher.errors_to_str(messages, title='', sep='\n')[source]
Dispatcher.get_data_file(file_designator)[source]

Get the correct data file give the file designator.

Parameters:

file_designator (str, DataFrame) – A dataFrame or the full path of the dataframe in the original dataset.

Returns:

DataFrame after reading the path.

Return type:

DataFrame

Raises:

HedFileError

  • If a valid file cannot be found.

Notes

  • If a string is passed and there is a backup manager, the string must correspond to the full path of the file in the original dataset. In this case, the corresponding backup file is read and returned.

  • If a string is passed and there is no backup manager, the data file corresponding to the file_designator is read and returned.

  • If a Pandas DataFrame, return a copy.

static Dispatcher.get_schema(hed_versions)[source]
Dispatcher.get_summaries(file_formats=['.txt', '.json'])[source]

Return the summaries in a dictionary of strings suitable for saving or archiving.

Parameters:

file_formats (list) – List of formats for the context files (‘.json’ and ‘.txt’ are allowed).

Returns:

A list of dictionaries of summaries keyed to filenames.

Return type:

list

Dispatcher.get_summary_save_dir()[source]

Return the directory in which to save the summaries.

Returns:

the data_root + remodeling summary path

Return type:

str

Raises:

HedFileError

  • If this dispatcher does not have a data_root.

static Dispatcher.parse_operations(operation_list)[source]
static Dispatcher.post_proc_data(df)[source]

Replace all nan entries with ‘n/a’ for BIDS compliance

Parameters:

df (DataFrame) – The DataFrame to be processed.

Returns:

DataFrame with the ‘np.NAN replaced by ‘n/a’

Return type:

DataFrame

static Dispatcher.prep_data(df)[source]

Make a copy and replace all n/a entries in the data frame by np.NaN for processing.

Parameters:

df (DataFrame) –

Dispatcher.run_operations(file_path, sidecar=None, verbose=False)[source]

Run the dispatcher operations on a file.

Parameters:
  • file_path (str or DataFrame) – Full path of the file to be remodeled or a DataFrame

  • sidecar (Sidecar or file-like) – Only needed for HED operations.

  • verbose (bool) – If true, print out progress reports

Returns:

The processed dataframe.

Return type:

DataFrame

Dispatcher.save_summaries(save_formats=['.json', '.txt'], individual_summaries='separate', summary_dir=None, task_name='')[source]

Save the summary files in the specified formats.

Parameters:
  • save_formats (list) – A list of formats [“.txt”, .”json”]

  • individual_summaries (str) – “consolidated”, “individual”, or “none”.

  • summary_dir (str or None) – Directory for saving summaries.

  • task_name (str) – Name of task if summaries separated by task or “” if not separated.

Notes

The summaries are saved in the dataset derivatives/remodeling folder if no save_dir is provided.

Notes

  • “consolidated” means that the overall summary and summaries of individual files are in one summary file.

  • “individual” means that the summaries of individual files are in separate files.

  • “none” means that only the overall summary is produced.

Dispatcher.REMODELING_SUMMARY_PATH = 'remodel/summaries'