nipy / PySurfer

Cortical neuroimaging visualization in Python
https://pysurfer.github.io/
BSD 3-Clause "New" or "Revised" License
240 stars 97 forks source link

NF: added the option to specify alpha transparency for Brain binarized curvature rendering #159

Closed ctw closed 8 years ago

ctw commented 8 years ago

I have added the option to specify alpha transparency for Brain binarized curvature rendering. This can be useful when plotting foci in internal structures that are otherwise obscured by the brain surface. I had considered adding an "alpha" keyword to the Brain interface, but opted instead to allow for alpha transparency to be specified in the cortex keyword. I've implemented the chance in a way that should ensure backward compatibility with code specifying the cortex keyword as a 4-tuple or string (in these cases alpha defaults to 1.0). Using a new alpha transparency keyword for the Brain constructor might make this feature more accessible and I'm happy to change the implementation accordingly if that's preferred.

mwaskom commented 8 years ago

Using a new alpha transparency keyword for the Brain constructor might make this feature more accessible and I'm happy to change the implementation accordingly if that's preferred.

I think this would be my preference, but others can comment. It's also possible that opacity would be a more obvious parameter name.

mwaskom commented 8 years ago

Also one weird thing about implementing it through the curvature overlay is that I would think in most cases when you want a semi-transparent cortical mesh you don't want to be showing curvature (it will only complicate things).

ctw commented 8 years ago

I agree that it's a bit annoying that one can only specify alpha when curv is True in the current implementation (although by specifying sufficiently large absolute values for vmin and vmax one can effectively eliminate the contrast). Will change to use a keyword argument unless others object. It seems like "alpha" is the standard keyword argument for transparency (e.g., in add_data, add_annotation, add_label, and add_foci), that's why I chose it over opacity.

larsoner commented 8 years ago

+1 for keyword

ctw commented 8 years ago

On further reflection, I'd like to refactor the interface to Brain a bit more as follows:

I would like to deprecate the curv keyword in favor of allowing the cortex keyword to accept colors (in addition to the currently allowed inputs). If a color is specified, a solid brain (without the curvature) is drawn in that color. This would add the new functionality of allowing the user to specify the color a solid brain is drawn in and eliminate one keyword.

To summarize I propose the following changes:

Any thoughts?

agramfort commented 8 years ago

no objection

ctw commented 8 years ago

I've made the proposed changes. Please let me know if you have questions and/or suggestions for improvements.

mwaskom commented 8 years ago

Please make sure that you update the pysurfer script to reflect this changes and also that you add a note to the CHANGES file.

You will also want to look at the example scripts and make sure that none of them are using curv. Then you should probably add an example script to show a semi-transparent brain (perhaps demonstrating how to add subcortical foci). It would also be good to update at least one other example script to cover the new functionality for specifying the curvature values.

ctw commented 8 years ago

I've made the suggested changes. None of the existing example scripts were affected by the changes, but I've added a new one where alpha transparency is specified and a color is passed to cortex instead of a colormap.

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.4%) to 76.602% when pulling 5af2dad7c8b080b3554c327d042133c442ef839e on ctw:addalpha into d6350fd9192dd8d4cccfef92706dd5d7cb217010 on nipy:master.

mwaskom commented 8 years ago

Thanks! Would you mind showing the output of the example script here in the thread so I don't need to pull down your changes and build the docs?

mwaskom commented 8 years ago

I guess one thing to think about (though it goes against my earlier concerns that the cortex= parameter is too complicated: instead of (or complementing) the (colormap, min, max, reverse) tuple, a much better API might just be a pair of colors giving the color of sulci and gyri. It would be easy to take that pair and generate a colormap with our existing code. Does anyone have thoughts about this option?

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.5%) to 76.564% when pulling 48bee78e3e9ee7b5da9ae48bf86f9031a1ca414a on ctw:addalpha into d6350fd9192dd8d4cccfef92706dd5d7cb217010 on nipy:master.

ctw commented 8 years ago

I'm having trouble building the docs, at least partly, it seems, because I don't have freesurfer installed. Is there another way?

I like the option of being able to pass two colors to cortex, but the subsequent call to mlab.pipeline.surface expects the colormap to be specified by a string, so getting this to work would seem to require some refactoring.

mwaskom commented 8 years ago

I like the option of being able to pass two colors to cortex, but the subsequent call to mlab.pipeline.surface expects the colormap to be specified by a string, so getting this to work would seem to require some refactoring.

I think you can take a look in Brain.add_data to see how custom colormaps are set there.

larsoner commented 8 years ago

Otherwise the arguments look reasonable to me

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.5%) to 76.564% when pulling 498f27e471cfeff390d2fdc860fcbdc80f7d0bd8 on ctw:addalpha into d6350fd9192dd8d4cccfef92706dd5d7cb217010 on nipy:master.

ctw commented 8 years ago

I've added the option to pass a list of colors as argument for cortex as suggested by @mwaskom.

larsoner commented 8 years ago

Style:

https://travis-ci.org/nipy/PySurfer/jobs/144918615#L826

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.4%) to 76.601% when pulling de69f0a9bbabf5bb42a72d12b968e2ca0f32095c on ctw:addalpha into d6350fd9192dd8d4cccfef92706dd5d7cb217010 on nipy:master.

ctw commented 8 years ago

Thanks @Eric89GXL -- fixed now!

larsoner commented 8 years ago

Looks like there are a number of un-covered relevant lines, can you write some simple tests that at least touch them? Can't really test the output but it can at least make sure some inputs get parsed.

larsoner commented 8 years ago

Otherwise LGTM, +1 for merge. Example looks cool.

larsoner commented 8 years ago

Ahh good I see "small fix" in the commit message to justify my nitpick :)

larsoner commented 8 years ago

PEP8 line length

https://travis-ci.org/nipy/PySurfer/jobs/145638217#L826

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.07%) to 77.094% when pulling f44f5d7eb564c4b409bc72e0a9659d95b851ffea on ctw:addalpha into d6350fd9192dd8d4cccfef92706dd5d7cb217010 on nipy:master.

larsoner commented 8 years ago

@mwaskom feel free to merge if you're happy, too

ctw commented 8 years ago

@mwaskom any chance this can be merged?

mwaskom commented 8 years ago

Hi, sorry. I started my postdoc last month and also just adopted a dog so I'm dropping things left and right. But if this looks good to @Eric89GXL it looks good to me.