Operations

Core service modules for processing different types of HED data.

Base Operations

Common base classes and shared functionality for all operations.

class hedweb.base_operations.BaseOperations[source]

Bases: ABC

set_input_from_dict(input_dict)[source]
Sets the child class attributes based on input_dict.

Only sets attributes that exist.

Parameters:

input_dict (dict) – A dict object containing user data from a JSON service request.

abstract process() dict[source]

Perform the requested string processing action.

Returns:

The results in standard format.

Return type:

dict

Event operations

Process event files with HED annotations.

Performs operations on tabular data files using metadata from relevant sidecars if available.

class hedweb.event_operations.EventOperations(arguments=None)[source]

Bases: BaseOperations

Class to perform operations on events files.

__init__(arguments=None)[source]

Construct a ProcessEvents object to handle events form requests.

Parameters:

arguments (dict) – Dictionary with parameters extracted from form or service

process() dict[source]

Perform the requested action for the events file and its sidecar.

Returns:

A dictionary of results in the standard results format.

Return type:

dict

Raises:
  • HedFileError – If the schema was not valid.

  • HedFileError – If the command was not found or the input arguments were not valid.

assemble() dict[source]

Create a tabular file with the original positions in first column and a HED column.

Returns:

A dictionary of results in standard format including either the assembled events string or errors.

Return type:

dict

Notes

options include columns_included and expand_defs.

check_quality() dict[source]

Check the quality of the HED annotations for an events file.

Returns:

A dictionary of results in standard format including either the assembled events string or errors.

Return type:

dict

Notes: The options for this are
  • limit_errors (bool): If True, report at most 2 errors of each type

  • show_details (bool): If True, a detailed breakdown of the event annotation is displayed with error.

generate_sidecar() dict[source]

Generate a JSON sidecar template from a BIDS-style events file.

Returns:

A dictionary of results in standard format including either the generated sidecar string or errors.

Return type:

dict

Notes: Options are the columns selected. If None, all columns are used.

get_hed_objs() tuple[list, DefinitionDict][source]

Return the assembled objects and applicable definitions.

Returns:

A tuple containing a list of HED objects and a DefinitionDict of definitions.

Return type:

tuple[list, DefinitionDict]

remodel() dict[source]

Remodel a given events file.

Returns:

A dictionary pointing to results or errors.

Return type:

dict

Raises:

HedFileError – If the remodeling operations were not valid.

Notes: The options for this are
  • include_summaries (bool): If true and summaries exist, package event file and summaries in a zip file.

search() dict[source]

Create a three-column tsv file with event number, matched string, and assembled strings for matched events.

Returns:

A dictionary pointing to results or errors.

Return type:

dict

Notes: The options for this are

columns_included (list): A list of column names of columns to include. expand_defs (bool): If True, expand the definitions in the assembled HED. Otherwise, shrink definitions.

validate() dict[source]

Validate the events tabular input object and return the results.

Returns:

A dictionary containing results of validation in standard format.

Return type:

dict

Notes: The dictionary of options includes the following.
  • check_for_warnings (bool): If true, validation should include warnings. (default False)

Schema operations

Validate and manipulate HED schemas.

Performs operations on HED schemas, such as validation, comparison, and conversion.

class hedweb.schema_operations.SchemaOperations(arguments=None)[source]

Bases: BaseOperations

Class to perform operations on HED schemas.

__init__(arguments=None)[source]

Construct a SchemaOperations object to handle sidecar operations.

Parameters:

arguments (dict) – Dictionary with parameters extracted from form or service

process() dict[source]

Perform the requested action for the schema.

Returns:

A dictionary of results in the standard results format.

Return type:

dict

Raises:
  • HedFileError – If the command was not found or the input arguments were not valid.

  • HedFileError – If the schema is not found or cannot be loaded.

compare()[source]

Compare two schemas and return the differences. :returns: A dictionary of results in the standard results format. :rtype: dict

convert() dict[source]

Convert schema to multiple formats, save to temp dir, zip, and return as base64-encoded data.

Returns:

A dictionary of results in the standard results format.

Return type:

dict

validate() dict[source]

Run schema compliance for HED-3G.

Returns:

A dictionary of results in the standard results format.

Return type:

dict

static format_error(command, exception) dict[source]

Format an error for a schema command.

Parameters:
  • command (str) – The command that caused the error.

  • exception (HedFileError) – The exception that was raised.

Returns:

A dictionary of results in the standard results format.

Return type:

dict

hedweb.schema_operations.get_schema(schema_input=None, version=None, as_xml_string=None) HedSchema[source]

Return a HedSchema object from the given parameters.

Parameters:
  • schema_input (str or FileStorage or None) – Input url or file

  • version (str or None) – A schema version string to load, e.g. “8.2.0” or “score_1.1.0”

  • as_xml_string (str or None) – A schema in xml string format

Returns:

Schema

Return type:

HedSchema

Raises:

HedFileError

  • The schema can’t be loaded for some reason

Sidecar operations

Handle BIDS sidecar JSON files.

Performs operations on JSON sidecars, such as validation, conversion, extraction, and merging with spreadsheets.

class hedweb.sidecar_operations.SidecarOperations(arguments=None)[source]

Bases: BaseOperations

Class to perform operations on sidecars.

__init__(arguments=None)[source]

Construct a SidecarOperations object to handle sidecar operations.

Parameters:

arguments (dict or None) – Dictionary with parameters extracted from form or service

process() dict[source]

Perform the requested action for the sidecar.

Returns:

A dictionary of results in standard form.

Return type:

dict

Raises:
  • HedFileError – If the command was not found or the input arguments were not valid.

  • HedFileError – If the schema is not found or cannot be loaded.

  • HedFileError – If the sidecar is not found or cannot be loaded.

  • HedFileError – If a required spreadsheet is not found or cannot be loaded.

sidecar_convert() dict[source]

Convert a sidecar from long to short form or short to long form.

Returns:

A downloadable response dictionary

Return type:

dict

Notes

command (str): Either ‘to short’ or ‘to long’ indicating type of conversion. expand_defs (bool): If True, expand definitions when converting, otherwise do no expansion

sidecar_extract() dict[source]

Create a four-column spreadsheet with the HED portion of the JSON sidecar.

Returns:

A downloadable dictionary file or a file containing warnings

Return type:

dict

sidecar_merge() dict[source]

Merge an edited 4-column spreadsheet with JSON sidecar.

Returns:

A downloadable dictionary file or a file containing warnings

Return type:

dict

Raises:

HedFileError – If the spreadsheet is not provided or cannot be loaded.

Notes: The allowed option for merge is:

include_description_tags (bool): If True, a Description tag is generated from Levels and included.

sidecar_validate() dict[source]

Validate the sidecars and return the errors and/or a message in a dictionary.

Returns:

A dictionary of response values in standard form.

Return type:

dict

Notes: The allowed option for validate is:

check_for_warnings (bool): If True, check for warnings as well as errors.

Spreadsheet operations

Process tabular data with HED columns.

Performs operations on spreadsheets, such as validation, conversion, and extraction.

class hedweb.spreadsheet_operations.SpreadsheetOperations(arguments=None)[source]

Bases: BaseOperations

Class to perform operations on spreadsheets.

__init__(arguments=None)[source]

Construct a ProcessSpreadsheet object to handle spreadsheet operations.

Parameters:

arguments (dict) – Dictionary with parameters extracted from form or service

process() dict[source]

Perform the requested action for the spreadsheet.

Returns:

A dictionary of results from spreadsheet processing in standard form.

Return type:

dict

Raises:
  • HedFileError – If the command was not found or the input arguments were not valid.

  • HedFileError – If the schema is not found or cannot be loaded.

  • HedFileError – If the spreadsheet is not found or cannot be loaded.

spreadsheet_convert() dict[source]

Convert a spreadsheet long to short unless the command is not COMMAND_TO_LONG then converts to short

Returns:

A downloadable dictionary in standard format.

Return type:

dict

Notes: the allowed options are

command (str): Name of the command to execute. check_for_warnings (bool): If True, check for warnings.

spreadsheet_validate() dict[source]

Validates the spreadsheet.

Returns:

A dictionary containing results of validation in standard format.

Return type:

dict

Notes: The allowed options are

check_for_warnings (bool): Indicates whether validation should check for warnings as well as errors.

String operations

Validate and manipulate HED strings.

Performs operations on strings, such as validation and conversion between long and short forms.

class hedweb.string_operations.StringOperations(arguments=None)[source]

Bases: BaseOperations

Class to perform operations on spreadsheets.

__init__(arguments=None)[source]

Construct a StringOperations object to handle sidecar operations.

Parameters:

arguments (dict) – Dictionary with parameters extracted from form or service

process() dict[source]

Perform the requested string processing action.

Returns:

The results in standard format.

Return type:

dict

Raises:
  • HedFileError – If the command was not found or the input arguments were not valid.

  • HedFileError – If the schema is not found or cannot be loaded.

  • HedFileError – If the string list is empty or not provided.

convert() dict[source]

Convert a list of strings from long to short or from short to long.

Returns:

The results of string processing in standard format.

Return type:

dict

search() dict[source]

Return a list or a boolean

Returns:

A dictionary pointing to results or errors.

Return type:

dict

Notes: The options for this are

columns_included (list): A list of column names of columns to include. expand_defs (bool): If True, expand the definitions in the assembled HED. Otherwise, shrink definitions.

validate() dict[source]

Validate a list of strings and returns a dictionary containing the issues or a no issues message.

Returns:

The results in standard form.

Return type:

dict