mne cannot use in command line

I want to open the raw MEG data recorded with MaxShield, but the data have not been processed with MaxFilter. So I use command line statements to process it
(mne maxfilter -i sample_audvis_raw.fif --st)
it shows the following error:
‘mne’ is not an internal or external command, nor is it a runnable program or batch file.

mne has been added to the environment variables
image

Why can’t I run mne from the command line in Win10?
Or is there another way I can do the MaxFilter process?

  • MNE version: 1.3
  • operating system: Windows 10

I’m not sure why the command line tool isn’t working for you, but you can load the maxshield-containing data and run maxwell filtering using

raw = mne.io.read_raw_fif(..., allow_maxshield=True)
raw_sss = mne.preprocessing.maxwell_filter(raw, ...)

Thank you for your answer!
But therein lies the problem.
When I use allow_maxshield=True and run maxwell filtering, the data will be distorted significantly.
Here are the links to the data I used OSF



This is the code I used

from mne.preprocessing import maxwell_filter
import matplotlib.pyplot as plt
from os import path as op
import pathlib
import mne

plt.ion()
#%% [1]
data_dir = pathlib.Path('E:/Notes/MEG/data/')
raw_path = data_dir / 'meg_2045_session2_raw.fif'

raw = mne.io.read_raw(raw_path, allow_maxshield=True)
raw.plot_psd().suptitle('raw_mc', horizontalalignment='left',verticalalignment='bottom')
raw.plot(title='raw')


#%% [2]
'''HPI frequencies'''
chpi_freqs, ch_idx, chpi_codes = mne.chpi.get_chpi_info(info=raw.info)
print(f'cHPI coil frequencies extracted from raw: {chpi_freqs} Hz')

#%% [3]
'''Estimating continuous head position'''

# Extract the HPI coil amplitudes as a function of time
chpi_amplitudes = mne.chpi.compute_chpi_amplitudes(raw)
# Compute time-varying HPI coil locations from these
chpi_locs = mne.chpi.compute_chpi_locs(raw.info, chpi_amplitudes)
# Compute head positions from the coil locations
head_pos = mne.chpi.compute_head_pos(raw.info, chpi_locs, verbose=True)

#%% [4]
mne.chpi.write_head_pos(data_dir / '2045_session1_head_poc.pos', head_pos)
#%% [5]
'''Visualizing continuous head position'''
mne.viz.plot_head_positions(
    head_pos, mode='field', destination=raw.info['dev_head_t'], info=raw.info)
# mne.viz.plot_head_positions(head_pos, mode='traces')
# mne.viz.plot_head_positions(head_pos, mode='field')

# #%% [6]
# '''Computing SNR of the HPI signal'''
# raw.crop(tmin=5, tmax=10)
# snr_dict = mne.chpi.compute_chpi_snr(raw)
# fig = mne.viz.plot_chpi_snr(snr_dict)

#%% [7]
# pos = mne.chpi.read_head_pos(data_dir / '2045_session1_head_poc.pos')
#%%
raw_sss = mne.preprocessing.maxwell_filter(
    raw, head_pos=head_pos, verbose=True)
raw_sss.plot(title='raw_sss')
raw_sss.plot_psd().suptitle('raw_mc', horizontalalignment='left',verticalalignment='bottom')

#%% 
raw_mc_path = data_dir / 'meg_2045_session1_mc.fif'

raw_mc = mne.io.read_raw(raw_mc_path)
raw_mc.plot(title='mc')
raw_mc.plot_psd().suptitle('raw_mc', horizontalalignment='left')

I don’t know why this happened, was there something wrong with the way I handled it?

import mne
raw = mne.io.read_raw_fif("meg_2045_session2_raw.fif", allow_maxshield=True)
noisy, flat = mne.preprocessing.find_bad_channels_maxwell(raw)  # <- this step was missing
raw.info['bads'] = noisy + flat                                 #    also this step
chpi_amplitudes = mne.chpi.compute_chpi_amplitudes(raw)
chpi_locs = mne.chpi.compute_chpi_locs(raw.info, chpi_amplitudes)
head_pos = mne.chpi.compute_head_pos(raw.info, chpi_locs)
raw_sss = mne.preprocessing.maxwell_filter(raw, head_pos=head_pos)

I’m not certain if that will fix it, but it’s a good thing to try. FYI, however: the command-line tools that ship as part of MNE-Python simply call the Python code under the hood, so they won’t give you different results. The MNE-C command-line tools might (but ideally should not).

cc @larsoner who might spot an error that I missed.

1 Like

You probably also want a mne.chpi.filter_chpi(raw) in there before running maxwell_filter in order to get rid of the cHPI signals

2 Likes

Hello,

Thank you very much. I used your method and successfully solved the problem.

Hello,

Thank you very much. I used your method and successfully solved the problem.