Skip to content
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

Version 0.12 mne_bids does not read channels.tsv #10

Open
jstout211 opened this issue Dec 21, 2022 · 1 comment
Open

Version 0.12 mne_bids does not read channels.tsv #10

jstout211 opened this issue Dec 21, 2022 · 1 comment
Assignees

Comments

@jstout211
Copy link
Collaborator

The current version of the channels.tsv in the openneuro has the wrong channel headers. Previous versions on mne_bids (before 0.12) did not check this file during the data load. Now it loads the data and overwrites the correct info in the meg file.

image (22)
image (23)

@jstout211
Copy link
Collaborator Author

The code below was used to regenerate the entire bids stack from the old and the channels.tsv were copied to a new location for upload to openneuro for update.

#!/usr/bin/env python
import mne
import mne_bids
import glob
import sys
from mne_bids import BIDSPath, write_raw_bids
import logging

'''The initial upload of the bids data did not properly encode the channels.tsv file
This rewrites the whole bids data so that the updated channels file can be retrieved'''

logfile = '/gpfs/gsfs12/users/NIMH_scratch/MEG_tmp/DATA_CHECKS/logfile.txt'
bids_root = '/gpfs/gsfs12/users/NIMH_scratch/MEG_tmp/DATA_CHECKS/data'
new_bids_root = '/gpfs/gsfs12/users/NIMH_scratch/MEG_tmp/DATA_CHECKS/UPDATED_BIDS'

logging.basicConfig(filename=logfile, level=logging.ERROR)

subjid = sys.argv[1]
#subjid = 'sub-ON02747'

dsets = glob.glob(f'{bids_root}/{subjid}/ses-01/meg/*.ds')

for dset in dsets:
        try:
                bids_path = mne_bids.read.get_bids_path_from_fname(dset)
                raw = mne.io.read_raw_ctf(bids_path.fpath)
                out_bids_path = bids_path.copy().update(root=new_bids_root)
                write_raw_bids(raw, out_bids_path, overwrite=True)
        except:
                logging.error(f'{subjid}  {dset}')


Swapping out the channels.tsv into the old data allows for reading with version 0.12 mne_bids

In [8]: bids_path = mne_bids.read.get_bids_path_from_fname(f'{os.getcwd()}/sub-ON02747_ses-01_task-airpu
   ...: ff_run-01_meg.ds')
   ...: bids_path
   ...: mne_bids.read.read_raw_bids(bids_path)
ds directory : /vf/users/EnigmaMeg/BIDS/NIH_hvmeg_20220131/sub-ON02747/ses-01/meg/sub-ON02747_ses-01_task-airpuff_run-01_meg.ds
    res4 data read.
    hc data read.
    Separate EEG position data file not present.
    Quaternion matching (desired vs. transformed):
       0.20   71.38    0.00 mm <->    0.20   71.38    0.00 mm (orig :  -38.30   62.19 -277.34 mm) diff =    0.000 mm
      -0.20  -71.38    0.00 mm <->   -0.20  -71.38    0.00 mm (orig :   56.04  -44.36 -288.64 mm) diff =    0.000 mm
      98.60    0.00    0.00 mm <->   98.60    0.00    0.00 mm (orig :   81.33   70.75 -257.54 mm) diff =    0.000 mm
    Coordinate transformations established.
    Polhemus data for 3 HPI coils added
    Device coordinate locations for 3 HPI coils added
    Measurement info composed.
Finding samples for /vf/users/EnigmaMeg/BIDS/NIH_hvmeg_20220131/sub-ON02747/ses-01/meg/sub-ON02747_ses-01_task-airpuff_run-01_meg.ds/sub-ON02747_ses-01_task-airpuff_run-01_meg.meg4: 
    System clock channel is available, checking which samples are valid.
    1 x 301200 = 301200 samples from 304 chs
Current compensation grade : 3
Reading events from /vf/users/EnigmaMeg/BIDS/NIH_hvmeg_20220131/sub-ON02747/ses-01/meg/sub-ON02747_ses-01_task-airpuff_run-01_events.tsv.
Reading channel info from /vf/users/EnigmaMeg/BIDS/NIH_hvmeg_20220131/sub-ON02747/ses-01/meg/sub-ON02747_ses-01_task-airpuff_run-01_channels.tsv.
<ipython-input-8-97268ec3d3f2>:3: RuntimeWarning: Unable to map "sex" value "None" to MNE. Not setting subject sex.
  mne_bids.read.read_raw_bids(bids_path)


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

No branches or pull requests

2 participants