Hi:
We are creating a function (for T2 mapping computation) that has two arguments: an array of MRI images, and an array of different float values. this is the function:
def find_t2(nifti_images, tes):
data_dicom = [pydicom.dcmread(fn) for fn in nifti_images]
data_sin_log=np.array([fn.pixel_array for fn in data_dicom]).astype("float32")
data = np.log(data_sin_log)
data[data < 0 ] = 0
tes = np.array(tes)
x = np.concatenate((np.ones_like(tes[..., np.newaxis]), -tes[..., np.newaxis]), 1)
beta, _, _, _ = sp.linalg.lstsq(x, data)
s0_ = np.exp(beta[0])
t2_ = 1./beta[1]
filename="/".join(nifti_images.split("/")[:-2])
data_s0 = data_dicom[0].copy()
data_t2 = data_dicom[0].copy()
data_s0.pixel_array=s0_
data_t2.pixel_array=t2_
pydicom.filewriter.dcmwrite(os.path.join(filename,"s0.dcm"), data_s0, write_like_original=True)
pydicom.filewriter.dcmwrite(os.path.join(filename,"t2.dcm"), data_t2, write_like_original=True)
return fn_s0, fn_t2
In the line "beta, _, _, _ = sp.linalg.lstsq(x, data)" we got this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-99-7c1bf581e9d2> in <module>
6
7 for index in range(0,len(arr),8):
----> 8 find_t2(arr[index:index+8], T_e_array)
9 break
<ipython-input-98-38eeaf7637e3> in find_t2(nifti_images, tes)
10 x = np.concatenate((np.ones_like(tes[..., np.newaxis]), -tes[..., np.newaxis]), 1)
11
---> 12 beta, _, _, _ = sp.linalg.lstsq(x, data)
13
14 s0_ = np.exp(beta[0])
~/python3.7_venv/lib/python3.7/site-packages/scipy/linalg/basic.py in lstsq(a, b, cond, overwrite_a, overwrite_b, check_finite, lapack_driver)
1209 overwrite_a=overwrite_a,
1210 overwrite_b=overwrite_b)
-> 1211
1212 elif driver == 'gelsd':
1213 if real_data:
ValueError: On entry to DGELSD parameter number 12 had an illegal value
The matrix of images we converted in float type and there haven't NaN. The version of scipy is 1.4.1.
How can we solve that? Please answer ASAP.
Sincerely,
Jose Manuel