Skip to content

ENH: Add kwargs in Brain.add_* and pass it to mayavi modules #276

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 30 commits into from
Nov 1, 2019
Merged

ENH: Add kwargs in Brain.add_* and pass it to mayavi modules #276

merged 30 commits into from
Nov 1, 2019

Conversation

DingkunLiu
Copy link
Contributor

Add kwargs in Brain.add_* and pass it to mayavi modules, so that we could directly manipulate mayavi display settings, like point resolution and overlay opacity.

…t we could directly manipulate mayavi display settings, like point resolution and overlay opacity.
@DingkunLiu DingkunLiu changed the title Feat: add kwargs in Brain.add_* and pass it to mayavi modules Feat: Add kwargs in Brain.add_* and pass it to mayavi modules Oct 3, 2019
@DingkunLiu DingkunLiu changed the title Feat: Add kwargs in Brain.add_* and pass it to mayavi modules ENH: Add kwargs in Brain.add_* and pass it to mayavi modules Oct 6, 2019
surfer/viz.py Outdated
@@ -932,6 +932,7 @@ def add_overlay(self, source, min=2, max="robust_max", sign="abs",
If None, it is assumed to belong to the hemipshere being
shown. If two hemispheres are being shown, an error will
be thrown.
kwargs: other mayavi surface arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should follow the NumPy docstring format, like:

kwargs : dict
    Other Mayavi surface arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it is not necessarily to be a dict here. How about changing it to "All additional keyword arguments are passed to the
mlab.pipeline.surface call." and specifying the name kwargs to mlab_kws?
Or I could just remove the ** symbols to make it a real dict?

Copy link
Contributor

@larsoner larsoner Oct 16, 2019

Choose a reason for hiding this comment

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

Let's do what nibabel does (except we don't need to escape the star characters)

https://github.com/nipy/nibabel/pull/827/files#diff-a1d0ba69368622536897ef9fe4aee05eR766

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a lot of detailed arguments for each mayavi function, so I think it is hard to list all the possible arguments. Could we just list some useful examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And one more thing, I think we should use the same name for the same argument in different functions. For example, the alpha in add_data() in mayavi is called opacity, so I think we should also specify this name in other functions and avoid it to appear in mlab_kws.

Copy link
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 we need to list all mayavi keywords, but it would be great if you could enable intersphinx so that the docs produce a link to the relevant mayavi api doc.

Nor do I think that we should have mlab_kws; the convention is to collect extra keyword arguments with **kwargs, and "mlab" isn't particularly informative about where the kwargs are actually going.

I'd also like to minimize changes unrelated to this specific enhancement. There is some inconsistency between pysurfer parameter names and mayavi ones, but aiming to fully streamline that would be a rabbit hole that is best to avoid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I would just do:

**kwargs : additional keyword arguments
    These are passed to the underlying :func:`mayavi.mlab.surface` call.

To figure out the links you can dump the intersphinx inventory with something like:

$ python -msphinx.ext.intersphinx http://docs.enthought.com/mayavi/mayavi/objects.inv > mayavi.txt

Then browse for relevant entries in mayavi.txt. Unfortunately they might not have entries for each function you actually want to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the documents, but unfortunately, those for the functions in mlab.pipeline are missing.

@codecov
Copy link

codecov bot commented Oct 18, 2019

Codecov Report

Merging #276 into master will increase coverage by 0.35%.
The diff coverage is 75%.

@@            Coverage Diff             @@
##           master     #276      +/-   ##
==========================================
+ Coverage   73.96%   74.31%   +0.35%     
==========================================
  Files           7        7              
  Lines        2535     2570      +35     
  Branches      511      514       +3     
==========================================
+ Hits         1875     1910      +35     
  Misses        482      482              
  Partials      178      178

surfer/viz.py Outdated
@@ -932,6 +932,10 @@ def add_overlay(self, source, min=2, max="robust_max", sign="abs",
If None, it is assumed to belong to the hemipshere being
shown. If two hemispheres are being shown, an error will
be thrown.
**kwargs: additional keyword arguments
These are passed to the underlying
:func:`mayavi.mlab.pipeline.surface` call.
Copy link
Contributor

@larsoner larsoner Oct 18, 2019

Choose a reason for hiding this comment

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

This extra indentation makes for weird spacing, see CircleCI doc artifact:

Suggested change
:func:`mayavi.mlab.pipeline.surface` call.
:func:`mayavi.mlab.pipeline.surface` call.

https://292-1551431-gh.circle-artifacts.com/0/html/generated/surfer.Brain.html#surfer.Brain.add_foci

Also many links do not work:

/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_annotation:37: WARNING: py:func reference target not found: mayavi.mlab.pipeline.surface
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_contour_overlay:42: WARNING: py:func reference target not found: mayavi.mlab.pipeline.contour_surface
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_data:105: WARNING: py:func reference target not found: mayavi.mlab.pipeline.surface
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_foci:41: WARNING: py:func reference target not found: mayavi.mlab.point3d
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_label:43: WARNING: py:func reference target not found: mayavi.mlab.pipeline.surface
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_morphometry:33: WARNING: py:func reference target not found: mayavi.mlab.pipeline.surface
/home/circleci/project/surfer/viz.py:docstring of surfer.Brain.add_overlay:29: WARNING: py:func reference target not found: mayavi.mlab.pipeline.surface

These should just be put in double-backticks to render as code. Or do the intersphinx dump and find a link that exists in the objects.inv.

Copy link
Contributor

Choose a reason for hiding this comment

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

At least one is just a typo, point3d should be points3d so it directs here

https://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#points3d

Fixing these errors is required to get CircleCI happy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late reply. I was a little overloaded these days. I just pushed a new commit. And, gladly, the errors seem to be solved.

@larsoner larsoner merged commit e85753e into nipy:master Nov 1, 2019
@larsoner
Copy link
Contributor

larsoner commented Nov 1, 2019

Thanks @DingkunLiu

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