[Mne_analysis] MNE Matlab fiff_write_coord_trans function help

Kambiz Tavabi ktavabi at uw.edu
Fri Oct 26 17:32:50 EDT 2012
Search archives:

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


On 10/26/2012 2:11 PM, Martin Luessi wrote:
> 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:
>
> --------------------------------------
> import mne
>
> raw = mne.fiff.Raw('raw.fif')
> raw.info['dev_head_t']['trans'] = my_matrix
> raw.save('raw_mytrans.fif')
> --------------------------------------
>
> where "my_matrix" is a 4x4 numpy array with your transform.
>
> I hope this helps.
>
> Best,
>
> Martin
>
>
> On 10/26/12 16:38, Kambiz Tavabi wrote:
>> 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
>>
>>
>> On 10/25/2012 6:39 AM, dgw wrote:
>>> 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
>>>
>>> On Wed, Oct 24, 2012 at 6:38 PM, Kambiz Tavabi <ktavabi at uw.edu> wrote:
>>>> 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
>>>>
>>>> _______________________________________________
>>>> Mne_analysis mailing list
>>>> Mne_analysis at nmr.mgh.harvard.edu
>>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>>>
>>>>
>>>> The information in this e-mail is intended only for the person to
>>>> whom it is
>>>> addressed. If you believe this e-mail was sent to you in error and the
>>>> e-mail
>>>> contains patient information, please contact the Partners Compliance
>>>> HelpLine at
>>>> http://www.partners.org/complianceline . If the e-mail was sent to
>>>> you in
>>>> error
>>>> but does not contain patient information, please contact the sender 
>>>> and
>>>> properly
>>>> dispose of the e-mail.
>>>>
>>
>>
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>
>
>

-- 
--------------------------------------------------
Kambiz Tavabi PhD
Institute for Learning & Brain Sciences
1715 Columbia Road N
Portage Bay Building
Box 357988
University of Washington
Seattle, WA 98195-7988
Tel: 206-221-6415
--------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ktavabi.vcf
Type: text/x-vcard
Size: 360 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20121026/b5d3e91c/attachment.vcf 


More information about the Mne_analysis mailing list