def task_eeg_to_bids():
    """Step 00: Bring data set into a BIDS compliant directory structure."""
    # Run the script for each subject in a sub-task.
    for subject in subjects:
        yield dict(
            # This task should come after `task_check`
            task_dep=['check'],

            # A name for the sub-task: set to the name of the subject
            name=subject,

            # If any of these files change, the script needs to be re-run. Make
            # sure that the script itself is part of this list!
            file_dep=[fname.source(subject=subject,
                                   source_type='eeg'),
                      fname.source(subject=subject,
                                   source_type='demographics'),
                      '00_eeg_to_bids.py'],

            # The files produced by the script
            targets=[fname.bids_data(subject=subject)],

            # How the script needs to be called. Here we indicate it should
            # have one command line parameter: the name of the subject.
            actions=['python 00_eeg_to_bids.py %s' % subject]
        )
# All parameters are defined in config.py
from config import fname, task_name, montage, parser, LoggingFormat

###############################################################################
# Start processing step

# Handle command line arguments
args = parser.parse_args()
subject = args.subject

print(LoggingFormat.PURPLE + LoggingFormat.BOLD +
      'Converting to BIDS: Subject %s' % subject + LoggingFormat.END)

###############################################################################
# 1) Import the data
input_file = fname.source(source_type='eeg', subject=subject)
raw = read_raw_bdf(input_file, preload=False)

# sampling rate
sfreq = raw.info['sfreq']
# channels in dataset
channels = raw.info['ch_names']

###############################################################################
# 2) Modify dataset info
# identify channel types based on matching names in montage
types = []
for channel in channels:
    if channel in montage.ch_names:
        types.append('eeg')
    elif channel.startswith('EOG') | channel.startswith('EXG'):
# Handle command line arguments
args = parser.parse_args()
subject = args.subject
session = args.session
task = args.task

print(LoggingFormat.PURPLE + LoggingFormat.BOLD +
      'Bad channel detection for subject %s (%s)' % (subject, task) +
      LoggingFormat.END)

##############################################################################
# 1) import the data

# name of the file
input_file = fname.source(subject=subject, task=task, data_type='eeg')
# bids-formatted path to data
bids_path = BIDSPath(subject=str(subject).rjust(3, '0'),
                     task=task,
                     root=output_bids,
                     extension='.vhdr')

# check if file exists, otherwise terminate the script
if not os.path.isfile(input_file):
    exit()

# import existing file
# raw = read_raw_brainvision(input_file, preload=True)
raw = read_raw_bids(bids_path, extra_params=dict(preload=True))
raw.set_montage(montage)
    LoggingFormat

###############################################################################
# Start processing step

# Handle command line arguments
args = parser.parse_args()
subject = args.subject

print(LoggingFormat.PURPLE +
      LoggingFormat.BOLD +
      'Converting subject %s to BIDS' % subject +
      LoggingFormat.END)

# Subject information (e.g., age, sex)
demo_path = fname.source(source_type='demographics',
                         subject=subject)

demo = pd.read_csv(demo_path, sep='\t', header=0)

###############################################################################
input_file = fname.source(source_type='eeg',
                          subject=subject)
# 1) Import the data
raw = read_raw_bdf(input_file,
                   preload=False)

# sampling rate
sfreq = raw.info['sfreq']
# channels in dataset
channels = raw.info['ch_names']