# Minor Priority: Issue with converting MNE Raw into BIDS with mne\_bids - Age/Birthday Info of Subject

**URL:** <https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922>\
**Category:** Support & Discussions\
**Created:** [November 14, 2022, 4:07pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922 "2022-11-14T16:07:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kathlin42](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kathlin42/32/1259_2.png) [@kathlin42](https://mne.discourse.group/u/kathlin42)\
**Post date:** [November 14, 2022, 4:07pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/1 "2022-11-14T16:07:12Z")

</div>

Dear All,

I found a minor issue in the Patient/Subject Information raw.info[‘subject\_info’] which is potentially new after some recent changes (adding weight and height).  
I used some of my old code parts to convert eeg data to bids using mne\_bids (which worked perfectly with the previous versions).

As before I added the age of the participants using the birthday key for the subject\_info dict before converting/writing the object into bids:  
raw.info[‘subject\_info’][‘birthday’] = (year, month, day) in integer (int)

Unfortunately, it was not recognized after the conversion (no info (n/a) in the participants.tsv file).

I looked into some documentation on the subject\_info and found this interesting format specification in the dictionary documentation 😅 - could it be a copy-paste mistake which causes the issue?

> <https://github.com/mne-tools/fiff-constants/blob/30d89d420d50c9e465f46524d4901795dac66741/DictionaryTags.txt#L378-L379>

subj\_birth\_day 404 **julian** - “Birthday of the subject”

Additional Info

- MNE version: ‘1.1.1’
- mne\_bids version: ‘0.11.1’
- operating system: Windows 10

Many thanks for looking into it 🤗  
Best,  
Katharina

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 14, 2022, 4:27pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/2 "2022-11-14T16:27:44Z")

</div>

Hello @kathlin42, I believe the date must be a `datetime.datetime` object, could you try with that? (I cannot check myself right now!)

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![kathlin42](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kathlin42/32/1259_2.png) [@kathlin42](https://mne.discourse.group/u/kathlin42)\
**Post date:** [November 14, 2022, 5:22pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/3 "2022-11-14T17:22:34Z")

</div>

Hi Richard,

Thanks for the first idea.  
I tested it with datetime.datetime object but it is still not working properly. It is correctly added in the subject\_info dict but gets lost after the conversion to bids (tsv file and raw object after read\_raw\_bids). Of course, the issue could also be in mne\_bids since they also changed some things in the last months…

Best  
Katharina

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 14, 2022, 6:41pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/4 "2022-11-14T18:41:41Z")

</div>

I cannot reproduce this…

```python
# %%
from pathlib import Path
import pandas as pd
import mne
import mne_bids

sample_dir = mne.datasets.sample.data_path()
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname)
subject_info = {
    'birthday': (1980, 12, 30) # YYYY, MM, DD
}
raw.info['subject_info'] = subject_info

bids_root = Path('/tmp/bids-test')
bp = mne_bids.BIDSPath(
    subject='sample', task='av', suffix='meg', extension='.fif',
    datatype='meg', root=bids_root
)
mne_bids.write_raw_bids(raw, bids_path=bp, overwrite=True)

# %%
participants_tsv_path = bids_root / 'participants.tsv'
participants_tsv = pd.read_csv(participants_tsv_path, sep='\t')
participants_tsv

```

produces:

 ![Screenshot 2022-11-14 at 19.40.27](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/d/d9d5923ae225f342cb59627d0e8e924d1245d1cf.png)

The only problem I noticed is that we don’t support the birthday to be a `datetime` object, so I passed a tuple instead …

Can you share the code you’re using?

Richard

cc @sappelhoff

---

<div class="post-metadata">

**Author:** ![kathlin42](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kathlin42/32/1259_2.png) [@kathlin42](https://mne.discourse.group/u/kathlin42)\
**Post date:** [November 14, 2022, 7:13pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/5 "2022-11-14T19:13:08Z")

</div>

Hi Richard,

Of course:  
Maybe it is an EEG specific issue? BrainVision format issue? I also get a warning for the Coordinate frame but I considered this independent from the subject\_info…

# CODE

```python
# Import necessary Packages
import os
import mne_bids
import mne
import pickle
# Project Specifications
task = 'errormonitoring'
datatype = 'eeg'
suffix = 'eeg'
extension = '.vhdr'
data_format= 'BrainVision'

mne_events_id = {'Fixation': 0,
                 'Good': 100,
                 'Error': 200,
                 'Response_Cue': 2,
                 'Key_Press': 3,
                 'ITI': 4}

# Data Paths
bids_root = 'raw_data' # Path where to save BIDS files
source_root = 'source_data' # Path where to copy 'example_subj_raw.fif' and 'mne_events.pickle'

# Read Data
raw = mne.io.read_raw(os.path.join(source_root, 'example_subj_raw.fif'))

with open(os.path.join(source_root, 'mne_events.pickle'), 'rb') as file:
    # A new file will be created
    mne_events = pickle.load(file)

# Add Information for BIDS Conversion
raw.info['line_freq'] = 50
raw.info['subject_info'] = {}
raw.info['subject_info']['first_name'] = 'sub-001'
raw.info['subject_info']['his_id'] = 'sub-001'
raw.info['subject_info']['birthday'] = (1996, 10, 1)
raw.info['subject_info']['sex'] = 1
raw.info['subject_info']['hand'] = 1
montage = mne.channels.make_standard_montage('standard_1020')
print(montage)
raw.set_montage(montage)
# Write Run Task Data to BIDS
bids_path = mne_bids.BIDSPath(subject='001', task='errormonitoring', run = 1,root=bids_root, datatype='eeg', suffix='eeg',
                     extension='.vhdr')
mne_bids.write_raw_bids(raw = raw, bids_path=bids_path, events=mne_events, event_id=mne_events_id,
                        allow_preload=True, overwrite=True, format='BrainVision', montage = montage)

# Test Result
raw_bids = mne_bids.read_raw_bids(bids_path, extra_params=None, verbose=None)
print(raw_bids.info['subject_info'])

```

If it helps, I can also share the raw fif file and mne\_events in pickle format…

Thanks a lot for your help!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 14, 2022, 8:04pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/6 "2022-11-14T20:04:35Z")

</div>

If you could share the input file(s), that would be helpful!

Btw you shouldn’t use pickle for long-term storage, it **will** cause problems sooner or later.

---

<div class="post-metadata">

**Author:** ![kathlin42](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kathlin42/32/1259_2.png) [@kathlin42](https://mne.discourse.group/u/kathlin42)\
**Post date:** [November 14, 2022, 8:12pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/7 "2022-11-14T20:12:48Z")

</div>

You should be able to download the files via the owncloud Link: [Fraunhofer ownCloud](https://owncloud.fraunhofer.de/index.php/s/ojJhE44tVGxpI23)  
I didn’t find an option to upload the file types directly in discourse 😉  
If there are any problems I can try another way to share them.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 14, 2022, 8:33pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/8 "2022-11-14T20:33:23Z")

</div>

The problem was that the measurement date was not set, so even though the birthday was present, the participant’s age could not be calculated.

MNE-BIDS should probably warn or even raise an exception in a case like this!

The following code works for me:

```python
import datetime
import mne_bids
import mne

bids_root = '/tmp/bids-mwe'

raw = mne.io.read_raw('example_subj_raw.fif')
raw.info['subject_info'] = {}
raw.info['subject_info']['birthday'] = (1996, 10, 1)

# meas_date must be set so participant age can be calculated
raw.set_meas_date(
    datetime.datetime(2017, 1, 30, tzinfo=datetime.timezone.utc)
)

bids_path = mne_bids.BIDSPath(
    subject='001',
    task='errormonitoring',
    root=bids_root,
    datatype='eeg',
    suffix='eeg',
    extension='.vhdr'
)
mne_bids.write_raw_bids(raw=raw, bids_path=bids_path, overwrite=True)

```

---

<div class="post-metadata">

**Author:** ![kathlin42](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/kathlin42/32/1259_2.png) [@kathlin42](https://mne.discourse.group/u/kathlin42)\
**Post date:** [November 14, 2022, 8:52pm UTC](https://mne.discourse.group/t/minor-priority-issue-with-converting-mne-raw-into-bids-with-mne-bids-age-birthday-info-of-subject/5922/9 "2022-11-14T20:52:25Z")

</div>

Thanks a lot!!! Now it worked - I’m sorry that it had such a trivial reason!
