Pythonで脳を研究する 12


引き続きPython MNEで色々と試している.

今回はfNIRSデータ(fnirs_motorデータセット)を前処理し、トリガ情報の注釈を整えた上で、センサ位置を被験者の脳表面(fsaverage)にオーバーレイ表示するプロットのサンプルコードを出してみた.

from itertools import compress
import matplotlib.pyplot as plt
import numpy as np
import mne

# fNIRSデータのパスを取得
fnirs_data_folder = mne.datasets.fnirs_motor.data_path()
fnirs_cw_amplitude_dir = fnirs_data_folder / "Participant-1"

# fNIRSの連続波(CW amplitude)データを読み込み
raw_intensity = mne.io.read_raw_nirx(fnirs_cw_amplitude_dir, verbose=True)
raw_intensity.load_data()

# --- 注釈の整備 ---
# 各刺激の持続時間を5秒に設定
raw_intensity.annotations.set_durations(5)

# トリガコードに意味のある名前を割り当てる
raw_intensity.annotations.rename(
    {"1.0": "Control", "2.0": "Tapping/Left", "3.0": "Tapping/Right"}
)

# トリガコード"15.0"(実験開始・終了の情報など不要なもの)を削除
unwanted = np.nonzero(raw_intensity.annotations.description == "15.0")
raw_intensity.annotations.delete(unwanted)

# --- センサ位置の表示 ---
# FreeSurferのサンプル被験者(fsaverage)のsubjectsディレクトリを指定
subjects_dir = mne.datasets.sample.data_path() / "subjects"

# 3D表示用のBrainオブジェクトを生成(背景を白、皮質の透明度0.5)
brain = mne.viz.Brain(
    "fsaverage", subjects_dir=str(subjects_dir), background="w", cortex="0.5"
)

# fNIRSのセンサ情報を、センサ(channels)だけでなく、
# ソース・デテクター、ペアなども表示する
brain.add_sensors(
    raw_intensity.info,
    trans="fsaverage",
    fnirs=["channels", "pairs", "sources", "detectors"],
)

# 視点を調整して表示(azimuth=20°, elevation=60°, 距離=400mm)
brain.show_view(azimuth=20, elevation=60, distance=400)

参考文献

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です