# write\_raw\_bids and SNIRF

**URL:** <https://mne.discourse.group/t/write-raw-bids-and-snirf/5843>\
**Category:** Support & Discussions\
**Tags:** fnirs, mne-bids\
**Created:** [November 1, 2022, 10:51am UTC](https://mne.discourse.group/t/write-raw-bids-and-snirf/5843 "2022-11-01T10:51:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfahrn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/rfahrn/32/1862_2.png) [@rfahrn](https://mne.discourse.group/u/rfahrn)\
**Post date:** [November 1, 2022, 10:51am UTC](https://mne.discourse.group/t/write-raw-bids-and-snirf/5843/1 "2022-11-01T10:51:54Z")

</div>

Hi, I have some problems writing my raw into bids

I did the following:

```python
mne_nirs.io.write_raw_snirf(raw, 'C:/Users/rebec/fNIRS-project/Data/S'+ str(participant) +"raw_coregistered_to_fsaverage.snirf") # save hitachi-raw obj to snirf file 
        raw_obj = mne.io.read_raw_snirf('C:/Users/rebec/fNIRS-project/Data/S'+ str(participant) +"raw_coregistered_to_fsaverage.snirf")
        root = r'C:\Users\rebec\fNIRS-project\Data\BIDS_1'
        bids_path = mne_bids.BIDSPath(subject=str(participant), task='intelligible speech',datatype="nirs", suffix="nirs", 
        description = 'cleaned', extension=".snirf" ,root=root)
        
        # write_bids 
        mne_bids.write_raw_bids(raw_obj, bids_path, events=events, event_id=event_dict,
                                format='FIF', anonymize=None, symlink=False, empty_room=None,
                                allow_preload=True, montage= montage, acpc_aligned=False,
                                overwrite=True, events_data=None, verbose=None)

```

The error looks like this:

```python

  C:\Users\rebec\fNIRS-project\generate_fif.py:110: RuntimeWarning: Coordinate frame could not be inferred from the raw object and the BIDSPath.space was none, skipping the writing of channel positions
  mne_bids.write_raw_bids(raw, bids_path, events=events, event_id=event_dict,
Traceback (most recent call last):

  File ~\fNIRS-project\generate_fif.py:117
    gen_fif(list_par)

  File ~\fNIRS-project\generate_fif.py:110 in gen_fif
    mne_bids.write_raw_bids(raw, bids_path, events=events, event_id=event_dict,

  File <decorator-gen-631>:12 in write_raw_bids

  File ~\Anaconda3\envs\old_mne\lib\site-packages\mne_bids\write.py:1904 in write_raw_bids
    elif format not in CONVERT_FORMATS[datatype]:

KeyError: 'nirs'

```

if I tried the same but loaded the raw-obj from a saved fif. file I get another error:

```python

ValueError: The specified datatype nirs was not found in the raw object. Please specify the correct datatype using `bids_path.update(datatype="<datatype>")` or use raw.set_channel_types to set the correct channel types in the raw object.

```

and when I tried to use the Hitachi-raw-object I get another error, as MNE-bids can not read Hitachi raw objects

What is the problem here, thanks,  
Rebecka

---

<div class="post-metadata">

**Author:** ![sappelhoff](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sappelhoff/32/3276_2.png) [@sappelhoff](https://mne.discourse.group/u/sappelhoff)\
**Post date:** [November 1, 2022, 11:29am UTC](https://mne.discourse.group/t/write-raw-bids-and-snirf/5843/2 "2022-11-01T11:29:14Z")

</div>

Why do you have `format="FIF"` specified in your call to `write_raw_bids`? If you use `format="auto"`, it should work.

But still this is something we could have a more meaningful error / handling in mne-bids. See: [fix: nirs convert only auto accepted by sappelhoff · Pull Request #1092 · mne-tools/mne-bids · GitHub](https://github.com/mne-tools/mne-bids/pull/1092)
