You can assign a segment number to each point on the streamline. And calculate the mean of that segment. For example, you choose 100 segments then the points of the streamline will be assigned to the closest segment. You can then take the average per segment. You can see here how to create those segments on a bundle https://dipy.org/documentation/1.4.1./examples_built/bundle_assignment_maps/#example-bundle-assignment-maps
from dipy.stats.analysis import assignment_map n = 100 indx = assignment_map(model_af_l, model_af_l, n) indx = np.array(indx)
indxhas segment number/label per point
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 = *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)
Links at the bottom of page https://dipy.org/documentation/1.4.1./documentation/ ("index" and "search page") are broken! Thanks!
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,
pam = savepeaks(os.path.join(Diffusion, 'peaks.pam5'), csapeaks, affine=np.eye(4))
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!