[FieldTrip] convert .nii files to .mri files.

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Wed Jan 25 10:10:09 CET 2023


Hi Siamak,

Again: this appears not to be a FieldTrip problem. All code that is under fieldtrip/external is included in the toolbox to make life easier for the users, but it’s code from an external origin, and not maintained/written by the contributors to the FieldTrip project. In this case the code is from the freesurfer folks.

The problem you face, is that your windows machine does not seem to be able to deal with the ‘zcat’ command, which is used in order to unzip the zipped files. The best remedy is to get yourself a computer with a decent operating system (mac or linux) and do your analysis there. Alternatively, you may want to reach out to your PI, or the technical support staff at your institute to get help. Alternatively, you may try to unzip the nii.gz files to .nii using some other software tool and take it from there.

Best wishes,
Jan-Mathijs

On 25 Jan 2023, at 05:13, Siamak Sorooshyari <siamak_sorooshyari at yahoo.com<mailto:siamak_sorooshyari at yahoo.com>> wrote:

Hi, Thanks so much, the below info is very helpful.
Indeed, I tried what I'm doing with several different files to see if the one I used was corrupt, but they all fail. It is not my own MEG data, it is from the OMEGA dataset which has been used by others.

I believe I've traced the first "ERROR" that you mention to the following file:
  C:\...\FieldTrip\fieldtrip-20210709\external\freesurfer\load_nifti.m
this is under FieldTrip, correct?

In this load_nifti.m  file I put some print statements to show me what's going on. I see the following when I run:

>> my_process_MEG_via_FT_1

WARNING: fsgettmppath: could not find a temporary folder, using current folder

new_niftifile =

    '.\tp26929383_9f52_4df6_8426_0e85742b2768.load_nifti.m.nii'

cmd =

    'zcat D:\MEG_OMEGA_data\controls\sub-0249\ses-01\anat\sub-0249_ses-01_run-1_T1w.nii.gz > .\tp26929383_9f52_4df6_8426_0e85742b2768.load_nifti.m.nii'

status =

     1

result =

    ''zcat' is not recognized as an internal or external command,
     operable program or batch file.
     '

cd C:\...\FieldTrip\fieldtrip-20210709
zcat D:\MEG_OMEGA_data\controls\sub-0249\ses-01\anat\sub-0249_ses-01_run-1_T1w.nii.gz > .\tp26929383_9f52_4df6_8426_0e85742b2768.load_nifti.m.nii
ERROR: 'zcat' is not recognized as an internal or external command,
operable program or batch file.

I'm not clear what is going on with "zcat" above - I googled it and found a file for it here:
https://urldefense.com/v3/__https://github.com/penghou620/matlab-toolbox/tree/master/spfirst__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszPAY0Rpjw$ <https://urldefense.com/v3/__https://github.com/penghou620/matlab-toolbox/tree/master/spfirst__;!!HJOPV4FYYWzcc1jazlU!5PgQtVl5-eUUY_hPkwXjJhTOR9fKuTN_F7C4RSiWFoSr5n_Tp4F464T8aQj0-H0lQZMn2u-Gn8lLtq5M3pjXByU5-WWy3-yu8QzP_vASXw$>
and included the file in running the above. I am not sure if this is the issue.

I am definitely not clear how/why/where the assignment that I've mentioned above:

new_niftifile =

    '.\tp26929383_9f52_4df6_8426_0e85742b2768.load_nifti.m.nii'

comes about.

Please let me know what is wrong and how to remedy?

Best,
Siamak


On Tuesday, January 24, 2023 at 01:27:12 AM PST, Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:


Hi Siamak,

As far as I can see, the page works with an anatomical file of a certain format, which happens to be *.mri. I don’t see why one would conclude that a file of another format needs to be converted into the *.mri format in order to be able to use the tutorial code for their own purpose.

Regarding the error you got: the lower level reading routine, based on the freesurfer toolbox, typically catches errors, and thus doesn’t lead to a hard crash if something goes wrong. These errors are indicated by the lines starting with ‘ERROR’ in your e-mail report. This suggests that something goes wrong with the low-level reading of the data. Perhaps the file is corrupt, or something else is wrong. Either way, this is out of fieldtrip hands.

The matlab error message you get, about the dot-indexing can subsequently be interpreted as follows: the tmp variable, which is accessed on said line 409 in ft_read_mri, in order to extract the field called vol, does not allow for dot indexing. Thinking a bit further this means that the tmp variable, which is assumed to be a struct (because structs are matlab variables that allow for dot-indexing in order to access the struct’s fields) apparently in your case is not a struct.

It is perhaps a bit suboptimal to get this particular error message, so we look forward to a pull request that suggests a more elegant error handling in this case.

Best wishes,
Jan-Mathijs


On 24 Jan 2023, at 09:21, Siamak Sorooshyari <siamak_sorooshyari at yahoo.com<mailto:siamak_sorooshyari at yahoo.com>> wrote:


Thanks so much for your response. To answer your question, this is the page that told me to do this:
https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/headmodel_meg/__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszNt0bqIQA$ <https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/headmodel_meg/__;!!HJOPV4FYYWzcc1jazlU!_YWDWs51vAwHGcxlNVFhN2v0kKGxiWDWciY9BuJs-UwCRap5VOu1gE3mvgbd4cUbTbS3EtWpuIfpjmVkTd3KLR9ElP3uS6tRCHXCNWNdKQ$>
Notice where they mention the following:

Then, you can read in the mri data.
mri = ft_read_mri('Subject01.mri');

When I give the above command with either .nii or .nii.gz I get an error:

ERROR: D:\MEG_OMEGA_data\controls\sub-0229_Siamak\ses-01\anat\sub-0229_ses-01_run-1_T1w.nii, read in 23592960 voxels, expected 11796480
ERROR: loading D:\MEG_OMEGA_data\controls\sub-0229_Siamak\ses-01\anat\sub-0229_ses-01_run-1_T1w.nii as analyze
Dot indexing is not supported for variables of this type.

Error in ft_read_mri (line 409)
    ndims = numel(size(tmp.vol));

Error in my_process_MEG_via_FT_1 (line 8)
mri = ft_read_mri('D:\MEG_OMEGA_data\controls\sub-0229_Siamak\ses-01\anat\sub-0229_ses-01_run-1_T1w.nii');

I am not clear at all what I'm doing wrong or what the best remedy would be?

Best,
Siamak


On Tuesday, January 24, 2023 at 12:11:47 AM PST, Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:


Hi Siamak,

Why do you think that you need to convert anything? As far as I can tell, the help documentation of ft_read_mri (https://urldefense.com/v3/__https://github.com/fieldtrip/fieldtrip/blob/master/fileio/ft_read_mri.m__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszPJe-Ef_Q$ <https://urldefense.com/v3/__https://github.com/fieldtrip/fieldtrip/blob/master/fileio/ft_read_mri.m__;!!HJOPV4FYYWzcc1jazlU!7npeRmvEN0Icn0O6P3WP_0hVkGO6DX5oScMzlLeYJvAl0qGUrBEuHvSoEXsHmolWWJ0n0DYUNJ5VRqw0nuH2zkpKMl-Eu_mEt_pQnw$>) clearly mentions that it directly supports *.nii and *.nii.gz files. If there’s some other documentation that you came across, which mentions otherwise, and this documentation is one of the subpages of fieldtriptoolbox.org<https://urldefense.com/v3/__http://fieldtriptoolbox.org__;!!HJOPV4FYYWzcc1jazlU!7npeRmvEN0Icn0O6P3WP_0hVkGO6DX5oScMzlLeYJvAl0qGUrBEuHvSoEXsHmolWWJ0n0DYUNJ5VRqw0nuH2zkpKMl-Eu_lNRaAPnw$>, please adjust the text accordingly in a pull request on github (https://urldefense.com/v3/__https://github.com/fieldtrip/website__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszMs2cfPkA$ <https://urldefense.com/v3/__https://github.com/fieldtrip/website__;!!HJOPV4FYYWzcc1jazlU!7npeRmvEN0Icn0O6P3WP_0hVkGO6DX5oScMzlLeYJvAl0qGUrBEuHvSoEXsHmolWWJ0n0DYUNJ5VRqw0nuH2zkpKMl-Eu_nX0tFnJA$>) or equivalently press the ‘edit page with github’ link on the relevant page.

Best wishes,
Jan-Mathijs


On 24 Jan 2023, at 08:14, Siamak Sorooshyari via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:


How do you convert .nii (or I guess .nii.gz) files to .mri files. This is because I've been given .nii.gz files by the OMEGA dataset and I want to feed them into FieldTrip via the FieldTrip ft_read_mri() function. I am trying to get anatomical information so I can feed that into the MEG source localization that I'm trying.

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!8Zu0-0EWmjs35RiZa4_KQLPCjFq1llUC0eWkKZg1QeNSUq4KR9vZoNlJGh6pjecl0GOWEICJXhM1b678lB9c4zlmK3mIMQpDBPLC9g$

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszOeDRIeaA$ <https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!_YWDWs51vAwHGcxlNVFhN2v0kKGxiWDWciY9BuJs-UwCRap5VOu1gE3mvgbd4cUbTbS3EtWpuIfpjmVkTd3KLR9ElP3uS6tRCHVk34TVvw$>


_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!78fx6JxF-9awXfPyS9nkux0KKPeJZqHyNluMId89knFsoDkueD1Z0Ei-M8o8g0cCZvkBeLLGcpG60akawqw45HM6JmKyszOeDRIeaA$ <https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!5PgQtVl5-eUUY_hPkwXjJhTOR9fKuTN_F7C4RSiWFoSr5n_Tp4F464T8aQj0-H0lQZMn2u-Gn8lLtq5M3pjXByU5-WWy3-yu8QywFwB3ag$>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230125/590e4c9f/attachment-0001.htm>


More information about the fieldtrip mailing list