AllenInstitute / mouse_connectivity_models

Python package providing mesoscale connectivity models for mouse.
http://mouse-connectivity-models.readthedocs.io/en/latest/
Other
39 stars 14 forks source link

From Voxel To Coordinates #49

Closed FedeClaudi closed 4 years ago

FedeClaudi commented 4 years ago

Hi,

I've only recently started using this awesome research, so I might be missing something obvious here. Is there a way to know the coordinates in a given reference frame for one of the voxels in VoxelModel?

I would need this for visualisation and to sort voxels based on their spatial location, but couldn't figure out a way to do this.

Thank you!

kamdh commented 4 years ago

Can you explain in more detail what you mean by "coordinates in a given reference frame"? Each voxel in the Allen atlas is assigned a particular 3d coordinate, so you can easily map that way.

FedeClaudi commented 4 years ago

Hi,

Thanks for getting back to me and sorry if my question wasn't too clear, I'll try to rephrase it.

What I meant is this, the VoxelArray is loaded as a large (~400.000 by ~ 200.000) matrix representing the connectivity strength from a set of source voxels to a set of target voxels. So each element in this matrix represents the connection strength between two voxels (A and B). What I would like to know is if there is way to know the coordinates in the atlas of A and B. Now I know that there is Mask.map_masked_to_annotation that maps a 1d vector onto a 3d mask, but this doesn't do exactly what I need.

I hope the question is a bit more clear now. I guess in general I am confused about the shape and number of voxels in the VoxelArray. Given that in the docs it's described as a graph's adjacency matrix I would've expected it to be a square matrix, and I'm not sure I get where the number of rows and columns come from.

Thanks for taking the time, Federico

sjkoelle commented 4 years ago

Hi,

The reason that the matrix is not square, but rather has one dimension of length 2x the other, is that projections are categorized as coming from the same or different side as the injection (ipsi or contra). You can map from the VoxelArray to the ccf using the coordinates attribute of the Mask class. This object takes a major_brain_structure as an argument. The major_brain_structures are ['CB','CTXsp', 'HPF','HY','Isocortex', 'MB', 'MY', 'OLF', 'P', 'PAL','STR','TH'] (this ordering is findable in the code as well, and important). Once you load a Mask, for example, one corresponding to 'CTXsp', you will have the CCF coordinates of the voxels in that major brain structure in the mask.coordinates attribute. Ordering is consistent with the 200k x 400k table, but cumulative with respect to the major_brain_structure, so, for example, the first coordinate of Mask('CTXsp') will correspond to position len(Mask('CB').coordinates) in the big array.

Hope that helps, Sam

FedeClaudi commented 4 years ago

Hi,

That works, and it explains a lot. Thank you very much Sam!

For reference, the reason why I needed this is because I'm trying to figure out how to visualise voxel-wise projection strength:

Thank you! Federico