mne_bids/write.py
def _write_raw_brainvision(raw, bids_fname, events, overwrite):
    """Save out the raw file in BrainVision format.

    Parameters
    ----------
    raw : mne.io.Raw
        Raw file to save out.
    bids_fname : str
        The name of the BIDS-specified file where the raw object
        should be saved.
    events : ndarray
        The events as MNE-Python format ndaray.
    overwrite : bool
        Whether or not to overwrite existing files.
    """
    if not check_version('pybv', '0.6'):  # pragma: no cover
        raise ImportError('pybv >=0.6 is required for converting '
                          'file to BrainVision format')
    from pybv import write_brainvision
    # Subtract raw.first_samp because brainvision marks events starting from
    # the first available data point and ignores the raw.first_samp
    if events is not None:
        events[:, 0] -= raw.first_samp
        events = events[:, [0, 2]]  # reorder for pybv required order
    meas_date = raw.info['meas_date']
    if meas_date is not None:
        meas_date = _stamp_to_dt(meas_date)

    # pybv needs to know the units of the data for appropriate scaling
    # get voltage units as micro-volts and all other units "as is"
    unit = []
    for chs in raw.info['chs']:
        if chs['unit'] == FIFF.FIFF_UNIT_V:
            unit.append('µV')
        else:
            unit.append(_unit2human.get(chs['unit'], 'n/a'))
            unit = [u if u not in ['NA'] else 'n/a' for u in unit]

    # We enforce conversion to float32 format
    # XXX: pybv can also write to int16, to do that, we need to get
    # original units of data prior to conversion, and add an optimization
    # function to pybv that maximizes the resolution parameter while
    # ensuring that int16 can represent the data in original units.
    if raw.orig_format != 'single':
        warn(f'Encountered data in "{raw.orig_format}" format. '
             f'Converting to float32.', RuntimeWarning)

    # Writing to float32 µV with 0.1 resolution are the pybv defaults,
    # which guarantees accurate roundtrip for values >= 1e-7 µV
    fmt = 'binary_float32'
    resolution = 1e-1
    write_brainvision(data=raw.get_data(),
                      sfreq=raw.info['sfreq'],
                      ch_names=raw.ch_names,
                      ref_ch_names=None,
                      fname_base=op.splitext(op.basename(bids_fname))[0],
                      folder_out=op.dirname(bids_fname),
                      overwrite=overwrite,
                      events=events,
                      resolution=resolution,
                      unit=unit,
                      fmt=fmt,
                      meas_date=meas_date)
Save out the raw file in BrainVision format.

    Parameters
    ----------
    raw : mne.io.Raw
        Raw file to save out.
    bids_fname : str
        The name of the BIDS-specified file where the raw object
        should be saved.
    events : ndarray
        The events as MNE-Python format ndaray.
    overwrite : bool
        Whether or not to overwrite existing files.
    
Save out the raw file in BrainVision format.
Parameters

raw : mne.io.Raw
Raw file to save out.
bids_fname : str
The name of the BIDS-specified file where the raw object
should be saved.
events : ndarray
The events as MNE-Python format ndaray.
overwrite : bool
Whether or not to overwrite existing files.
Save out the raw file in BrainVision format . Parameters raw : mne . io . Raw Raw file to save out . bids_fname : str The name of the BIDS - specified file where the raw object should be saved . events : ndarray The events as MNE - Python format ndaray . overwrite : bool Whether or not to overwrite existing files .
def _write_raw_brainvision(raw, bids_fname, events, overwrite):
    if not check_version('pybv', '0.6'):  
        raise ImportError('pybv >=0.6 is required for converting '
                          'file to BrainVision format')
    from pybv import write_brainvision
    if events is not None:
        events[:, 0] -= raw.first_samp
        events = events[:, [0, 2]]  
    meas_date = raw.info['meas_date']
    if meas_date is not None:
        meas_date = _stamp_to_dt(meas_date)
    unit = []
    for chs in raw.info['chs']:
        if chs['unit'] == FIFF.FIFF_UNIT_V:
            unit.append('µV')
        else:
            unit.append(_unit2human.get(chs['unit'], 'n/a'))
            unit = [u if u not in ['NA'] else 'n/a' for u in unit]
    if raw.orig_format != 'single':
        warn(f'Encountered data in "{raw.orig_format}" format. '
             f'Converting to float32.', RuntimeWarning)
    fmt = 'binary_float32'
    resolution = 1e-1
    write_brainvision(data=raw.get_data(),
                      sfreq=raw.info['sfreq'],
                      ch_names=raw.ch_names,
                      ref_ch_names=None,
                      fname_base=op.splitext(op.basename(bids_fname))[0],
                      folder_out=op.dirname(bids_fname),
                      overwrite=overwrite,
                      events=events,
                      resolution=resolution,
                      unit=unit,
                      fmt=fmt,
                      meas_date=meas_date)
def _write_raw_brainvision ( raw , bids_fname , events , overwrite ) : if not check_version ( 'pybv' , '0.6' ) : raise ImportError ( 'pybv >=0.6 is required for converting ' 'file to BrainVision format' ) from pybv import write_brainvision if events is not None : events [ : , 0 ] -= raw . first_samp events = events [ : , [ 0 , 2 ] ] meas_date = raw . info [ 'meas_date' ] if meas_date is not None : meas_date = _stamp_to_dt ( meas_date ) unit = [ ] for chs in raw . info [ 'chs' ] : if chs [ 'unit' ] == FIFF . FIFF_UNIT_V : unit . append ( 'µV') else : unit . append ( _unit2human . get ( chs [ 'unit' ] , 'n/a' ) ) unit = [ u if u not in [ 'NA' ] else 'n/a' for u in unit ] if raw . orig_format != 'single' : warn ( f'Encountered data in "{raw.orig_format}" format. ' f'Converting to float32.' , RuntimeWarning ) fmt = 'binary_float32' resolution = 1e-1 write_brainvision ( data = raw . get_data ( ) , sfreq = raw . info [ 'sfreq' ] , ch_names = raw . ch_names , ref_ch_names = None , fname_base = op . splitext ( op . basename ( bids_fname ) ) [ 0 ] , folder_out = op . dirname ( bids_fname ) , overwrite = overwrite , events = events , resolution = resolution , unit = unit , fmt = fmt , meas_date = meas_date )
Save out the raw file in BrainVision format.
Save out the raw file in BrainVision format .
"""Save out the raw file in BrainVision format.

    Parameters
    ----------
    raw : mne.io.Raw
        Raw file to save out.
    bids_fname : str
        The name of the BIDS-specified file where the raw object
        should be saved.
    events : ndarray
        The events as MNE-Python format ndaray.
    overwrite : bool
        Whether or not to overwrite existing files.
    """ # pragma: no cover # Subtract raw.first_samp because brainvision marks events starting from # the first available data point and ignores the raw.first_samp # reorder for pybv required order # pybv needs to know the units of the data for appropriate scaling # get voltage units as micro-volts and all other units "as is" # We enforce conversion to float32 format # XXX: pybv can also write to int16, to do that, we need to get # original units of data prior to conversion, and add an optimization # function to pybv that maximizes the resolution parameter while # ensuring that int16 can represent the data in original units. # Writing to float32 µV with 0.1 resolution are the pybv defaults, # which guarantees accurate roundtrip for values >= 1e-7 µV
raw
bids_fname
events
overwrite