annotation_util¶
Utilities to facilitate annotation of events in BIDS.
Functions
|
Return a list of the specified columns that are missing from a dataframe. |
|
Create sidecar-like dictionary from a 4-column dataframe. |
|
Extract all instances of specified tag from a tag_string. |
|
Create a sidecar column dictionary for column. |
|
Return a BIDS dataset object given a path to a dataset root. |
|
Return a 4-column dataframe of HED portions of sidecar. |
|
Update a JSON sidecar based on the hed_dict values. |
|
Convert a series to an integer factor list. |
|
Return a TabularInput a tsv string. |
|
Returns a list of HedString objects from a list of strings. |
|
Return a Sidecar from a sidecar as string or as a list of sidecars as strings. |
|
Convert data to an integer factor list. |
|
Return a list with the objects converted to string except for None elements. |
- check_df_columns(df, required_cols=('column_name', 'column_value', 'description', 'HED'))[source]¶
Return a list of the specified columns that are missing from a dataframe.
- Parameters:
df (DataFrame) – Spreadsheet to check the columns of.
required_cols (tuple) – List of column names that must be present.
- Returns:
List of column names that are missing.
- Return type:
list
- df_to_hed(dataframe, description_tag=True)[source]¶
Create sidecar-like dictionary from a 4-column dataframe.
- Parameters:
dataframe (DataFrame) – A four-column Pandas DataFrame with specific columns.
description_tag (bool) – If True description tag is included.
- Returns:
A dictionary compatible with BIDS JSON tabular file that includes HED.
- Return type:
dict
Notes
The DataFrame must have the columns with names: column_name, column_value, description, and HED.
- extract_tags(hed_string, search_tag)[source]¶
Extract all instances of specified tag from a tag_string.
- Parameters:
hed_string (str) – Tag string from which to extract tag.
search_tag (str) – HED tag to extract.
- Returns:
str: Tag string without the tags.
list: A list of the tags that were extracted, for example descriptions.
- Return type:
tuple
- generate_sidecar_entry(column_name, column_values=None)[source]¶
Create a sidecar column dictionary for column.
- Parameters:
column_name (str) – Name of the column.
column_values – List of column values.
- get_bids_dataset(data_root)[source]¶
Return a BIDS dataset object given a path to a dataset root.
- Parameters:
data_root (str) – Path to the BIDS dataset root.
- Returns:
BidsDataset
- hed_to_df(sidecar_dict, col_names=None)[source]¶
Return a 4-column dataframe of HED portions of sidecar.
- Parameters:
sidecar_dict (dict) – A dictionary conforming to BIDS JSON events sidecar format.
col_names (list, None) – A list of the cols to include in the flattened sidecar.
- Returns:
Four-column spreadsheet representing HED portion of sidecar.
- Return type:
DataFrame
Notes
The returned DataFrame has columns: column_name, column_value, description, and HED.
- merge_hed_dict(sidecar_dict, hed_dict)[source]¶
Update a JSON sidecar based on the hed_dict values.
- Parameters:
sidecar_dict (dict) – Dictionary representation of a BIDS JSON sidecar.
hed_dict (dict) – Dictionary derived from a dataframe representation of HED in sidecar.
- series_to_factor(series)[source]¶
Convert a series to an integer factor list.
- Parameters:
series (Series) –
- Returns:
list - contains 0’s and 1’s, empty, ‘n/a’ and np.nan are converted to 0.
- str_to_tabular(tsv_str, sidecar=None)[source]¶
Return a TabularInput a tsv string.
- Parameters:
tsv_str (str) – A string representing a tabular input.
sidecar – An optional Sidecar object.
- strs_to_hed_objs(hed_strings, hed_schema)[source]¶
Returns a list of HedString objects from a list of strings.
- Parameters:
hed_strings (string or list) – String or strings representing HED annotations.
hed_schema (HedSchema or HedSchemaGroup) – Schema version for the strings.
- Returns:
list of HedString objects or None.
- Return type:
list or None
- strs_to_sidecar(sidecar_strings)[source]¶
Return a Sidecar from a sidecar as string or as a list of sidecars as strings.
- Parameters:
sidecar_strings (string or list) – String or strings representing sidecars.
- Returns:
the merged sidecar from the list.
- Return type:
Sidecar or None