Skip to content

Plotting of comp morphology #432

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 6 commits into from
Oct 2, 2024
Merged

Plotting of comp morphology #432

merged 6 commits into from
Oct 2, 2024

Conversation

jnsbck
Copy link
Contributor

@jnsbck jnsbck commented Sep 27, 2024

I got side-tracked while working on a different PR and implemented plotting of the actual compartment structure:

The compartments are rendered in 3D and then the correct projection of the 3d mesh is plotted on whatever plane.

fig, ax = plt.subplots(2, 3, figsize=(10, 5))

for i, orientation in enumerate([np.array([1,1,2]), np.array([0,1,0.1]), np.array([0,0.1,1])]):
    plot_cylinder_projection(orientation, length=5, radius=1, center=np.array([0,0,0]), dims=[0,1], ax=ax[0,i])
    plot_cylinder_projection(orientation, length=5, radius=1, center=np.array([0,0,0]), dims=[1,2], ax=ax[1,i])
    ax[0,i].set_title(f"Orientation: {orientation}")
plt.show()

image

Hence the compartment radii and lengths are correctly reflected in the plot.
image

However, plotting an imported morphology looked weird for some reason.
image

While looking into this, I noticed two things:
Since the cylindrical compartments are straight, they run from one compartment edge to the other on a straight line. However, they model a potentially very zigzaggy branch/path structure. This means:
a) Assuming the comp center is at loc=0.5 along the path (currently how we do it), can put the comp center off axis.
b) Setting the comp length to the path length can result in comps which appear longer than the distance between their two endpoints.

This can be illustrated by adding a bit of noisy to the xyz coordinates of the example above.
image

Changing the compartment centers to be the center of the cylinder, already produces much better looking plots.
image

While I dont think changing b) makes sense (apart from for visualization maybe) I think changing a) might be a good idea.

Lemme know your thoughts.

PR is missing documentation, some cleanup and handling of single point cases.

@michaeldeistler
Copy link
Contributor

Hi Jonas, thanks, this can be super useful, especially for the radiuses.

I don't understand this sentence: Assuming the comp center is at loc=0.5 along the path (currently how we do it), can put the comp center off axis.

Afaik we currently have no notion of "comp center", so I don't understand what you mean.

@jnsbck
Copy link
Contributor Author

jnsbck commented Sep 27, 2024

We do in '_update_nodes_with_xyz'.
When the locations of the compartments are computed they are assumed to lie on the traced morphology (xyzr). For a branch that gets split into 4 comps this means the comp Centers are spaced at equidistant points along xyzr.

@michaeldeistler
Copy link
Contributor

Okay! Then yes, I think I would be pro changing the compartment centers to be the center of the cylinder.

@jnsbck
Copy link
Contributor Author

jnsbck commented Sep 30, 2024

Ready for review. Now cell.vis(type="volume") plots the compartments as seen below.
image
Not sure if "volume" is the best kwarg tho.

Q: Should I also add col kwarg for color like vis?

Copy link
Contributor

@michaeldeistler michaeldeistler left a comment

Choose a reason for hiding this comment

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

Thanks, awesome! Please add a test (just ensuring that there is no error) for a compartment, branch, cell, network, swc file, and net.cell(1).vis(...)

@jnsbck
Copy link
Contributor Author

jnsbck commented Oct 1, 2024

Thanks for the feedback!

Should I also add the col kwarg for consistency? #432 (comment)
@michaeldeistler ?

@michaeldeistler
Copy link
Contributor

Yes I think it would be great to have a col argument!

@jnsbck
Copy link
Contributor Author

jnsbck commented Oct 1, 2024

@michaeldeistler added tests and addressed all comments. Feel free to merge if you approve.

@michaeldeistler michaeldeistler merged commit 4fc75a1 into main Oct 2, 2024
1 check passed
@michaeldeistler michaeldeistler deleted the comp_volume_plotting branch October 2, 2024 10:26
@jnsbck jnsbck mentioned this pull request Oct 3, 2024
@jnsbck
Copy link
Contributor Author

jnsbck commented Oct 9, 2024

swc files to reproduce the effect of zigzaging morphologies on the comp lengths. file extension changed to txt since swc not supported

noisy_test.txt
test.txt

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.

2 participants