Closed ElChiriquiski closed 8 months ago
Hello I created a python code to rectify the bvec file:
import os import numpy as np
def transpose_bvecs_in_directory(directory_path, output_directory=None, delimiter=None): if not os.path.exists(directory_path): raise ValueError('Directory does not exist: ' + directory_path)
if output_directory is None:
output_directory = directory_path
for filename in os.listdir(directory_path):
if filename.endswith(".bvec"):
bvecs_filepath = os.path.join(directory_path, filename)
output_filepath = os.path.join(output_directory, "transposed_" + filename)
# Transpose and save with the specified delimiter and format
bvecs = np.loadtxt(bvecs_filepath, delimiter=delimiter).T
np.savetxt(output_filepath, bvecs, delimiter=delimiter, fmt='%f')
print(f"Transposed and saved: {output_filepath}")
directory_path = "/Volumes/neurosciencedata/MRI-Data/Francis_HION/ncanda-practice/NCANDA_S01010/pre/brain/dwi" transpose_bvecs_in_directory(directory_path, delimiter=' ')
Bvec:
0.000000 0.000000 1.000000 0.361000 -0.255000 0.861000 -0.307000 -0.736000 0.532000 0.177000 0.771000 0.079000 0.109000 0.302000 -0.464000 -0.464000 -0.529000 -0.825000 0.697000 0.479000 -0.213000 -0.648000 0.580000 -0.729000 0.963000 0.229000 -0.016000 0.359000 0.806000 -0.045000 -0.177000 0.946000 -0.318000 -0.312000 -0.284000 -0.421000 -0.963000 -0.881000 0.758000 -0.684000 0.932000 -0.648000 0.773000 0.276000 -0.555000 0.007000 0.919000 -0.223000 -0.544000 0.867000 0.534000 -0.001000 -0.611000 0.691000 0.731000 0.024000 0.453000 0.432000 -0.870000 0.283000 0.088000 -0.016000 0.000000 0.000000 0.000000 0.933000 0.565000 -0.464000 -0.766000 0.013000 0.343000 0.965000 0.163000 -0.996000 -0.920000 -0.779000 -0.460000 0.839000 0.014000 -0.540000 -0.287000 -0.338000 -0.851000 0.736000 0.745000 0.197000 -0.264000 0.507000 0.171000 -0.932000 -0.422000 0.087000 0.841000 0.315000 0.257000 0.165000 -0.200000 -0.093000 -0.020000 0.161000 -0.450000 0.720000 0.229000 -0.252000 0.610000 -0.533000 0.591000 0.715000 -0.070000 -0.589000 -0.730000 -0.477000 -0.554000 0.726000 -0.791000 0.503000 0.475000 -0.380000 0.646000 -0.820000 -0.289000 0.912000 0.393000 -0.964000 -0.000000 -0.000000 -0.000000 -0.000000 -0.785000 -0.210000 -0.564000 -0.677000 -0.774000 -0.195000 -0.615000 0.036000 0.376000 0.549000 -0.757000 -0.284000 0.849000 0.167000 0.657000 0.810000 0.480000 0.195000 -0.330000 0.656000 -0.054000 -0.831000 0.985000 -0.051000 0.415000 -0.995000 0.511000 0.068000 0.912000 -0.936000 0.938000 -0.902000 -0.271000 -0.444000 -0.471000 -0.121000 -0.281000 -0.719000 0.174000 -0.800000 -0.586000 -0.699000 -0.388000 -0.777000 -0.414000 0.145000 -0.639000 0.688000 0.027000 0.519000 -0.489000 0.925000 -0.615000 -0.376000 -0.399000 0.298000 0.915000 -0.265000
Now I get an error by the program indicating: raise ValueError(f'w2 should be positive, but is {w2:e}') ValueError: w2 should be positive, but is -9.999998e-09
Please see full feedback:
-> Writing scheme file to [ /Volumes/neurosciencedata/MRI-Data/Francis_HION/ncanda-practice/NCANDA_S01010/pre/brain/dwi/dwi.scheme ]
-> Loading data:
Hello, just an update: I was able to calculate NODDI using the matlab version without any error. I wonder why that is so.
Hi @ElChiriquiski,
this error is triggered by nibabel
due to precision issues. When nibabel
attempts to load your data, it computes the quaternion from the image header and it uses a threshold value (quaternion_threshold
) to determine whether the quaternion is valid or not.
In your case, the threshold might be too strict, resulting in this error. You can try setting a more permissive threshold before loading your data, e.g. nib.Nifti1Header.quaternion_threshold = 1e-6
.
Related issue:
@nightwnvol Thank you for providing a solution. I was able to edit and the the data inputted. I ran into an error, to setup amico.setup() code before running the rest of the code. Thank you for your help!
Hello, I had an error regarding the bval and bvecs files being incorrect or incompatible. I have a feeling it is the arrangement of the bvecs since I had to extract and build them from an .XML file. They worked fine for FSL DTI. I hope this would be a quick fix.
Would greatly appreciate the help, Thank you!
bval: 0.0 0.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0 1000.0
bvec: 0.0 0.0 -0.0 0.0 0.0 -0.0 1.0 0.0 -0.0 0.361 0.933 -0.0 -0.255 0.565 -0.785 0.861 -0.464 -0.21 -0.307 -0.766 -0.564 -0.736 0.013 -0.677 0.532 0.343 -0.774 0.177 0.965 -0.195 0.771 0.163 -0.615 0.079 -0.996 0.036 0.109 -0.92 0.376 0.302 -0.779 0.549 -0.464 -0.46 -0.757 -0.464 0.839 -0.284 -0.529 0.014 0.849 -0.825 -0.54 0.167 0.697 -0.287 0.657 0.479 -0.338 0.81 -0.213 -0.851 0.48 -0.648 0.736 0.195 0.58 0.745 -0.33 -0.729 0.197 0.656 0.963 -0.264 -0.054 0.229 0.507 -0.831 -0.016 0.171 0.985 0.359 -0.932 -0.051 0.806 -0.422 0.415 -0.045 0.087 -0.995 -0.177 0.841 0.511 0.946 0.315 0.068 -0.318 0.257 0.912 -0.312 0.165 -0.936 -0.284 -0.2 0.938 -0.421 -0.093 -0.902 -0.963 -0.02 -0.271 -0.881 0.161 -0.444 0.758 -0.45 -0.471 -0.684 0.72 -0.121 0.932 0.229 -0.281 -0.648 -0.252 -0.719 0.773 0.61 0.174 0.276 -0.533 -0.8 -0.555 0.591 -0.586 0.007 0.715 -0.699 0.919 -0.07 -0.388 -0.223 -0.589 -0.777 -0.544 -0.73 -0.414 0.867 -0.477 0.145 0.534 -0.554 -0.639 -0.001 0.726 0.688 -0.611 -0.791 0.027 0.691 0.503 0.519 0.731 0.475 -0.489 0.024 -0.38 0.925 0.453 0.646 -0.615 0.432 -0.82 -0.376 -0.87 -0.289 -0.399 0.283 0.912 0.298 0.088 0.393 0.915 -0.016 -0.964 -0.265