Skip to content

Some BrainVision data contain Lowpass=0 #10516

@Lychfindel

Description

@Lychfindel

Describe the bug

BrainVision data acquired with V-Amp without any hardware filtering are stored in header file as:

Channels
--------
#     Name      Phys. Chn.    Resolution / Unit   Low Cutoff [s]   High Cutoff [Hz]   Notch [Hz]    Gradient         Offset
1     EOGR        1          0.0488281 µV             DC                0              Off
2     EOGL        2          0.0488281 µV             DC                0              Off
3     FP3         3          0.0488281 µV             DC                0              Off
4     Fz          4          0.0488281 µV             DC                0              Off

The current code in brainvision.py, the filtering section don't set the lowpass filter only in the case the value is NaN or Off

if len(lowpass) == 0:
    pass
elif len(set(lowpass)) == 1:
    if lowpass[0] in ('NaN', 'Off'):
        pass  # Placeholder for future use. Lowpass set in _empty_info
    else:
        info['lowpass'] = float(lowpass[0])
        if lp_s:
            # filter time constant t [secs] to Hz conversion: 1/2*pi*t
            info['lowpass'] = 1. / (2 * np.pi * info['lowpass'])

else:
    heterogeneous_lp_filter = True
    if lp_s:
        # We convert channels with disabled filters to having
        # infinitely relaxed / no filters
        lowpass = [float(filt) if filt not in ('NaN', 'Off')
                   else 0.0 for filt in lowpass]
        info['lowpass'] = np.min(np.array(lowpass, dtype=np.float64))
        try:
            # filter time constant t [secs] to Hz conversion: 1/2*pi*t
            info['lowpass'] = 1. / (2 * np.pi * info['lowpass'])

        except ZeroDivisionError:
            if len(set(lowpass)) == 1:
                # No lowpass actually set for the weakest setting
                # so we set lowpass to the Nyquist frequency
                info['lowpass'] = info['sfreq'] / 2.
                # not actually heterogeneous in effect
                # ... just heterogeneously disabled
                heterogeneous_lp_filter = False
            else:
                # no lowpass filter is the weakest filter,
                # but it wasn't the only filter
                pass
    else:
        # We convert channels with disabled filters to having
        # infinitely relaxed / no filters
        lowpass = [float(filt) if filt not in ('NaN', 'Off')
                   else np.Inf for filt in lowpass]
        info['lowpass'] = np.max(np.array(lowpass, dtype=np.float64))

        if np.isinf(info['lowpass']):
            # No lowpass actually set for the weakest setting
            # so we set lowpass to the Nyquist frequency
            info['lowpass'] = info['sfreq'] / 2.
            if len(set(lowpass)) == 1:
                # not actually heterogeneous in effect
                # ... just heterogeneously disabled
                heterogeneous_lp_filter = False

    if heterogeneous_lp_filter:
        # this isn't clean FP, but then again, we only want to provide
        # the Nyquist hint when the lowpass filter was actually
        # calculated from dividing the sampling frequency by 2, so the
        # exact/direct comparison (instead of tolerance) makes sense
        if info['lowpass'] == info['sfreq'] / 2.0:
            nyquist = ', Nyquist limit'
        else:
            nyquist = ""
        warn('Channels contain different lowpass filters. '
             'Highest (weakest) filter setting (%0.2f Hz%s) '
             'will be stored.' % (info['lowpass'], nyquist))

This lead to an error when you try e.g. to plot the data.

  File "<decorator-gen-292>", line 12, in plot_raw
  File "c:\users\atonin\pycharmprojects\mne-fork\mne-python\mne\viz\raw.py", line 227, in plot_raw
    decim, picks_data = _handle_decim(info, decim, lowpass)
  File "c:\users\atonin\pycharmprojects\mne-fork\mne-python\mne\viz\utils.py", line 1754, in _handle_decim
    decim = max(int(info['sfreq'] / (lp * 3) + 1e-6), 1)
ZeroDivisionError: float division by zero

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions