Advertisement
El_Chaderino

Clinical Q overlay

Dec 17th, 2023
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.11 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def plot_1020_electrodes():
  6.     fig, ax = plt.subplots(figsize=(8, 8))
  7.     ax.set_aspect('equal')
  8.     ax.axis('off')
  9.  
  10.     # Set up electrode locations
  11.     electrode_locations = {
  12.         'CZ': (0, 0),
  13.         'O1': (-2.11, -3.04),
  14.         'F3': (-2, 2),
  15.         'F4': (2, 2),
  16.         'FZ': (0, 2)
  17.     }
  18.  
  19.     # Plot modified head outline
  20.     head_outline = plt.Circle((0, 0), radius=4, edgecolor='black', facecolor='white', linewidth=1.5)
  21.     ax.add_artist(head_outline)
  22.  
  23.     # Plot electrode spots and text
  24.     electrode_texts = {}
  25.     for electrode, (x, y) in electrode_locations.items():
  26.         ax.plot(x, y, 'o', markersize=10, markerfacecolor='white', markeredgecolor='black', markeredgewidth=1.5)
  27.         electrode_texts[electrode] = ax.text(x, y, electrode, ha='center', va='center', fontsize=10, color='blue')
  28.  
  29.     # Add electrode areas and information
  30.     areas = {
  31.         'CZ': {
  32.             'Clinical Q': 'Vertex',
  33.             '10-20 System': 'CZ',
  34.             'Brodmann Area': 'Areas 4 and 6',
  35.             'Function': 'Motor cortex, supplementary motor area',
  36.             'Functional Info': 'The motor cortex in CZ area controls voluntary movements and is involved in motor planning and coordination.',
  37.             'Mental Health Issues': 'Imbalances in this area may be associated with motor-related disorders or difficulties in motor control.'
  38.         },
  39.         'O1': {
  40.             'Clinical Q': 'Left Occipital',
  41.             '10-20 System': 'O1',
  42.             'Brodmann Area': 'Area 17',
  43.             'Function': 'Primary visual cortex',
  44.             'Functional Info': 'The primary visual cortex in O1 area processes visual information received from the eyes.',
  45.             'Mental Health Issues': 'Disruptions in this area can affect visual perception and may be related to visual processing disorders or visual hallucinations.'
  46.         },
  47.         'F3': {
  48.             'Clinical Q': 'Left Frontal',
  49.             '10-20 System': 'F3',
  50.             'Brodmann Area': 'Area 6',
  51.             'Function': 'Motor cortex, language production',
  52.             'Functional Info': 'The motor cortex in F3 area controls voluntary movements, including those involved in language production.',
  53.             'Mental Health Issues': 'Imbalances in this area may contribute to difficulties in speech production or language-related disorders.'
  54.         },
  55.         'F4': {
  56.             'Clinical Q': 'Right Frontal',
  57.             '10-20 System': 'F4',
  58.             'Brodmann Area': 'Area 6',
  59.             'Function': 'Motor cortex, language production',
  60.             'Functional Info': 'The motor cortex in F4 area controls voluntary movements, including those involved in language production.',
  61.             'Mental Health Issues': 'Imbalances in this area may contribute to difficulties in speech production or language-related disorders.'
  62.         },
  63.         'FZ': {
  64.             'Clinical Q': 'Midline Frontal',
  65.             '10-20 System': 'FZ',
  66.             'Brodmann Area': 'Areas 9 and 10',
  67.             'Function': 'Prefrontal cortex, attention, emotional processing',
  68.             'Functional Info': 'The prefrontal cortex in FZ area plays a role in executive functions, attention, and emotional processing.',
  69.             'Mental Health Issues': 'Imbalances in this area may impact attention, impulse control, decision-making, and emotional regulation.'
  70.         }
  71.     }
  72.  
  73.     info_texts = []
  74.  
  75.     def on_click(event):
  76.         for electrode, (x, y) in electrode_locations.items():
  77.             if x - 0.5 < event.xdata < x + 0.5 and y - 0.5 < event.ydata < y + 0.5:
  78.                 if electrode in info_texts:
  79.                     info_texts.remove(electrode)
  80.                     plt.close(electrode)
  81.                 else:
  82.                     info = areas[electrode]
  83.                     clinical_q = info['Clinical Q']
  84.                     system_1020 = info['10-20 System']
  85.                     brodmann_area = info['Brodmann Area']
  86.                     function = info['Function']
  87.                     functional_info = info['Functional Info']
  88.                     mental_health_issues = info['Mental Health Issues']
  89.  
  90.                     function_text = f"Clinical Q: {clinical_q}\n10-20 System: {system_1020}\nBrodmann Area: {brodmann_area}\nFunction: {function}"
  91.                     functional_info_text = f"\n\nFunctional Information:\n{functional_info}"
  92.                     mental_health_issues_text = f"\n\nMental Health Issues:\n{mental_health_issues}"
  93.  
  94.                     info_texts.append(electrode)
  95.                     fig2, ax2 = plt.subplots(figsize=(6, 4))
  96.                     ax2.set_title(electrode)
  97.                     ax2.text(0.5, 0.5, function_text + functional_info_text + mental_health_issues_text,
  98.                              ha='center', va='center', fontsize=10, color='blue', wrap=True)
  99.                     ax2.axis('off')
  100.                     plt.show(block=False)
  101.  
  102.         fig.canvas.draw_idle()
  103.  
  104.     fig.canvas.mpl_connect('button_press_event', on_click)
  105.     plt.show()
  106.  
  107.  
  108. # Call the function to display the modified 10/20 electrode diagram
  109. plot_1020_electrodes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement