def test_run_plot_GLM_topo(): 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) fig = plot_glm_topo(raw_haemo, glm_estimates.data, design_matrix) # 5 conditions (A,B,C,Drift,Constant) * two chroma + 2xcolorbar assert len(fig.axes) == 12 # Two conditions * two chroma + 2 x colorbar fig = plot_glm_topo(raw_haemo, glm_estimates.data, design_matrix, requested_conditions=['A', 'B']) assert len(fig.axes) == 6 # Two conditions * one chroma + 1 x colorbar with pytest.warns(RuntimeWarning, match='Reducing GLM results'): fig = plot_glm_topo(raw_haemo.copy().pick(picks="hbo"), glm_estimates.data, design_matrix, requested_conditions=['A', 'B']) assert len(fig.axes) == 3 # One conditions * two chroma + 2 x colorbar fig = plot_glm_topo(raw_haemo, glm_estimates.data, design_matrix, requested_conditions=['A']) assert len(fig.axes) == 4 # One conditions * one chroma + 1 x colorbar with pytest.warns(RuntimeWarning, match='Reducing GLM results'): fig = plot_glm_topo(raw_haemo.copy().pick(picks="hbo"), glm_estimates.data, design_matrix, requested_conditions=['A']) assert len(fig.axes) == 2 # One conditions * one chroma + 0 x colorbar with pytest.warns(RuntimeWarning, match='Reducing GLM results'): fig = plot_glm_topo(raw_haemo.copy().pick(picks="hbo"), glm_estimates.data, design_matrix, colorbar=False, requested_conditions=['A']) assert len(fig.axes) == 1 # Ensure warning thrown if glm estimates is missing channels from raw glm_estimates_subset = { a: glm_estimates.data[a] for a in raw_haemo.ch_names[0:3] } with pytest.raises(RuntimeError, match="does not match regression"): plot_glm_topo(raw_haemo, glm_estimates_subset, design_matrix)
def test_run_plot_GLM_topo(): 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) glm_estimates = run_GLM(raw_haemo, design_matrix) fig = plot_glm_topo(raw_haemo, glm_estimates, design_matrix) # 5 conditions (A,B,C,Drift,Constant) * two chroma + 2xcolorbar assert len(fig.axes) == 12 fig = plot_glm_topo(raw_haemo, glm_estimates, design_matrix, requested_conditions=['A', 'B']) # Two conditions * two chroma + 2xcolorbar assert len(fig.axes) == 6
plt.hlines([0.0], 0, 2) ############################################################################### # Fit GLM to all data and view topographic distribution # ----------------------------------------------------- # # Lastly we can run the GLM analysis on all sensors and plot the result on a # topomap. # We see the same result as in the MNE tutorial, # that activation is largest # contralateral to the tapping side. Also note that HbR tends to be the # negative sof HbO as expected. glm_est = run_GLM(raw_haemo, design_matrix) plot_glm_topo(raw_haemo, glm_est, design_matrix, requested_conditions=['Tapping/Left', 'Tapping/Right']) ############################################################################### # # Compute contrasts # ----------------- # # We can also define a contrast as described in # `Nilearn docs <https://5874-1235740-gh.circle-artifacts.com/0/doc/_build/html/auto_examples/04_glm_first_level_models/plot_localizer_surface_analysis.html>`_ # and plot it. # Here we contrast the response to tapping on the left hand with the response # from tapping on the right hand. contrast_matrix = np.eye(design_matrix.shape[1]) basic_conts = dict([(column, contrast_matrix[i])
############################################################################### # Fit GLM to all data and view topographic distribution # ----------------------------------------------------- # # Lastly we can run the GLM analysis on all sensors and plot the result on a # topomap. # We see the same result as in the MNE tutorial, # that activation is largest # contralateral to the tapping side. Also note that HbR tends to be the # negative of HbO as expected. glm_est = run_GLM(raw_haemo, design_matrix) plot_glm_topo(raw_haemo, glm_est, design_matrix, requested_conditions=['Tapping/Left', 'Tapping/Right']) ############################################################################### # # Note that the topographic visualisation is a high level representation # of the underlying data. This visual representation fits a smoothed surface # to the data and makes many assumptions including that the data is # spatially smooth and that the sensors sufficiently cover the scalp surface. # These assumptions can be violated with fNIRS due to the improved spatial # sensitivity (relative to EEG) and typically low number of sensors that are # unevenly distributed over the scalp. # As such, researchers should understand the underlying data and ensure that # the figure accurately reflects the effect of interest. #