import numpy as np
from dipy.tracking.streamline import transform_streamlines
from dipy.stats.analysis import assignment_map
from scipy.ndimage.interpolation import map_coordinates
from dipy.io.image import load_nifti,
bundle #load your bundle
FA, affine = load_nifti(metric_file_name)
n = 100 #this is for total number of segments and won't change the number of points per streamline
indx = assignment_map(bundle, bundle, n)
indx = np.array(indx)
affine_r = np.linalg.inv(affine)
transformed_bundle = transform_streamlines(bundle, affine_r)
values = map_coordinates(FA, transformed_bundle._data.T, order=1)
# here indx has segment number/label per point of all streamlines
# values has FA value per point of all streamlines
#you can take an average of FA values based on which segment its corresponding point belongs to.
fa_mean = [0]*n
for i in range(n):
fa_mean[i] = np.mean(values[indx==i])
#plot the mean FA profile
import matplotlib.pyplot as plt
plt.plot(list(range(n)), fa_mean)
plt.title("FA mean profile")
plt.xlabel("Segment number")
plt.ylim([0,1])
plt.ylabel("FA")
# you can also visualize your bundle with n segments
colors = [np.random.rand(3) for si in range(n)]
disks_color = []
for i in range(len(indx)):
disks_color.append(tuple(colors[indx[i]]))
from dipy.viz import window, actor
scene = window.Scene()
scene.SetBackground(1, 1, 1)
scene.add(actor.line(bundle, fake_tube=True, colors=disks_color,
linewidth=6))
window.show(scene)
Hi!
Links at the bottom of page https://dipy.org/documentation/1.4.1./documentation/ ("index" and "search page") are broken! Thanks!
Hello everyone,
I am trying to run the following code:
from dipy.denoise.localpca import localpca
from dipy.denoise.pca_noise_estimate import pca_noise_estimate
from dipy.core.gradients import gradient_table
gtab = gradient_table(bvals, bvecs)
sigma = pca_noise_estimate(data, gtab, correct_bias=True, smooth=3)
denoised_arr = localpca(data, sigma, tau_factor=2.3, patch_radius=2)
using a dataset that is (100, 128, 3, 21) with the following bvals setup:
array([ 0., 1000., 1000., 1000., 1000., 1000., 1000., 0., 1000.,
1000., 1000., 1000., 1000., 1000., 0., 1000., 1000., 1000.,
1000., 1000., 1000.])
I keep receiving this error when I run though:
.../opt/anaconda3/lib/python3.7/site-packages/dipy/denoise/localpca.py:246: RuntimeWarning: invalid value encountered in true_divide
denoised_arr = thetax / theta
The resulting array is all np.nan's.
Any idea on how to go about this?
Hi all, I am working with a script that generates peaks using dipy's peaks_from_model() to track white matter pathways. I am attempting to save these peaks to a nifti from the .PAM5 file they are saved in using save_peaks(). My PeaksandMetrics object does not have the affine attribute, however even if I specify it in save_peaks() as the docs suggest it still fails to recognize it and gives the error: AttributeError: 'PeaksAndMetrics' object has no attribute 'affine'
. I am using dipy 0.15, python 2.7 . Here is my code, any advice is helpful since I am still fairly new to dipy:
`csapeaks = peaks_from_model(model=csa_model,
data=maskdata,
sphere=sphere,
relative_peak_threshold=.25,
min_separation_angle=40, mask=mask,
return_odf=True, normalize_peaks=True)
print('csa_peaks generated')
pam = savepeaks(os.path.join(Diffusion, 'peaks.pam5'), csapeaks, affine=np.eye(4))
peaks_toniftis(pam, Diffusion+'/'+PIDN+'peaksSH.nii',
Diffusion+'/'+PIDN+'peaksdirections.nii',
Diffusion+'/'+PIDN+'peaksindices.nii',
Diffusion+'/'+PIDN+'peaksvalues.nii',
Diffusion+'/'+PIDN+'GFA.nii', reshape_dirs=False)`
Hi, a question for the community: I would need to cluster streamline pairs rather than streamlines whilst still using QuickBundles. By this I mean that I have one streamline pair [A B], where A and B are individual streamlines, and one streamline pair [C D], where C and D are individual streamlines. What I want to do is calculate the distance between A and C, and B and D and cluster based on the total distance between the pairs as: totalDistance = distanceBetween(A, C) +distanceBetween(B, D).
If anyone has any idea of how to achieve this I would be very thankful to hear it!
Dear DIPY Community (@/all),
Do you need help to add a new feature on DIPY?
Do you want to share ideas or a moment with DIPY users and developers? or Do you have any questions about your DIPY code?
Feel free to join us on December 16th-17th during our Brainhack event! (https://brainhack.luddy.indiana.edu/)
Whatever your background or level of expertise is, you are encouraged to join us and participate: propose and discuss ideas, showcase demos, or contribute to activities initiated by others.
This free online event will be a good opportunity to connect with each other (registration is mandatory).
.
Some users already have proposed projects that you might be interested in:
You will find all the information (schedule, registration, ...) at https://brainhack.luddy.indiana.edu/