Plots and reports pipeline¶
This module creates plots and collects them into HTML reports based on TSV filens calculated and saved as derivatives for each metric.
- class meg_qc.plotting.meg_qc_plots.Deriv_to_plot(path: str, metric: str, deriv_entity_obj, raw_entity_name: str | None = None)[source]¶
A class to represent the derivatives to be plotted.
- path¶
The path to the TSV file.
- Type:
str
- metric¶
The metric to be plotted.
- Type:
str
- deriv_entity_obj¶
The entity object of the derivative created with ANCPBIDS.
- Type:
dict
- raw_entity_name¶
The name of the raw entity.
- Type:
str
- subject¶
The subject ID.
- Type:
str
- meg_qc.plotting.meg_qc_plots.create_categories_for_selector(entities: dict)[source]¶
Create categories based on what metrics have already been calculated and detected as ancp bids as entities in MEGqc derivatives folder.
- Parameters:
entities (dict) – A dictionary of entities and their subcategories.
- Returns:
categories – A dictionary of entities and their subcategories with modified names
- Return type:
dict
- meg_qc.plotting.meg_qc_plots.csv_to_html_report(raw_info_path: str, metric: str, tsv_paths: List, report_str_path: str, plot_settings)[source]¶
Create an HTML report from the CSV files.
- Parameters:
raw_info_path (str) – The path to the raw info object.
metric (str) – The metric to be plotted.
tsv_paths (List) – A list of paths to the CSV files.
report_str_path (str) – The path to the JSON file containing the report strings.
plot_settings (dict) – A dictionary of selected settings for plotting.
- Returns:
report_html_string – The HTML report as a string.
- Return type:
str
- meg_qc.plotting.meg_qc_plots.extract_raw_entities_from_obj(obj)[source]¶
Function to create a key from the object excluding the ‘desc’ attribute
- Parameters:
obj (ancpbids object) – An object from ancpbids.
- Returns:
A tuple containing the name, extension, and suffix of the object.
- Return type:
tuple
- meg_qc.plotting.meg_qc_plots.get_ds_entities(dataset, calculated_derivs_folder: str)[source]¶
Get the entities of the dataset using ancpbids, only get derivative entities, not all raw data.
- Parameters:
dataset (ancpbids object) – The dataset object.
calculated_derivs_folder (str) – The path to the calculated derivatives folder.
- Returns:
entities – A dictionary of entities and their subcategories.
- Return type:
dict
- meg_qc.plotting.meg_qc_plots.make_plots_meg_qc(dataset_path: str)[source]¶
Create plots for the MEG QC pipeline.
How it works: - Load the data set with ancp bids - Find what entities (sub, task, etc we have in Derivatives of that data set in MEG_QC folder - based on entities creates a selector for the user in the command line. Selector is sort of a gui, slect by clicking, scroll with buttons up/down - For selected entities finds all fitting TSVs, also raw info and ReportStrings in MEG_QC drivs folder using ancpbids - Arranges figure for every separate metric and referring to every original raw data file into a separate HTML report - Writes that HTML report into the file system with ancpbuds usong the recreated entities of original raw file. (Here we dont have access to raw file, only to derivatives, so the original entities are recareted using the search on the file name and such. Maybe there is a better way using ANCP bids to reacreate the raw entities, consult devs.)
- Parameters:
dataset_path (str) – A list of paths to the datasets.
- Returns:
tsvs_to_plot_by_metric – A dictionary of metrics and their corresponding TSV files.
- Return type:
dict
- meg_qc.plotting.meg_qc_plots.select_subcategory(subcategories: List, category_title: str, window_title: str = 'What would you like to plot? Click to select.')[source]¶
Create a checkbox list dialog for the user to select subcategories. Example: sub: 009, 012, 013
- Parameters:
subcategories (List) – A list of subcategories, such as: sub, ses, task, run, metric, mag/grad.
category_title (str) – The title of the category.
window_title (str) – The title of the checkbox list dialog, for visual.
- Returns:
results (List) – A list of selected subcategories.
quit_selector (bool) – A boolean indicating whether the user clicked Cancel.
- meg_qc.plotting.meg_qc_plots.selector(entities: dict)[source]¶
Creates a in-terminal visual selector for the user to choose the entities and settings for plotting.
Loop over categories (keys) for every key use a subfunction that will create a selector for the subcategories.
- Parameters:
entities (dict) – A dictionary of entities and their subcategories.
- Returns:
selected_entities (dict) – A dictionary of selected entities.
plot_settings (dict) – A dictionary of selected settings for plotting.
- meg_qc.plotting.meg_qc_plots.sort_tsvs_by_raw(tsvs_by_metric: dict)[source]¶
For every metric, if we got same raw entitites, we can combine derivatives for the same raw into a list. Since we collected entities not from raw but from derivatives, we need to remove the desc part from the name. After that we combine files with the same ‘name’ in entity_val objects in 1 list:
- Parameters:
tsvs_by_metric (dict) – A dictionary of metrics and their corresponding TSV files.
- Returns:
combined_tsvs_by_metric – A dictionary of metrics and their corresponding TSV files combined by raw entity
- Return type:
dict