MNE Matlab fiff_write_coord_trans function help

Greetings all,
I accidently sent this email to mne_support at nmr, if you're getting this
again, I am sorry for the duplicate.
I am trying to define a new device-to-head transformation matrix and
either (a) over write the transformation matrix in a existing raw fif
file or (b) write a new 'dummy' fif file. I get the impression option
(a) is more feasible, using some of the MNE Matlab functions.
To that end I tried using the function fiff_write_coord_trans to
overwrite a coordinate transfomation structure to a raw fif file. The
device-to-head transformation matrix output from fiff_read_meas_info is
of type double precision, once I make the desired changes to that matrix
and pass the new coordinate transfomation structure to fiff_write_coord
I get an error at line 53:

ln51-count = fwrite(fid,int32(FIFF_COORD_TRANS),'int32');
ln52-if count ~= 1
ln53- error(me,'write failed');
ln54-end

I suspect the problem is due to mismatch between 'int32' and 'double'
precision types. But I get the same error if I convert the
transformation matrix to int32, not to mention the values are now quite
different as compared to the original double precision matrix output by
fiff_read_meas_info. Anyone know what's going on here? or know of a fix
or workaround?

Thanks in advance
Kambiz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ktavabi.vcf
Type: text/x-vcard
Size: 387 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20121024/36b6e20d/attachment.vcf

Hi Kambiz,

From your description of approach "a" it seems like you should start a

bit closer to the beginning. i.e. read the raw fiff file change the
device to head transformation matrix and write it out again. You
shouldn't need to deal with those other functions. I would use
mne_ex_read_write_raw as a guide. I am not sure of what you tried to
do exactly, but the above approach is simpler. It sounds as though you
were trying to simply overwrite directly into an already written file,
which I do not believe is supported in the MATLAB toolbox (or if it
is, it may be more complicated to use than simply reading in the file
and writing it out again). You need to read in the whole file and
write it back out.

D

Hi Dan,

Thanks for pointing me mne_ex_read_write_raw. It seems to work for the
most part, i.e., writing a new raw file minus the MISC channels. There
is the option to change the data at Line 98 "add your own miracle here".
But alas a miracle I cannot conjure. In all my attempts I cannot manage
to change the desired recording information (info.dev_head_t), this
information is always copied from the original input file argument. So
I'm forced to ask, have you actually managed to change the recording
information using mne_ex_read_write_raw? or is that even possible?

Kambiz

Kambiz,

What Dan meant is to read the fif file, change the transform, and write
the file back. I'm not very familiar with the matlab toolbox, but in
mne-python you could do it as follows:

Thanks Martin,
I'll give it a try with python. But I really need do figure this out in
Matlab.
I understood what Dan said, and what I was trying to say is that I can
read the file and change the transfrom with mne_ex_read_write_raw, but
somewhere in the writing procedures, which relies on calls to the low
level fiff writing functions e.g., fiff_start_writing_raw &
fiff_write_coord_trans, the measurement info is rather tricky to change.

Kambiz

Hi,

Matti may chime in here. I remember you do need to set
raw.info.filename = [];
otherwise the code will copy a lot of the raw parameters from the
original file. If that still doesn't work, try this (but only as a
last resort, because I don't know what this does):
raw.info.acq_pars = [];

HTH
D