Esempio n. 1
0
def test_run_plot_GLM_projection(requires_pyvista):
    raw_intensity = _load_dataset()
    raw_intensity.crop(450, 600)  # Keep the test fast

    design_matrix = make_first_level_design_matrix(raw_intensity,
                                                   drift_order=1,
                                                   drift_model='polynomial')
    raw_od = mne.preprocessing.nirs.optical_density(raw_intensity)
    raw_haemo = mne.preprocessing.nirs.beer_lambert_law(raw_od, ppf=0.1)
    glm_estimates = run_glm(raw_haemo, design_matrix)
    df = glm_to_tidy(raw_haemo, glm_estimates.data, design_matrix)
    df = df.query("Chroma in 'hbo'")
    df = df.query("Condition in 'A'")

    brain = plot_glm_surface_projection(raw_haemo.copy().pick("hbo"),
                                        df,
                                        clim='auto',
                                        view='dorsal',
                                        colorbar=True,
                                        size=(800, 700),
                                        value="theta",
                                        surface='white',
                                        subjects_dir=subjects_dir)
    assert type(brain) == mne.viz._brain.Brain
                       groups=ch_summary["ID"]).fit(method='nm')
model_df = statsmodels_to_results(ch_model,
                                  order=raw_haemo.copy().pick("hbo").ch_names)

# %%
# Plot surface projection of GLM results
# --------------------------------------
#
# Finally, we can project the GLM results from each channel to the nearest cortical surface
# and overlay the sensor positions and two different regions of interest.
# In this example we also highlight the premotor cortex and auditory association cortex
# in green and blue respectively.

# Plot the projection and sensor locations
brain = plot_glm_surface_projection(raw_haemo.copy().pick("hbo"),
                                    model_df,
                                    colorbar=True)
brain.add_sensors(raw_haemo.info,
                  trans='fsaverage',
                  fnirs=['channels', 'pairs', 'sources', 'detectors'])

# mark the premotor cortex in green
aud_label = [
    label for label in labels_combined if label.name == 'Premotor Cortex-lh'
][0]
brain.add_label(aud_label, borders=True, color='green')

# mark the auditory association cortex in blue
aud_label = [
    label for label in labels_combined
    if label.name == 'Auditory Association Cortex-lh'
Esempio n. 3
0
# respect to the underlying cortical locations. It is also possible to present
# the data by projecting the channel level GLM values to the nearest cortical
# surface. This can make it easier to understand the spatial aspects of your
# data. Note however, that this is not a complete forward model with photon
# migration simulations.
# In the figure below we project the group results from the two conditions
# to the cortical surface, and also present the contrast results in the same
# fashion.
# As in the topo plots above you can see that the activity is predominately
# contralateral to the side of finger tapping.


# Generate brain figure from data
clim = dict(kind='value', pos_lims=(0, 8, 11))
brain = plot_glm_surface_projection(raw_haemo.copy().pick("hbo"),
                                    con_model_df, clim=clim, view='dorsal',
                                    colorbar=True, size=(800, 700))
brain.add_text(0.05, 0.95, "Left-Right", 'title', font_size=16, color='k')

# Run model code as above
clim = dict(kind='value', pos_lims=(0, 11.5, 17))
for idx, cond in enumerate(['Tapping_Left', 'Tapping_Right']):

    # Run same model as explained in the sections above
    ch_summary = df_cha.query("Condition in [@cond]")
    ch_summary = ch_summary.query("Chroma in ['hbo']")
    ch_model = smf.mixedlm("theta ~ -1 + ch_name", ch_summary,
                           groups=ch_summary["ID"]).fit(method='nm')
    model_df = statsmodels_to_results(ch_model, order=raw_haemo.copy().pick("hbo").ch_names)

    # Generate brain figure from data