Skip to content

MRG+1: store GUI config options - #3948

Merged
larsoner merged 18 commits into
mne-tools:masterfrom
christianbrodbeck:coreg-gui
Feb 17, 2017
Merged

larsoner merged 18 commits into
mne-tools:masterfrom
christianbrodbeck:coreg-gui

Conversation

@christianbrodbeck

Copy link
Copy Markdown
Member

@Eric89GXL This uses get_config and set_config to restore some options across GUI sessions. I can add other options that would be useful. From a cursory search I did not find where to retrieve the view size.

This reads and writes the config file multiple times; I assume that's not a huge deal but maybe we could make getting/setting of multiple keys more efficient. Reading with get_config() has the disadvantage that environment variables are ignored.

@larsoner

Copy link
Copy Markdown
Member

This reads and writes the config file multiple times

This should be a trivial overhead, assume YAGNI until we hit a problem

Reading with get_config() has the disadvantage that environment variables are ignored.

This shouldn't be the case. get_config should give preference to env vars. Are you sure?

@christianbrodbeck

Copy link
Copy Markdown
Member Author

Sorry that was ambiguous, I meant literally get_config(), i.e. without argument, which returns the contents of the config file :)

@larsoner

Copy link
Copy Markdown
Member

Actually we should fix get_config() to return the values in the env vars by first preference. That way we have get_config(X) == get_config()[X]

@christianbrodbeck

Copy link
Copy Markdown
Member Author

Ok, I'll do that in a separate PR

Comment thread mne/gui/_coreg_gui.py Outdated
str(info.object.mri_obj.opacity), set_env=False)
except Exception as error:
print("Error saving GUI configuration:\n%s" % (error,))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Eric89GXL it would be straight forward to also modify set_config() to accept a dict as first argument and write multiple entries in one call, should I?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd say not for now. It's easy enough (and rare enough) that we need to do for key, val in update_dict: set_config(key, val)

@christianbrodbeck christianbrodbeck changed the title ENH Coreg-GUI: store config options ENH guis: store config options Feb 4, 2017

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise LGTM, should be nice when using GUIs

Comment thread mne/gui/__init__.py Outdated
<http://www.slideshare.net/mne-python/mnepython-scale-mri>`_.
"""
config = get_config(home_dir=os.environ.get('_MNE_FAKE_HOME_DIR'))
prepare_bem = config.get('MNE_COREG_PREPARE_BEM', 'True') == 'True'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think because this goes to JSON we've been using 'true' instead of 'True'

Comment thread mne/gui/__init__.py Outdated
return frame.edit_traits(), frame
else:
frame.configure_traits()
return frame

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Refactor repeated code into function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not quite the same... above we have a view argument

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes but is it equivalent to view=None in the case it's not used?

Comment thread mne/gui/_backend.py Outdated


def _testing_mode():
"""Helper to determine if we're running tests."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI the suggested standard is to us imperative tone, so """Determine if we're...""" is preferred (but is a non-essential change). "Helper" is implied anyway by the private function-ness

Comment thread mne/gui/_coreg_gui.py Outdated
self.view_options_panel.edit_traits()

def save_config(self, home_dir=None):
"Write configuration values"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

triple-quotes, end with period

Comment thread mne/gui/_viewer.py
def plot(self):
"""Add the points to the mayavi pipeline"""
_scale = self.scene.camera.parallel_scale if not _testing_mode() else 1
_scale = self.scene.camera.parallel_scale

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did this and the other similar change fail on 4.4.0 and now works on 4.5.0?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought so, after tentatively removing some _testing_mode() checks... but travis looks like I might have been rash in removing all of them...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Travis seems to fail even on tests that don't even install mayavi, and it fails even though according to the log all tests passed, what does that mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, the GUI tests work on OS X but not on linux. Is it possible there is something about the environment? Mayavi's travis.yml starts /etc/init.d/xvfb here, but our travis.yml also seems to run it, just in a different way?

@larsoner

larsoner commented Feb 5, 2017 via email

Copy link
Copy Markdown
Member

@christianbrodbeck

Copy link
Copy Markdown
Member Author

I guess then we'll have to wait...

I was wondering whether it might also make sense to save SUBJECTS_DIR form the coregistration GUI. For current users it seems like it might break a workflow, but for new users it seems like it would be more logical. Or we could save it to MNE_COREG_SUBJECTS_DIR.

@larsoner

larsoner commented Feb 5, 2017 via email

Copy link
Copy Markdown
Member

@larsoner

larsoner commented Feb 6, 2017

Copy link
Copy Markdown
Member

Please no vulgarity in commit messages :)

@christianbrodbeck

Copy link
Copy Markdown
Member Author

lol sorry

@larsoner

larsoner commented Feb 6, 2017 via email

Copy link
Copy Markdown
Member

@codecov-io

codecov-io commented Feb 8, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #3948 into master will increase coverage by 0.09%.
The diff coverage is 72.67%.

@@            Coverage Diff             @@
##           master    #3948      +/-   ##
==========================================
+ Coverage   85.96%   86.05%   +0.09%     
==========================================
  Files         349      349              
  Lines       62519    62696     +177     
  Branches     9571     9592      +21     
==========================================
+ Hits        53742    53956     +214     
+ Misses       6090     6043      -47     
- Partials     2687     2697      +10

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bba62a5...cc0c590. Read the comment docs.

@christianbrodbeck
christianbrodbeck force-pushed the coreg-gui branch 2 times, most recently from 96f9f35 to e785a01 Compare February 8, 2017 03:01
Comment thread mne/commands/mne_coreg.py
options, args = parser.parse_args()

if options.low_res_head:
head_high_res = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably worth adding if options.high_res_head: raise ValueError(...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sys.exit(1) since it's a script?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think you need it, the raise will already exit

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I meant whether printing a reason and calling sys.exit() would be more appropriate since we're in a script and the conflicting arguments were specified in bash, not in a Python function call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it makes much difference. I'd do raise but it's up to you

@christianbrodbeck

Copy link
Copy Markdown
Member Author

The problem must be in test_kit2fiff_gui() because skipping it makes the linux test pass. The error itself is hard to locate because the test itself passes, and only at the end of all tests there is a message

Ran 654 tests in 1647.522s

OK (SKIP=22)
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  14 (X_GetGeometry)
  Resource id in failed request:  0x20007b
  Serial number of failed request:  32
  Current serial number in output stream:  32

But I can't find what the kit2fiff GUI is doing that the coreg GUI is not... Do you remember what exactly it is that has to be disabled?

@larsoner

Copy link
Copy Markdown
Member

X Error of failed request:

I have gotten this problem locally with Mayavi before. Not sure what causes it, other than it clearly being a bug with Mayavi/VTK. I'll see if I can replicate locally. Can you? Probably not since IIRC you're on OSX and this is an X server-related error...

@larsoner

Copy link
Copy Markdown
Member

I can't replicate it. I would personally leave the skip in there and deal with it later :)

But if you really want to try to fix it, this seems to be caused by some cleanup / exit routines. You could try extra hard to make sure everything is closed (look at Mayavi, VTK, etc. for such functions) and garbage-collected (import gc; gc.collect()) to try and emulate the end issue.

The most enlightening thing might be to do import faulthandler; faulthandler.enable() because this might give you a full traceback if you're lucky. In fact, we should probably cook up some simple custom nose plugin to do this anytime we run nosetests. I'll see how hard that is and open a PR, but in the meantime you can just put those lines in your failing test function.

@christianbrodbeck
christianbrodbeck force-pushed the coreg-gui branch 2 times, most recently from f10b21c to 831443a Compare February 10, 2017 20:14
@christianbrodbeck

Copy link
Copy Markdown
Member Author

Hm, no better error message...

@larsoner

Copy link
Copy Markdown
Member

Shoot. Well maybe just raise SkipTest on Linux for that test, then. At least we have an OSX CI now.

@larsoner

Copy link
Copy Markdown
Member

... but only do that if on Travis

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise LGTM, +1 for merge assuming it's ready from your end

Comment thread mne/commands/mne_coreg.py
options, args = parser.parse_args()

if options.low_res_head:
head_high_res = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think you need it, the raise will already exit

Comment thread mne/gui/_coreg_gui.py
"and 1, got %r" % (head_opacity,))
self._initial_head_opacity = head_opacity

subjects_dir = get_subjects_dir(subjects_dir)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're getting rid of this because the default is already taken elsewhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@christianbrodbeck

Copy link
Copy Markdown
Member Author

I added the ValueError to $ mne coreg. If CIs pass this is ready from my end.

@larsoner larsoner changed the title ENH guis: store config options MRG: store GUI config options Feb 15, 2017
@larsoner

Copy link
Copy Markdown
Member

LGTM, +1 for merge

Anyone else want to have a look?

@larsoner larsoner changed the title MRG: store GUI config options MRG+1: store GUI config options Feb 15, 2017
@larsoner
larsoner merged commit 4f677bc into mne-tools:master Feb 17, 2017
@larsoner

Copy link
Copy Markdown
Member

Thanks @christianbrodbeck

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.

3 participants