Channels misplaced when importing Fieldtrip data

Hello,

I tried to import a MEG recording from a mat file saved with Fieldtrip (which only consisted of preprocessing, epoching, trial/channel rejections and ICA). The epochs and time series appear in a correct way, but the channels are not in the right place (the helmet is turned 90° to the left of the head):

Capture

This is strange because they are normally aligned when I import the original MEG neuromag fif file. I tried to add digitized head points to the imported fieldtrip mat, they do fit the head shape correctly, but "Refine using head points" does not fix the channels' orientation. I aslo tried importing channels from the original fif file, but they still are incorrectly placed as opposed to when I simply import the original fif.

I wonder if applying ICA to the data in fieldtrip was responsible for this? or only including MEG gradiometers?

I also get a bunch of error messages saying:
"Warning: the linear projection for the montage is not full-rank, the resulting data will have reduced dimensionality;
Error: Wrong number of coils for channel MEG0123: Cannot import this file correctly...
etc."

But this simply seems to come from the fact I rejected some channels within fieldtrip so I don't know if that's the cause of the issue. Could you please give me any suggestion?

I'm sorry, we can't really help you explain what happens in your FieldTrip scripts...
Tracking changes of coordinate systems is sometimes incredibly complicated.

Maybe you could try something like the following:

  1. Link the FIF file to your Brainstorm database (Review raw file), so that you get a correct "channel file" imported directly without any interference from your custom scripts.
  2. Import your processed epochs from the .mat file (Import MEG/EEG)
  3. Copy-paste the "correct" channel file to the FieldTrip folder

This option would come with some limitations:

  • Your FieldTrip script should not delete any channel (not even the useless non-MEG channels), and should not change their order in the data file. The number of channels indicated in the two channel files (link to FIF and imported .mat) must be the same.
  • The ICA mixing matrix will be missing in the channel file (as it's not computed within Brainstorm), therefore the forward modeling function would not be informed of this linear recombination of the sensors. This is OK if and only if the recordings you use to compute the noise covariance matrix are computed from MEG recordings on which the exact same ICA mixing matrix has been applied (either estimated from pre-stim baselines, or applied manually on empty-room recordings)

Hi Francois,

Many thanks for you help. Is that an issue if I simply modify the "correct" channel file after pasting it (excluding the channels that were not in the imported fieldtrip channel file)? This at least allows me to read the time series without being told that the number of channels do not match.

It does seem to impact source modelling as you said though:
"Error using * Inner matrix dimensions must agree. Error in process_inverse_2018>Compute (line 551) NoiseCovMat.NoiseCov = Proj * NoiseCovMat.NoiseCov * Proj'; ).

I did not know ICA would impact the sensors coordinates in any way so this is quite beyond my level of understanding. I do compute the noise covariance matrix from the recordings I imported from fieldtrip (I only replaced the channel file and nothing else), so I'm not sure what I should do. Also the noise covariance matrix I get looks exactly the same as when I computed it with the wrong channel file.

Is there a way to import a sourcemodel created in fieldtrip, and if yes, could that fix the problem?

Many thanks for you help. Is that an issue if I simply modify the "correct" channel file after pasting it (excluding the channels that were not in the imported fieldtrip channel file)?

This is doable, but you need to be sure of what you are doing, as this includes high risks of manipulation errors (but as you coded your analysis with FieldTrip, I guess you have good Matlab programming skills).
If you have SSP projectors in the Projectors field, you need to delete those.
https://neuroimage.usc.edu/brainstorm/Tutorials/ChannelFile#On_the_hard_drive

It does seem to impact source modelling as you said though:
"Error using * Inner matrix dimensions must agree. Error in process_inverse_2018>Compute (line 551) NoiseCovMat.NoiseCov = Proj * NoiseCovMat.NoiseCov * Proj'; ).

This comes either from problems in dimensions of the noise covariance matrix or the SSP projectors saved in the channel file:

I did not know ICA would impact the sensors coordinates in any way so this is quite beyond my level of understanding.

Not the sensors coordinates, the linear relationships between the sensors values (ICA cleaning is a spatial filter = [Nchannel x Nchannel] linear operator applied to the recordings).

Also the noise covariance matrix I get looks exactly the same as when I computed it with the wrong channel file.

Indeed, it should not change anything, as the noise covariance computation does not involve the sensors positions.

Is there a way to import a sourcemodel created in fieldtrip, and if yes, could that fix the problem?

No. The import possibilities from FieldTrip structures are limited to importing recordings.
It is possible to export head models / forward models from Brainstorm to FieldTrip.

Thanks a lot François, I removed the Projectors field in matlab and reimported it: the source modelling worked fine and the sensors are still well aligned to it.

Sorry, may I ask another question? I wanted to know if that would make sense to copy a noise covariance matrix computed from a raw unfiltered empty room recording to the cleaned fieldtrip data?

No. If you pre-process your data with FieldTrip, you need to pre-process your noise recordings exactly in the same way to be able to use them to estimate the noise covariance. If you used ICA, you need to apply the same ICA mixing matrix to the noise recordings.

The noise patterns are very different depending on the pre-processing procedure you used.

Okay, can you confirm that the mixing matrix isn't dependent on what components I rejected but strictly relates to the ICA analysis that precedes the rejection? I presume I can simply run the same analysis with the same parameters on the empty room recording, import it in brainstorm too and move its noise cov matrix to the recording of interest?

I don't understand what difference you make between these two things.

I presume I can simply run the same analysis with the same parameters on the empty room recording, import it in brainstorm too and move its noise cov matrix to the recording of interest?

No, you'd need to apply the results of the ICA analysis of your subject recordings to the noise recordings.
It you run the ICA on the noise recordings, the IC would be completely different, it would make no sense to keep or remove any of these, and the final mixing matrix (the linear operator that is assembled and applied to the MEG recordings in order to remove the spatial components you don't want) will be completely different.

This mixing matrix introduces an important amount of correlation between the sensors, and many completely change the aspect of the noise covariance matrix.

This is all theoretical. In practice, maybe it doesn't make much difference to apply this ICA mixing matrix or not to the empty room recordings. But maybe it does, and if you don't test it, you won't know.

If this seems highly unpractical, chose one other solution for the computation of the noise covariance matrix:
https://neuroimage.usc.edu/brainstorm/Tutorials/NoiseCovariance#Variations_on_how_to_estimate_sample_noise_covariance

Or just run you ICA analysis in Brainstorm... this ICA mixing matrix would be saved in the channel file (field Projectors) and applied automatically to the forward model before the source estimation.

I think I just got confused because the mixing matrix does not seem to be saved in the output after rejecting the components in fieldtrip, so I assumed it was unchanged. Thanks for all the explanation this is very helpful. I'll choose your alternative if I can't find it. Thanks !

So I tried to decompose the empty room recording using the mixing matrix I obtained with the subject recording in fieldtrip, with the "predetermined mixing matrix" method.The noise covariance matrices now look exactly the same (raw empty room file compared to processed empty room file). Is it something you would expect? I just want to make sure I did what I think I did.

I'm sorry, I can't help you much with validating these manual steps you did with FieldTrip.
The difference between raw and processed recordings (with ICA) depend on the components you removed.

Okay so I do have to apply the same rejection. There was a misunderstanding because ft can reuse un/mixing matrices but the rejection of components is a separate step which "backprojects an ICA (or similar) decomposition to the channel level after removing the independent components that contain the artifacts." So what I did was simply decomposing without rejecting anything.

The empty room noise covariance matrix does change a lot if I keep the same rejection as in the subject recording.