Skip to content

Add example snirf file#68

Merged
larsoner merged 2 commits intomne-tools:masterfrom
rob-luke:snirf
Jul 15, 2020
Merged

Add example snirf file#68
larsoner merged 2 commits intomne-tools:masterfrom
rob-luke:snirf

Conversation

@rob-luke
Copy link
Copy Markdown
Member

@rob-luke rob-luke commented Jul 14, 2020

SNIRF is the new standard file format for NIRS data. It will become the official BIDS file format.

This file was created in MATLAB from the existing nirx file with the same name.

The nirx file was converted to .nirs using the HomerOfflineConverter script provided by NIRX (unable to share, this is behind their password section, but anyone with a machine can get access). Then I ran the .nirs to .snirf conversion as specified at https://github.com/fNIRS/snirf_homer3

Here is the script used for the creation of this file

HomerOfflineConverter('mne-testing-data/NIRx/nirx_15_2_recording_w_short')

nirs = load('mne-testing-data/NIRx/nirx_15_2_recording_w_short/NIRS-2019-08-23_001.nirs','-mat')
snirf1 = SnirfClass(nirs);
snirf1.metaDataTags.tags.LengthUnit = 'cm'
snirf1.Save('nirx_15_2_recording_w_short.snirf');

I chose to use one of our existing files to convert because then we can check against the original in the tests. However, there is one change caused by the conversion. The HomerOfflineConverter script modifies the source and detector locations and projects them to a 2D(ish) set of positions. I considered using a modified custom version of HomerOfflineConverter, but decided against as then my creation of this file would then not be reproducible. Instead I have included the modified source detector locations below, and these values will be used in the tests for the file reader.

snirf1.probe.sourcePos3D
ans =

   -8.6765    0.0049   -2.6167
    7.9579   -2.7571   -2.2631
   -2.1387   -8.8874    3.8393
    1.8602    9.7164    1.7539
   -0.1108    0.7066    8.9883

snirf1.probe.detectorPos3D
ans =

   -8.0409   -2.9677   -2.5415
    1.9938   -9.1284    3.4154
    9.2027    0.0161   -2.8909
   -2.0105    9.9926    1.4288
   -3.6544    4.5020    6.9401
    3.4600    4.5611    6.9840
    3.8166   -3.1388    7.8525
   -4.0041   -3.1971    7.7754
   -8.7329    0.7577   -2.7980
    7.7548   -3.5901   -2.3179
   -2.8367   -8.7457    3.7415
    2.5925    9.6442    1.5931
    0.6539    0.6587    8.9554

Created from nirx recording with same name
@rob-luke rob-luke changed the title WIP: Add example snirf file Add example snirf file Jul 14, 2020
@larsoner
Copy link
Copy Markdown
Member

This is kind of a WIP standard, right? With opening an issue to get them to at least include the original 3D positions as well? I find it very surprising they'd voluntarily reduce the information in conversion to a file type they are in the process of defining. :(

But either way if they plan to produce some files with only this information I guess we do need to figure out how to project 2D back to 3D...

@rob-luke
Copy link
Copy Markdown
Member Author

rob-luke commented Jul 15, 2020

I think I confused a few different issues in my description above, sorry let me try and clarify. I think I wasn't clear on the two step procedure to create this file. Step one is converting NIRX to .nirs format. Step two is converting the .nirs file to SNIRF and writing the SNIRF file to disk. We are interested mainly in step two and making sure we read back the same information that was written to disk. I used the nirx to nirs procedure for step 1 simply because that's test data we already have and can compare to to easily in the tests, but step one isn't really that meaningful as people could just use our nirx reader.

This is kind of a WIP standard, right?

The SNIRF standard is complete, the first version was released in 2019 (reference). It's currently at version 1.3 and they are about to progress the spec to draft 1.4. This raises a good point that I should make the version clear in the filename, I will rename the file in this PR to include snirf_1_3_*. Then we can include future versions and have them all clearly tested.

Some vendors already export in SNIRF format. For example, NIRX exports their NIRSport2 devices with SNIRF format and they have kindly sent me some files, but they are too large to put in for unit tests. Until everyone gets new devices that export in snirf the majority of users will use the snirf converter provided by the fnirs society, so that's what I have used here.

BIDS for NIRS is a WIP. However, SNIRF will 100% be the supported file format.

With opening an issue to get them to at least include the original 3D positions as well?

The SNIRF format does not cause the loss of location information, it is the HomerOfflineConverter provided by NIRX. I have been in contact with NIRX to discuss this issue and they will not be releasing a version that has true 3d coordinates, because homer does not support true 3d coordinates and that is the most popular software. I can simply comment out the transformation in the conversion (that's what I do for my own data sets) or I can manually code in the original locations, but I opted to keep it in to make this process reproducible.

However, I don't consider the NIRX to nirs issue a concern here. We want to add support for reading SNIRF files which is vendor agnostic. This PR is to add a simple test file with known information. How different manufacturers encode location in to their SNIRF files will vary. To start with we want to just make sure we are faithfully reading what is stored in the file, so I considered the precise coding of locations tangential. We know the location information that is in the snirf file (its printed above), we just need to ensure this is read correctly by our reader. But if you prefer I can use my hacked version of HomerOfflineConverter?

The 3D positions stored in this file aren't very meaningful, but that's not the focus of the test file. Similarly the data itself isn't meaningful (its just room noise). What I thought was important for the test file was that we know what's in it, and that we read it correctly and that the file size is not too large. I guess I opted for reproducibility over meaningful 3d locations, but happy to switch if you prefer.

But either way if they plan to produce some files with only this information I guess we do need to figure out how to project 2D back to 3D...

Yeah this is an issue with the NIRX to nirs converter, its also appears to not be a static transformation but an adaptive iterative approach per file, so I don't know if its even possible to reverse. If people want to use NIRX data with correct 3d locations then they should just use our read_raw_nirx function. Actually I have been mainly working with Hitachi files in the .nirs format and they have correct 3d positions because the Hitachi to nirs conversion doesn't transform the 3d locations.

@larsoner
Copy link
Copy Markdown
Member

However, I don't consider the NIRX to nirs issue a concern here. We want to add support for reading SNIRF files which is vendor agnostic. This PR is to add a simple test file with known information. How different manufacturers encode location in to their SNIRF files will vary. To start with we want to just make sure we are faithfully reading what is stored in the file, so I considered the precise coding of locations tangential. We know the location information that is in the snirf file (its printed above), we just need to ensure this is read correctly by our reader. But if you prefer I can use my hacked version of HomerOfflineConverter?

No I agree it makes sense to use the data that standard files produce.

Actually I have been mainly working with Hitachi files in the .nirs format and they have correct 3d positions because the Hitachi to nirs conversion doesn't transform the 3d locations.

Okay good to know that some of the conversion tools are non-lossy at least :)

@larsoner larsoner merged commit aedcd45 into mne-tools:master Jul 15, 2020
@larsoner
Copy link
Copy Markdown
Member

@rob-luke
Copy link
Copy Markdown
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants