Hi @Steven,
I mix some lines of the code, so apologies for that. I’ll reply to your questions and show you the final code. This is the correct code:
import pandas as pd
import numpy as np
from neuroHarmonize.harmonizationNIFTI import createMaskNIFTI
nifti_list = pd.read_csv('model_list.csv')
nifti_avg, nifti_mask, affine, hdr0 = createMaskNIFTI(nifti_list, threshold=0)
from neuroHarmonize.harmonizationNIFTI import flattenNIFTIs
nifti_array = flattenNIFTIs(nifti_list, 'thresholded_mask.nii.gz')
import neuroHarmonize as nh
covars = pd.read_csv('demographics_all.csv')
my_model, nifti_array_adj = nh.harmonizationLearn(nifti_array, covars, smooth_terms=['AGE_B'])
nh.saveHarmonizationModel(my_model, 'MY_MODEL')
from neuroHarmonize.harmonizationNIFTI import applyModelNIFTIs
# load pre-trained model
my_model = nh.loadHarmonizationModel('MY_MODEL')
applyModelNIFTIs(covars, my_model, nifti_list, 'thresholded_mask.nii.gz')
What is the shape of this?
The shape of the nifti array is: (373, 33220). Number of subjects, number of voxels.
You were right, see the corrected code at the beginning of the post.
The error is in this line:
applyModelNIFTIs(covars, my_model, nifti_list, 'thresholded_mask.nii.gz')
And is the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/EBC/local/fsl/lib/python3.10/site-packages/neuroHarmonize/harmonizationNIFTI.py", line 152, in applyModelNIFTIs
nifti_array_adj = applyModelOne(nifti_array, covarsSel, model)
File "/EBC/local/fsl/lib/python3.10/site-packages/neuroHarmonize/harmonizationApply.py", line 176, in applyModelOne
stand_mean += np.dot(tmp, B_hat).T
File "<__array_function__ internals>", line 5, in dot
ValueError: shapes (1,6) and (14,33220) not aligned: 6 (dim 1) != 14 (dim 0)
For reference the shape of covars is: 373, 5.
This is quite common in neonatal imaging and they are not always that covaried. I can do a transformation and get rid of one of them.
Best regards,
Manuel