I have some subject data as well as the ImagingKernel from Brainstorm, and I’m trying to compute the source space data in Python for further analysis. Now, if I understand the documentation correctly, all I need to do is take the appropriate channels of the sensor space data and multiply them with the ImagingKernel. Are the channel indices given by the GoodChannels field to be used as is to retrieve the correct channels from the F matrix?
Thank you for your time!
This is correct. The field GoodChannels lists the channels that have to be selected from the F matrix and multiplied with the ImagingKernel.
Sources = ImagingKernel * F(GoodChannels, :);
Thanks for your reply, and sorry it took so long to get back to you!
Here is my code:
channels = kernel_data['GoodChannel']
kernel = kernel_data['ImagingKernel']
good_data = np.squeeze(subject_data['F'][channels,:])
sources = np.dot(kernel, good_data)
According to the numpy documentation, the dot(m1, m2) performs a matrix multiplication on matrices m1 and m2. To test this, I performed the matrix multiplication manually on the first few channels and got the exact same result:
channels = kernel_data['GoodChannel']
kernel = kernel_data['ImagingKernel']
good_data = np.squeeze(subject_data['F'][channels,:])
n_sources = kernel.shape[0]
n_samples = good_data.shape[1]
sources = np.asarray([[sum(kernel[i,:] * good_data[:,j]) for j in range(n_samples)] for i in range(10)])
My issue, as you can see in the following image (showing the first two sources) is that every source signal is a linear transformation of any other source signal. That is, Si = aSj + b.

Can you spot where I went wrong?
Regards
No, I’m sorry, I’m not good enough with Python for spotting your error without debugging it.
First, test what you’re trying to do in Matlab. Then try to recode this matrix multiplication in other ways (using matmul, or by writing the full multiplication with explicit loops on scalars). Or ask some Python expert for help.