NIRScout data and errors

Hi Everyone,

I am a new user of MNE-NIRS package with no experience in Python. Since I watched Dr.Robert Luke’s webinar regarding the MNE-NIRS analysis, I became interested in exploring the package in Python.

I have run into many obstacles to try the package with my data, which brings out multiple questions. Some questions can sound very silly…

My data have been collected using NIRScout system having multiple outcome files including .nirs, .snirf per subject. Because I have used Homer3 for analysis, my files are organized by subject and each file of subjects contains all of the outcome files (nirs and snif files in the same folder). I am wondering if it is still okay to keep that structure of the files in each folder to run the data in MNE-NIRS package. Also, when running a group level analysis, can I have sub-folders by subjects in a folder?

Also, I grappled with how to import/load the data. In each subject folder, there are two files - .nirs, and .snirf - which one do you recommend to use ( mne.io.read_raw_nirx() or ‘mne.io.read_raw_snirf()’)?

Lastly, here is the error code that I ran into. Due to the lack of my experience in Python, I could not figure out what it meant. I actually tried the both, nirx and snif codes. This is one of them. FYI, ANN is the file name of a subject, and I can see the ANN folder in the directory (User/hkim302/JupyterNotebook).

Thank you for your help in adavance!

Loading User/hkim302/JupyterNotebook/ANN
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-69-ffff1d20a989> in <module>
----> 1 raw_intensity = mne.io.read_raw_nirx(fname, preload=False, verbose=None)

~\Anaconda3\lib\site-packages\mne\io\nirx\nirx.py in read_raw_nirx(fname, preload, verbose)
     43     mne.io.Raw : Documentation of attribute and methods.
     44     """
---> 45     return RawNIRX(fname, preload, verbose)
     46 
     47 

<decorator-gen-238> in __init__(self, fname, preload, verbose)

~\Anaconda3\lib\site-packages\mne\io\nirx\nirx.py in __init__(self, fname, preload, verbose)
     76             fname = op.dirname(op.abspath(fname))
     77 
---> 78         fname = _check_fname(fname, 'read', True, 'fname', need_dir=True)
     79 
     80         # Check if required files exist and store names for later use

~\Anaconda3\lib\site-packages\mne\utils\check.py in _check_fname(fname, overwrite, must_exist, name, need_dir)
    176                     f'{name} does not have read permissions: {fname}')
    177     elif must_exist:
--> 178         raise FileNotFoundError(f'{name} does not exist: {fname}')
    179     return str(op.abspath(fname))
    180 

FileNotFoundError: fname does not exist: User/hkim302/JupyterNotebook/ANN

Hello @kim1208 and welcome to the forum!

The error message you’re seeing indicates that the specified filename / path could not be found. I think the path is missing a / in the beginning.

As to the other questions, I’m sure @rob-luke will be happy to answer!

Best wishes,
Richard

Hi Kim,

First off, thanks for trying MNE with your fNIRS data. And double thanks for taking the time to report your experience to us. I greatly appreciate it.

All you questions are very clear, I will try and answer them in turn. Let me know if I miss anything.

I am wondering if it is still okay to keep that structure of the files in each folder to run the data in MNE-NIRS package. Also, when running a group level analysis, can I have sub-folders by subjects in a folder?

Leaving your data in this format will work fine with MNE. You do not have to change your folder structure. Some of the examples use a certain folder structure (see The Brain Imaging Data Structure - Brain Imaging Data Structure v1.6.0), but this is not a requirement.

Also for future reference, I am currently working with the Homer team to ensure our folder structure requirements are the same in the future. So watch this space!

Also, I grappled with how to import/load the data. In each subject folder, there are two files - .nirs, and .snirf - which one do you recommend to use ( mne.io.read_raw_nirx() or ‘mne.io.read_raw_snirf()’)?

You must have a fancy new machine if it exports in SNIRF, cool stuff. Both read_raw_nirx and read_raw_snirf should produce the same result in theory. But SNIRF is the future, and there may currently be some teething issues. So I recommend you use the read_raw_nirx function for now.

Lastly, here is the error code that I ran into. Due to the lack of my experience in Python, I could not figure out what it meant.

I agree with @Richard this looks like a path error. You seem to be missing the /. Sometimes its also handy to provide the path for the hdr file to the function. So try something like raw = read_raw_nirx("User/hkim302/JupyterNotebook/ANN/AAAA-BB-CC_01.hdr"). Then test it out with a raw.plot_sensors() or raw.info

I hope this helps. Let us know if you manage to load the data, im keen to hear how you go.

Also thanks for stepping through the MNE-NIRS install steps, there are a currently a few more steps than I would like. But there will soon be a new release of MNE-Python which brings many improvements to NIRS functionality, and it will also simplify installation greatly.

1 Like

Thank you for your responses. I don’t know why but .nirs file was not working. Instead, .snirf worked. Will it cause any potential issues if I keep working on my data with snirf files?

I was re-watching the nirx workshop video, and tried to run some codes. Some outcomes that I got did not seem to be correct to me. I am attaching files here

What seems right to me is that we have 6 stimuli (our participants were asked to listen to stories [2 different types; real story and scrambled story]. Real stories last approximately 50 sec, and scrambled stories last 30 sec. The order of the stories is alternating. However, looking at the figure - the stim markers look very short and did not seem that they last for certain seconds.

My other question is when I made annotations for stimuli- # 1,3,5 stimuli are real stories; # 2,4,6 stimuli are scrambled stories. I got an error message.

Here is my code

event_dict = {‘story’: 1, ‘scrambled’: 2, ‘story’: 3, ‘scrambled’: 4, ‘story’: 5, ‘scrambled’: 6}
plt.rcParams[“figure.figsize”] = (10, 6)
mne.viz.plot_events(events, event_id=event_dict, sfreq=raw_intensity.info[‘sfreq’]);

This is what I got

I would be happy to get any advice from you. Any comments or feedbacks are welcomed. Thank you!

I don’t know why but .nirs file was not working.

MNE does not support reading .nirs files, so that would be why it didn’t work :slight_smile:

Will it cause any potential issues if I keep working on my data with snirf files?

Working with .snirf files will not cause issues. We support snirf and its the preferred format of the society for fNIRS.

the stim markers look very short and did not seem that they last for certain seconds.

I am guessing (see comment below) that the markers just indicate the onset of your stimulus. The triggers in the SNIRF file just encode the onset of the stimulus (this would depend on your recording software, correct me if Im wrong), If you want the stim marker to extend for the duration of your stimulus then use something like set_durations. So your plot looks good to me.

I got an error message.

I think you might benefit from cleaning your annotations earlier on in your script. Check out this link: clean-up-annotations-before-analysis (but you may need to use 1 rather than 1.0 because its a snirf file) doing this early on will fix your annotation names and then you can simply run:

events, event_dict = mne.events_from_annotations(raw_haemo, verbose=False)
mne.viz.plot_events(events, event_id=event_dict, sfreq=raw_haemo.info['sfreq'])

But check out that tutorial in full, it might have other handy tips for you.

Hope this works, keep us posted if this helps. I appreciate the feedback.


General comment: please provide more specific details about your issues. For example provide a minimum working example code, currently I am having to guess what your code is. And also please use the code formatting feature to make it easier for us to read your examples. Good luck!

1 Like