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

Dispatcher.__init__(operation_list[, ...])

Constructor for the dispatcher.

Dispatcher.errors_to_str(messages[, title, sep])

Return an error string representing error messages in a list.

Dispatcher.get_data_file(file_designator)

Get the correct data file give the file designator.

Dispatcher.get_schema(hed_versions)

Return the schema objects represented by the hed_versions.

Dispatcher.get_summaries([file_formats])

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

Dispatcher.get_summary_save_dir()

Return the directory in which to save the summaries.

Dispatcher.parse_operations(operation_list)

Return a parsed a list of remodeler operations.

Dispatcher.post_proc_data(df)

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

Dispatcher.prep_data(df)

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

Dispatcher.run_operations(file_path[, ...])

Run the dispatcher operations on a file.

Dispatcher.save_summaries([save_formats, ...])

Save the summary files in the specified formats.

Attributes

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 valid 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]

Return an error string representing error messages in a list.

Parameters:
  • messages (list) – List of error dictionaries each representing a single error.

  • title (str) – If provided the title is concatenated at the top.

  • sep (str) – Character used between lines in concatenation.

Returns:

Single string representing the messages.

Return type:

str

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]

Return the schema objects represented by the hed_versions.

Parameters:

hed_versions (str, list, HedSchema, HedSchemaGroup) – If str, interpreted as a version number.

Returns:

Objects loaded from the hed_versions specification.

Return type:

HedSchema or HedSchemaGroup

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]

Return a parsed a list of remodeler operations.

Parameters:

operation_list (list) – List of JSON remodeler operations.

Returns:

List of Python objects containing parsed remodeler operations.

Return type:

list

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'