Open Islast opened 5 years ago
@Islast Could you please elaborate on the idea of ordered nodes?
# We're going to figure out the best way to plot these nodes
# so that they're sensibly on top of each other
sort_dict = {}
sort_dict['axial'] = 'z'
sort_dict['coronal'] = 'y'
sort_dict['sagittal'] = 'x'
node_order = np.argsort(df[sort_dict[orientation]]).values
# Now remove all the nodes that are not in the node_list
node_order = [ x for x in node_order if x in node_list ]
and later we use it here:
for node in node_order:
plot(node)
Just can not figure out by which criteria we are sorting. Do we sort in the ascending order by the values of x or y or z based on the orientation?
Hi @KirstieJane ,
Could you please explain what the parameter measure='module' to the plot_anatomical_network
means?
def plot_anatomical_network(G, **measure='module'**, orientation='sagittal', cmap_name='jet_r', continuous=False ...
And then we pass measure to setup_color_list
colors_list = setup_color_list(df,
cmap_name=cmap_name,
sns_palette=sns_palette,
measure=measure,
vmin=vmin,
vmax=vmax,
continuous=continuous)
def setup_color_list(df, cmap_name='jet', sns_palette=None, measure='module', continuous=False, vmax=1, vmin=0):
'''
Use a colormap to set colors for each value in the
sort_measure and return a list of colors for each node
# Figure out how many different colors you need
n = np.float(len(set(df[measure])))
And also how do we decide which color a node will have? (e.g. in the image above, nodes are displayed in 4 different colors)
I thought that measure is one of the nodal measures we calculate for our nodes (like degree, closeness, betweenness ...). And my best guess was that color and measure is connected. Depending on the measure we select a color for a node.
But does it mean that there will be as many colors as different measure for nodes?
ps. I have already created the above mentioned images, but at this moment all nodes are "green"
Hi @wingedRuslan!! This is so exciting that you can make the figures!
Let me try to answer some of the questions (brushing off my memory hat from 3 years ago 😆)
Do we sort in the ascending order by the values of x or y or z based on the orientation?
The short answer is, yes 😸
The nodes in a 2D image of the brain will overlap. For example when you're looking sideways at the brain (top left image) the nodes on the left and right sides will be on top of each other. The sorting in the code above says:
x
coordinate dictates the left to right position on the brain (see: http://www.fieldtriptoolbox.org/faq/how_are_the_different_head_and_mri_coordinate_systems_defined/#details-of-the-mni-coordinate-system)z
coordinates) and add the more superior ones on top of the others.If this isn't clear @wingedRuslan, please let me know - it might be easiest to cover in the weekly call when I can point and explain things in person!
I thought that measure is one of the nodal measures we calculate for our nodes (like degree, closeness, betweenness ...). And my best guess was that color and measure is connected. Depending on the measure we select a color for a node.
Yes! Exactly. In the code above I've chosen to color each node according to the module in which it is allocated by the community
partition. Do we have that in the code?
(Update: Looking at the code in scona/graph_measures.py#L279-L295 below, I think the answer is no 😄. But then I looked in scona/classes.py#L223-L241 and the class does calculate the module for each node. I've opened a new issue to see if we can document this better! https://github.com/WhitakerLab/scona/issues/123)
A few more notes on this function (which definitely needs more documentation, and can be found at https://github.com/WhitakerLab/scona/blob/38e5f3157d6864909a5cd480dce96f9c2a44337f/scona/scripts/make_figures.py#L2697)
df
: data frame containing a row for each node in the network (or subnetwork)cmap_name
: the matplotlib colourmap: https://matplotlib.org/examples/color/colormaps_reference.html. The code reads this colourmap in by default (L2710). If continous
is True
then it scales the colourmap to be between vmin
and vmax
. If continuous
is False
then The default value is jet
. If continuous
is False
then you split up the range of the colourmap into n
RGB values: cmap((i+0.5)/n)
sns_palette
: If this is passed then it is used to allocate discrete color values for the measures. Good for modules etc and when you know you've passed the right number of colors. Here's more information about palettes if you haven't seen them yet: https://seaborn.pydata.org/tutorial/color_palettes.htmlmeasure
: By default we colour in the nodes according to which module
they've been allocated to by the community
partition. This is quite nice as it will usually be quite a small number of groups (4 above) and so you can pick 4 separate colours from the continuous colourmap. If you passed something like degree
here, you'd want to make sure that the continuous
measure was True
so it could pick from across the colour spectrum.continuous
: Tells the arguments above how to deal with coming up with the colours.I hope that's helpful! Let me know if not!
Thank you @KirstieJane ! it is definitely helpful :)
I still have a vague picture about ordered nodes. So yeah, looking forward to a weekly call, if I would not understand before by myself.
it might be easiest to cover in the weekly call when I can point and explain things in person!
And speaking about measure='module', do we decide the color of a node based only on this measure, or we could pass any other measure?
What I do not understand is that if we pass, let's say, measure=betweenness we will have as many colors as there are distinct values of measure. So we will have 300 different colors for 300 different measures of nodes(number of nodes 300). Is it okay? Cause I think it would be quite messy.
I think in the case that you pass measure=betweenness you want a continuous cmap. I think the best way to handle this is to allow the user to specify which colourmap they want to use.
@KirstieJane, what do you think about the produced figures for measure = "module" ?
In this summary figure from the PNAS paper we have two lovely plots of the connectome. To recreate these we will need the following things:
N
these are stored atN.centroids
as a dict mapping nodes to (x,y,z) tuples.networkx.drawing
module.The code to create the original figure can be found here
I forget what the original colouring scheme for the nodes is. It may have been a data driven community analysis of the nodes (network communities can be accessed at
N.partition()
) or by some other scheme. Kirstie can let us know when she gets back, for now I think it's best to simply accept as an argument some dictionary mapping nodes to colours.Let me know if you have any concerns. Good luck and don't be afraid to ask questions!