How to save the movie

  • MNE version:0.22.0
  • operating system: Windows 10

Hello! I am new with fnirs, and I hope someone kind could help me. I want to project the blood oxygen onto the model and save it as movie, also showing the optrodes and detectors.
I noticed that ,in the visual window as below, the place I circled is save movie, but it doesn’t work when I click on it.This visualization is exactly what I want, so I am wondering if there is someway to save it as a movie.I pasted my code below.

import numpy as np
import mne
import os.path as op
import pandas as pd
import mne_nirs
from mne_nirs.experimental_design import make_first_level_design_matrix
from mne_nirs.statistics import (run_glm, statsmodels_to_results)
from mne_nirs.channels import (get_long_channels, get_short_channels)
from mne_nirs.visualisation import plot_glm_surface_projection

raw_intensity = mne.io.read_raw_snirf("sub-01_task-tapping_nirs.snirf").load_data()
raw_intensity.annotations.description[:] = [
    d.replace('/', '_') for d in raw_intensity.annotations.description]
raw_od = mne.preprocessing.nirs.optical_density(raw_intensity)
raw_haemo = mne.preprocessing.nirs.beer_lambert_law(raw_od, ppf=0.1)
raw_haemo.resample(0.3)

short_chs = get_short_channels(raw_haemo)  
raw_haemo = get_long_channels(raw_haemo)

design_matrix = make_first_level_design_matrix(raw_haemo,
                                               drift_model='cosine', 
                                               high_pass=0.005,  
                                               hrf_model='spm', 
                                               stim_dur=5.0 )

design_matrix["ShortHbO"] = np.mean(short_chs.copy().pick(
                                    picks="hbo").get_data(), axis=0)
design_matrix["ShortHbR"] = np.mean(short_chs.copy().pick(
                                    picks="hbr").get_data(), axis=0)

glm_est = run_glm(raw_haemo, design_matrix)
cha = glm_est.to_dataframe()
cha["ID"] = 'subject'
cha["theta"] = [t * 1.e6 for t in cha["theta"]]
df_cha = pd.DataFrame()  
df_cha = pd.concat([df_cha, cha], ignore_index=True)
ch_summary = df_cha.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)

brain = plot_glm_surface_projection(raw_haemo.copy().pick("hbo"), model_df, colorbar=True)
brain.save_movie('1.mp4',time_dilation=20, tmin=0.05, tmax=0.16, framerate=10,
                  interpolation='linear', time_viewer=True)
brain.add_sensors(raw_haemo.info, trans='fsaverage', fnirs=['channels', 'pairs', 'sources', 'detectors'])

If the visualizations currently in use can not be saved as movie, can someone tell me about other ways to achieve my desired effect? I would be very grateful. :smiley:

do you get any error message in the console / terminal?

Alex

The UI is obviously broken (it’s a known bug that has existed for a long time now); are you sure the click actually “gets through” to the “Save Movie” button? Otherwise, there might be a keyboard shortcut to execute the same action; I think you can get a list of those by clicking on the question-mark button in the right corner of the toolbar.

Richard

Hi, Alex. Sorry, I forgot to paste the error message.
When I click the “Save Movie” button, an error message appears.

ValueError: No time points selected
    self.dlg_accepted.emit(filename)

And when I run the code of save movie , another error message appears.

brain = plot_glm_surface_projection(raw_haemo.copy().pick("hbo"), model_df, colorbar=True)
brain.save_movie('1.mp4',time_dilation=20, tmin=0.05, tmax=0.16, framerate=10,
                  interpolation='linear', time_viewer=True)

ValueError: tmax=0.16 is greater than the lastest time point (0,0)

I think the processed data does not contain the time data, so it can not be saved as a movie. I don’t know how to modify the function to save the time data while processing the data.

Hi ,Richard! Thank you for your advince. I am sure I click the “save movie” button.
Since the error message occurred when click the button is “ValueError: No time points selected”,I think the reason why it can not be saved as a movie is that there is no time data in the processed data, so I wonder if there are any other visual methods other than using the method under this link " Group Level GLM Analysis — MNE-NIRS 0.6.0 documentation :smiley:

1 Like

Hi, do you have a new solution now? I now hope to be able to display a 3D map of time-related brain activity.