-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import Snirf file #283
Import Snirf file #283
Conversation
Thanks for initiating this work! My first question would be about the necessity of including cascades of dependent libraries to Brainstorm. Not a major problem, but may come with additional distribution and maintenance problems. |
Just to clarify - JSNIRF is basically the JSON (.jnirs) and UBJSON (.bnirs) wrapper of SNIRF (with the data serialization following the JData specification). To read/write JSNIRF files, you need the JSONLab toolbox, which is already included in Iso2mesh. One can also use the The ZMat toolbox is optional if your user is using MATLAB in the GUI mode (in such case, JSONLab uses jvm/java to compress/decompress zlib/gzip data), but to support other formats such as The SNIRF format - JSNIRF is basically a JSON wrapper of SNIRF - uses HDF5 for the underlying storage. In such case, I would say use easyh5 is the simplest/easiest solution, but Octave does not support HDF5 (yet), JSON-based JSNIRF is more suitable if Octave support is needed. |
@fangq Thanks for this detailed comments! @Edouard2laire Since using the Jsnirf library would add other additional depending libraries (probably making the compilation/distribution process more complicated), I would tend to prefer a solution that relies directly on reading the SNIRF format with an HDF5-reading library (either the Matlab function, or with easyh5 if it can be compiled/redistributed with Brainstorm). I could help with this. Otherwise, I'd be happy to use Jsnirf if it saves a lot of development time, but ideally it would need to meet the following criteria:
|
Hi. I am not sure about using easyh5 but not jsnirf as we might end up just re-coding jsnirf and we will still have the inconvenience of using easyh5 that you pointed out before. Maybe what I can do is finish the code using Jsnirf toolbox (so reading data from the structure created by loadsnirf) so we have the main logic of the code, and then we can look to replace this function with Matlab one (or easyh5) |
Works for me. Thanks for your contributions! |
Additional discussions about EasyH5, JSONLab, OpenJData: |
Hi @ftadel Code is ready to be reviewed. I join you the snirf version of the exemple presented in the nirs tutorial (https://neuroimage.usc.edu/brainstorm/Tutorials/NIRSFingerTapping) : https://filesender.renater.fr/?s=download&token=45fc881f-46eb-4272-82d1-2fabbbf2443e You can also find exemple of snirf file here : https://github.com/fNIRS/snirf-samples (with a consideration to the issue I raised fNIRS/snirf-samples#5) I might upgrade the code later to be able to handle processed data such as dOD or HbO, Hbr and HbT (see fNIRS/snirf#40) I also have some question regarding the importation :
|
It's not possible to save in one file signals with different time vectors (different recording period or different sampling rate). If you want to be able to keep them together with the NIRS recordings, you'd need to re-interpolate on the NIRS time vector with the interp1 function.
Yes, everything is in international units. |
@ftadel, please see a summary of the licenses/disk budget for the dependencies involved
All dependencies are released under GPL v3 compatible licenses:
also, not related to this issue, but #284
among these, jsonlab/jsnirfy/jnifti are already included in iso2mesh.
I've successfully compiled most of the iso2mesh-included units in the i2m GUI and they compiles without any problem. https://github.com/fangq/iso2mesh/blob/master/i2m.prj#L95-L181
These toolboxes should be compatible to at least R2010a because that's the version I am using for my development. I also test those on Octave 4.2 and later versions of MATLAB. Happy to install 2009b and test, but I don't expect any major problem.
below, I summarized the dependency package sizes before and after compression.
so, to add jsonlab, easyh5, jsnirfy and jnifti to brainstorm only cost 187kB of compressed space (all native matlab/octave code, including documentations). zmat is a mex file based package, which contains 3 pre-compiled mex files for windows/mac/linux. After exe-packing using also, a lot of the functions are "wrappers" for easy utility, and can be stripped if more space is needed. let me know if you have further questions. |
Thanks @fangq, this sounds perfect! As you sound totally fine with it, I will copy the libraries I need (at least easyh5) directly to our external code folder (https://github.com/brainstorm-tools/brainstorm3/tree/master/external). |
@Edouard2laire Have you forgotten to push out_fwrite_snirf.m? |
Hi. Thanks a lot
|
The functions out_fopen/out_fwrite are for saving continuous binary files in multiple calls. I am reformatting everything so that it fits all the Brainstorm conventions and looks similar to all the other existing reading functions. I apologize in advance if you don't recognize much of your initial code at the end. Will post it soon. |
oh ok. Thank you. Sorry to cause you extra-work.
so, I guess it the same in in_fopen/in_fread ? A strange thing I notice, is in_fopen_nirs_brs, the code doesn't seems to load the data but only load the nirs montage. (but I guess then brainstorm call in_fread_nirs_bsr to read data) |
Indeed, the in_fopen and out_fopen functions only read/write the header, no data. |
I pushed the modified reader in this commit (includes easyh5 and jsnirfy) : @fangq Easyh5 doesn't work with 2009b or 2010a, for reading @Edouard2laire's example.snirf (https://filesender.renater.fr/?s=download&token=45fc881f-46eb-4272-82d1-2fabbbf2443e)
With 2015b, I get this warning:
With 2014b: jnirs.nirs.data.measurementList is a cell array while it is an array of struct other versions... With 2014b: Your neuro_run01.snirf does this:
I didn't test other Matlab versions, but it looks like some more exhaustive testing across Matlab versions should be done. |
sorry, I meant that JSON-based JSNIRF files should have a broader compatibility (JSONLab were tested on R2010a), but the HDF5 based SNIRF file were developed mostly on R2016, and I did not run sufficient test on other versions. I will do that this week. It appears that MATLAB's HDF5 APIs were added in R2011a, so, you were right, R2009-R2010 does not support this toolbox. I just ran this on R2013a and eazyh5 only works if I do not have empty arrays. I am going to do more tests and improve the code for better compatibility. Will create a ticket in easyh5 to follow up. |
this is partially fixed (fangq/easyh5@600c2d1) - for matlab older than R2011, it exits and gives an error that hdf5 is not supported. For matlab 2011-2014, its HDF5 support is quite buggy, so I let It works without any issue on R2016 and 2018, but I haven't installed R2015 to find out what has caused the warnings. will continue updating it. |
Reported to Brainstorm here: ff6e180 Thanks! |
Hi,
This PR makes Brainstorm compatible with a new nirs format (snirf) that is currently discussed to replace previous Homer format (.nirs) and that might be used for BIDS specification.
Snirf specification are detailed here : https://github.com/fNIRS/snirf/blob/master/snirf_specification.md
The format is based on HDF5 file format so I am using the toolbox Jsnirf (https://github.com/fNIRS/jsnirf) which is build upon eazyh5 to read it . Jsnirf can also allow us to read and write the two following format : .jsnirf and .bnirs if we add the toolboxes JSONLab and zmat. But I don't know yet if it's necessary to support them.
The PR is not ready to be merge as I still have to some part of the code for exemple to import event, or add condition on the presence of optional data. but I would like to make sure I am going in the right direction before writing too much code. I can send you exemple files if you want.
Best regards,
Edouard