Skip to content

Instantly share code, notes, and snippets.

@danlurie
Last active December 13, 2019 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlurie/691d0cea1b2c74b227e11d32147e9823 to your computer and use it in GitHub Desktop.
Save danlurie/691d0cea1b2c74b227e11d32147e9823 to your computer and use it in GitHub Desktop.
Python Surface Plotting
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BraINstinct0
Copy link

BraINstinct0 commented Dec 13, 2019

When I tried to reproduce this notebook, the colors are exactly opposite of what's shown here.
Plotting with -X[idx] instead of X[idx] seems to give exactly the same output as one shown here,
so either nilearn(or other packages) slightly changed its behavior, or the notebook is not actually the final run result.
Maybe worth checking out?

Edit: Also (when values of X is sign-reversed) in the second(medial) plot,
image
the corpus callosum region shows as dark green not gray.

@danlurie
Copy link
Author

danlurie commented Dec 13, 2019

Hi! I think there are two things going on here:

  1. The sign of the diffusion embedding gradient is arbitrary, and will randomly flip each time the algorithm is run (unless you set a random seed). I forgot that the notebook doesn't actually do the embedding. Not sure what's happening; I'll need to look into it as well.
  2. I would need to dig a bit, but it looks like plot_surf has changed how it handles (exactly) zero values (which are areas of the surface mesh for which there is no data). In my gist, they show up as grey, whereas for you they're showing up as the middle color of the colormap. The latter is the behavior I also currently see in nilearn. A quick way to fix this (based again on the fact that the gradient sign and values are arbitrary), is:
from sklearn import preprocessing

scaler = preprocessing.MinMaxScaler(feature_range=(0.00001, 1)
ed_scaled = scaler.fit_transform(ed.reshape(-1, 1))[:, 0]

Then, when plotting: use vmin=0, vmax=1.0, threshold=0.00001. This will avoid coloring the empty areas.

@BraINstinct0
Copy link

BraINstinct0 commented Dec 13, 2019

Didn't expect feedback to happen this quick!
For replication I (first flipped the sign of ed then) applied the scaler.

ed = -np.loadtxt('./ _insert_appropriate_location_ /LG400_Med.txt')
scaler = preprocessing.MinMaxScaler(feature_range=(0.00001, 1))
ed_scaled = scaler.fit_transform(ed.reshape(-1, 1))[:, 0]

Now, the result shows as below:
image image

I think it is (sort of) finally replicated well! (Used data from LG400_Med.txt on your gist)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment