danjgale / surfplot

A package for publication-ready brain surface figures
https://surfplot.readthedocs.io/en/latest/
Other
53 stars 14 forks source link

Show custom views #1

Open danjgale opened 3 years ago

danjgale commented 3 years ago

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 commented 3 years ago

WIll be added for 0.0.2a

danjgale commented 2 years ago

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:

danjgale commented 2 years ago

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.