Edit Channel- coil_def.dat

Hi,

I changed and add some info in coil_def.dat, then I edit the channel file (by export it to matlab and load it again) I am not sure if the channel file ,now will understand that will take the new info updated in coil_def.dat; It is ?
please any explanation?

Thanks

The information from the file coil_def.dat is integrated in the channel file when loading data from CTF .res4 or Elekta .fif files.
https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/io/ctf_add_coil_defs.m
https://github.com/brainstorm-tools/brainstorm3/blob/master/external/mne/matlab/mne_load_coil_def.m

If you are not reading from a .fif or a .res4 file, you would need to create your own function for adding the coil_def.dat information into your channel file. You can find some inspiration in the functions above.

1-I am reading from fif file from the tutorial in BST: mind004_050924_median01_raw.fif
2-Then I modify the coil_def.f.dat
3- I export the channel file to matlab, I modify it, then I import it from matlab
4-I compute the leadfield
------------due to your answer this leadfield is not corresponding to the correct one because as you said (the information from the file coil_def.dat is integrated in the channel file when loading data from Elekta .fif files).

This what I expected, for this I think to export the file to fif then load it again so that the integration happen, is this thinking right? but as I remember I did not succeed to export the file as fif, as I remember I exported to edf mind004_050924_median01_raw.edf
it could be exported to .fif?

You said:
If you are not reading from a .fif or a .res4 file, you would need to create your own function for adding the coil_def.dat information into your channel file. You can find some inspiration in the functions above.

can you please clarify more, so in my steps above 1,2, 3, at 3 I should create the function but how? I am beginner in BST I used it as user friendly interface, not coding, but I do not have problem to learn how to code on it.

Yes.

This what I expected, for this I think to export the file to fif then load it again so that the integration happen, is this thinking right? but as I remember I did not succeed to export the file as fif, as I remember I exported to edf mind004_050924_median01_raw.edf
it could be exported to .fif?

Brainstorm does not provide any FIF writer.
You would have to do this directly with the low-level MNE-Matlab toolbox (https://github.com/mne-tools/mne-matlab) or with MNE-Python (https://github.com/mne-tools/mne-python).

can you please clarify more, so in my steps above 1,2, 3, at 3 I should create the function but how? I am beginner in BST I used it as user friendly interface, not coding, but I do not have problem to learn how to code on it.

What you are doing is beyond the current scope of Brainstorm, I'm sorry we won't be able to provide much support for this. Beyond what you can find in Brainstorm, you'll have to code everything by yourself in Matlab.
To get started with the data structures, read the Scripting tutorial (https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting). For the rest, you'll have to go directly through the code.

If you decide to create a new file format, you'll need to write readers in Brainstorm (in_fopen_yourformat / in_fread_yourformat).
If you decide to use the .fif format, you'll need to write your own "acquisition" software, independent from Brainstorm, which creates the .fif file.

Thank you Francois,
At instance the BST integrate the info in coil_def.dat to the acquisition channel file just if we load the fif file ( or .res4 may be we can export res4 after update it and import it again? or BST also cannot write BST?)

So what I should think about it is:
instead of integrate the info in coil_def.dat just when loading the fif file, for example to make the integration upon computing the LF matrix... so here I should understand where in the code you make the integration, and where you compute the LF, I will try, I hope I can arrive to a solution,

Thank you again

Brainstorm can't write CTF .res4 files either.

The easiest for you would be to write your own function that modifies the channel file by adding the integration points you want. You don't even need the coil_def.dat for that at the moment (not until you produce an MEG system and file format that other people start using).
Just edit the channel file from a Matlab script in a similar way as what ctf_add_coil_defs.m do.
You'll lose less time than trying to write these complicated CTF or FIF files...

pic
please if someone did it before please help me:
the idea is I load the fif file and I have the 2 file as you see in the attached image raw and channel, if I export them to matlab it seems to be its extension name .edf and .pos respectively
the idea is to make them again as .fif file
I am interesting to load the fif file so that the info in the coil_def.dat can be integrated after I made the changes in the channel file
Thanks in advance

Dear Francois

Can you please explain more what do you mean by:
Just edit the channel file from a Matlab script in a similar way as what ctf_add_coil_defs.m do.

Thank you

As explained before, you need to learn how to use the writing functions of the MNE-Matlab toolbox. This will be done 100% outside of Brainstorm, unfortunately we won't be able to help you with this task.
Otherwise, you can ask the MNE-Python community, they might have easier solutions for you.

Just edit the channel file from a Matlab script in a similar way as what ctf_add_coil_defs.m do.

Edit the .Loc and .Orient fields of the channel file from a Matlab script in order to integrate the geometry of each MEG sensor.
There is nothing that can do this for you with a single function call in Brainstorm or in any other Matlab tool I know of. The only advice I can give you is to read the existing functions that does it for the CTF and FIF file, and get some inspiration to write your own code.

This is not trivial. If you are not confident with your Matlab coding abilities, you might want to start with a generic Matlab programming training.

Hi Francois,

Sorry I have another question,
If I write just the channel file (exported from BST to .pos file) in fiff file and then I load it again, does the info in coil_def.dat will integrated now?
or I need to write both the channel and raw file into fif file? because when I loaded an example from BST mind004_050924_median01_raw.fif as you see in the attached image both the raw and channel file appearpic
for this I think to save the both again in fif format, but may be it is enough just to save the channel file, and this will be more easy i think?

Thank you