119 lines
4.2 KiB
Python
119 lines
4.2 KiB
Python
"""
|
|
Filename: participantbrain.py
|
|
Description: Logic for the Participant Brain analysis window
|
|
|
|
Author: Tyler de Zeeuw
|
|
License: GPL-3.0
|
|
"""
|
|
|
|
# External library imports
|
|
from flares import brain_3d_visualization, brain_landmarks_3d
|
|
from src.shared.flaresbasewidget import ParticipantUIMixin, FlaresBaseWidget
|
|
from src.shared.shareddata import APP_NAME
|
|
|
|
|
|
PARAMETERIZED_INDEXES = {
|
|
0: [
|
|
{
|
|
"key": "show_optodes",
|
|
"label": "Determine what is rendered above the brain. Valid values are 'sensors', 'labels', 'none', 'all'.",
|
|
"default": "all",
|
|
"type": str,
|
|
},
|
|
{
|
|
"key": "show_brodmann",
|
|
"label": "Show common brodmann areas on the brain.",
|
|
"default": "True",
|
|
"type": bool,
|
|
}
|
|
],
|
|
1: [
|
|
{
|
|
"key": "show_optodes",
|
|
"label": "Determine what is rendered above the brain. Valid values are 'sensors', 'labels', 'none', 'all'.",
|
|
"default": "all",
|
|
"type": str,
|
|
},
|
|
{
|
|
"key": "t_or_theta",
|
|
"label": "Specify if t values or theta values should be plotted. Valid values are 't', 'theta'",
|
|
"default": "theta",
|
|
"type": str,
|
|
},
|
|
{
|
|
"key": "show_text",
|
|
"label": "Display informative text on the top left corner. THIS DOES NOT WORK AND SHOULD BE LEFT AT FALSE",
|
|
"default": "False",
|
|
"type": bool,
|
|
},
|
|
{
|
|
"key": "brain_bounds",
|
|
"label": "Graph Upper/Lower Limit",
|
|
"default": "1.0",
|
|
"type": float,
|
|
}
|
|
],
|
|
}
|
|
|
|
|
|
class ParticipantBrainViewerWidget(ParticipantUIMixin, FlaresBaseWidget):
|
|
def __init__(self, haemo_dict, cha_dict):
|
|
super().__init__("ParticipantBrain")
|
|
self.setWindowTitle(f"Participant Brain Viewer - {APP_NAME.upper()}")
|
|
self.haemo_dict = haemo_dict
|
|
self.cha_dict = cha_dict
|
|
|
|
self.setup_participant_ui(["0 (Brain Landmarks)", "1 (Brain Activity Visualization)",])
|
|
|
|
|
|
def process_request(self):
|
|
|
|
request = self.get_common_request_data(PARAMETERIZED_INDEXES)
|
|
if request is None:
|
|
return
|
|
|
|
(selected_event, selected_file_paths, selected_indexes, param_values,) = request
|
|
|
|
# Pass the necessary arguments to each method
|
|
for file_path in selected_file_paths:
|
|
haemo_obj = self.haemo_dict.get(file_path)
|
|
|
|
if selected_event:
|
|
participant_events = set(haemo_obj.annotations.description)
|
|
if selected_event not in participant_events:
|
|
print(f"Skipping {self.participant_map[file_path]}: Event '{selected_event}' not found.")
|
|
continue
|
|
|
|
if haemo_obj is None:
|
|
raise Exception("How did we get here?")
|
|
|
|
cha = self.cha_dict.get(file_path)
|
|
|
|
for idx in selected_indexes:
|
|
if idx == 0:
|
|
|
|
params = param_values.get(idx, {})
|
|
show_optodes = params.get("show_optodes", None)
|
|
show_brodmann = params.get("show_brodmann", None)
|
|
|
|
if show_optodes is None or show_brodmann is None:
|
|
print(f"Missing parameters for index {idx}, skipping.")
|
|
continue
|
|
|
|
brain_landmarks_3d(haemo_obj, show_optodes, show_brodmann)
|
|
|
|
elif idx == 1:
|
|
params = param_values.get(idx, {})
|
|
show_optodes = params.get("show_optodes", None)
|
|
t_or_theta = params.get("t_or_theta", None)
|
|
show_text = params.get("show_text", None)
|
|
brain_bounds = params.get("brain_bounds", None)
|
|
|
|
if show_optodes is None or t_or_theta is None or show_text is None or brain_bounds is None:
|
|
print(f"Missing parameters for index {idx}, skipping.")
|
|
continue
|
|
|
|
brain_3d_visualization(haemo_obj, cha, selected_event, t_or_theta=t_or_theta, show_optodes=show_optodes, show_text=show_text, brain_bounds=brain_bounds)
|
|
|
|
else:
|
|
print(f"No method defined for index {idx}") |