Skip to content

refactor commands/scripts to expose only one named mne #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2013

Conversation

agramfort
Copy link
Member

as suggested by @yarikoptic

else:
cmd = sys.argv[1]
cmd_path = op.join(mne_bin_dir, 'commands', 'mne_%s.py' % cmd)
cmd = cmd_path + " " + " ".join(sys.argv[2:])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might lead to various unpleasant side effects happen there are spaces in the arguments etc. I guess it would be better to use subprocess.Popen or may be runpy would fit here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably the easiest would be to use 'subprocess.call([cmdpath] + sys.argv[2:])', not sure if adding ', shell=True' is needed here

note: updated to add cmdpath

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a convenience wrapper for subprocess.popen in utils.py that could probably be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok now using Popen and hacking the usage message to recommand the "mne browse_raw" syntax.

@agramfort
Copy link
Member Author

usage example

$mne browse_raw -h
Usage: mne browse_raw [options]

Options:
  -h, --help            show this help message and exit
  --raw=FILE            Input raw FIF file
  --proj=FILE           Projector file
  --eve=FILE            Events file
  -d DURATION, --duration=DURATION
                        Time window for plotting (sec)
  -t START, --start=START
                        Initial start time for plotting
  -n N_CHANNELS, --n_channels=N_CHANNELS
                        Number of channels to plot at a time
  -o ORDER, --order=ORDER
                        Order for plotting ('type' or 'original')
  -p PRELOAD, --preload=PRELOAD
                        Preload raw data (for faster navigaton)
  -s SHOW_OPTIONS, --show_options=SHOW_OPTIONS
                        Show projection options dialog
  --version             Return script version

@agramfort
Copy link
Member Author

should be good to go ...

@dengemann
Copy link
Member

Please wait and let me try tomorrow. I'll let you know how it goes.

import mne

mne_bin_dir = op.dirname(mne.__file__)
valid_commands = sorted(glob.glob(op.join(mne_bin_dir, 'commands', 'mne_*.py')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filtering is not needed here, os.listdir will be 50 % faster

@dengemann
Copy link
Member

The following commands fail on my box (error prevents print help)

1. flash_bem_model

Traceback (most recent call last):
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/commands/mne_flash_bem_model.py", line 136, in <module>
    flash05 = os.path.abspath(options.flash05)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/posixpath.py", line 352, in abspath
    if not isabs(path):
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/posixpath.py", line 61, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'


2. clean_eog_ecg

Traceback (most recent call last):
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/commands/mne_clean_eog_ecg.py", line 147, in <module>
    clean_ecg_eog(raw_in, raw_out, eog=eog, ecg=ecg)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/commands/mne_clean_eog_ecg.py", line 39, in clean_ecg_eog
    raw_in = mne.fiff.Raw(in_fif_fname)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/utils.py", line 360, in dec
    return function(*args, **kwargs)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/fiff/raw.py", line 89, in __init__
    fnames = [op.abspath(fnames)] if not op.isabs(fnames) else [fnames]
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/posixpath.py", line 61, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'


3. surf2bem

/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/datasets/utils.py:173: UserWarning: Sample dataset (version 0.6) is older than mne-python (version 0.7.git). If the examples fail, you may need to update the sample dataset by using force_update=True
  % (data_version, mne_version))
Traceback (most recent call last):
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/commands/mne_surf2bem.py", line 39, in <module>
    points, tris = mne.read_surface(options.surf)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/utils.py", line 360, in dec
    return function(*args, **kwargs)
  File "/Users/dengemann/anaconda/python.app/Contents/lib/python2.7/site-packages/mne/surface.py", line 564, in read_surface
    with open(fname, "rb") as fobj:
TypeError: coercing to Unicode: need string or buffer, NoneType found
Converting None to BEM FIF file.

@dengemann
Copy link
Member

However these particular scripts are broken themselves, it's not due to the new master command.

dengemann pushed a commit that referenced this pull request Nov 2, 2013
refactor commands/scripts to expose only one named mne
@dengemann dengemann merged commit 81c87a0 into mne-tools:master Nov 2, 2013
@dengemann
Copy link
Member

Thanks @agramfort ! I'll open new issues for the points I mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants