surfplot icon indicating copy to clipboard operation
surfplot copied to clipboard

Show custom views

Open danjgale opened this issue 4 years ago • 3 comments

Currently the views parameter takes one or more predefined views (e.g., 'lateral'). Under the hood these just map to a tuple of viewing angles, so there's no reason why tuples could also just be passed in as well.

The only extra step required would be flipping the sign of the y angle (second element in the tuple) for the right hemisphere. This could probably be all done in _set_layout(), or a sub-function to be place in _set_layout()

danjgale avatar Jul 13 '21 15:07 danjgale

WIll be added for 0.0.2a

danjgale avatar Jul 18 '21 16:07 danjgale

Hi @alyssadai! This is the issue I had in mind in our discussion.

As mentioned above, the views parameter currently only takes strings for predefined views. Those are mapped on orientations here. Downstream, this tuple is passed into the plotting here.

Passing in custom orientations would just mean that the user would be able to pass in a tuple directly instead of a string that maps to a tuple.

Some potential hurdles:

  • The views parameter gets broadcasted to the plotting array (basically, the grid of brains that are going to be plotted). I don't know if the function _broadcast() used here handles tuples.
  • As mentioned above, the sign of the second element in the tuple must be flipped for the right hemisphere to effectively mirror that of the left hemisphere. Basically you would have to check if the right hemisphere is being plotted, and if so, flip the sign. If not, you'll end up plotting from the same viewpoint as you would from the left hemisphere.
  • I didn't write surf.py, and admittedly I don't have a full grasp of that code. It's complicated! So it might take a good amount of time figuring out what works and what doesn't. And given that some of the code is convoluted at times, we might end up having to piece together our own hacks over top of it if needed. But if it works...

danjgale avatar Jan 04 '22 02:01 danjgale

Elaborating further:

The key line of code is here, as mentioned above.

if view[i, j] is not None:
    actor['orientation'] = orientations[view[i, j]]

the view variable is basically an array of whatever views the user passed, with the shape being determined by the layout (see here) . Rather than using the orientation variable to look up the respective tuple for the view, you could do something like:

if view[i, j] is not None:
    if isintance(view[i, j], str):
        actor['orientation'] = orientations[view[i, j]]
    else:
        actor['orientation'] = view[i, j] # pass in a tuple directly

Again, this depends if _broadcast() lets us pass in a tuple. As mentioned, _broadcast() basically converts the user's view to an array of views matching the layout.

The final piece of the puzzle is to handle the sign flip. I've done that lazily in the _set_layout() function here. I basically ask if the right hemisphere is plotted, and if so, swap the medial and lateral views. This amounts to flipping the sign. We might need to check if the user passed a tuple here instead of a string, and manually flip the sign.

danjgale avatar Jan 04 '22 03:01 danjgale