Skip to content

Conversation

@mscheltienne
Copy link
Member

Today, I had a researcher from our sleep lab that came-in with a ~8 hours long night recording that could not be converted to EDF either through the BrainVision software or through MNE. The converted signals were all "flat" (or mostly flat), and this was due to 10' in the recording (around hour 7 ) where the signal went completely off-scale, for whatever reason.

The physical range is estimated here

if physical_range == 'auto':
# get max and min for each channel type data
ch_types_phys_max = dict()
ch_types_phys_min = dict()
for _type in np.unique(ch_types):
_picks = np.nonzero(ch_types == _type)[0]
_data = raw.get_data(units=units, picks=_picks)
ch_types_phys_max[_type] = _data.max()
ch_types_phys_min[_type] = _data.min()

On a good file, I get: pmin = ~ -130k and pmax= ~ 80k. The range is in the ~ 250k scale. On the bad file, the range was in the ~ 10M or 100M range, several order of magnitude larger. Thus, the conversion failed.

By setting the physical_range to (-150000, 80000) in the BrainVision software or in MNE, the data could be exported to EDF and the 10' segment off-scale is saturating as expected. However, in MNE, I did have to comment out this sanity-check

# check that physical min and max is not exceeded
if data.max() > pmax:
raise RuntimeError(f'The maximum μV of the data {data.max()} is '
f'more than the physical max passed in {pmax}.')
if data.min() < pmin:
raise RuntimeError(f'The minimum μV of the data {data.min()} is '
f'less than the physical min passed in {pmin}.')

I am not familiar at all with the EDF format, and might be missing something; but IMO it should be a warning instead of a raise.

@larsoner
Copy link
Member

Nice @mscheltienne , I can't find anything to complain about! In it goes

@larsoner larsoner merged commit 5238cf7 into mne-tools:main Mar 17, 2023
@mscheltienne mscheltienne deleted the edf branch March 17, 2023 23:55
larsoner added a commit to larsoner/mne-python that referenced this pull request Mar 20, 2023
* upstream/main:
  Fix bug in new `mne.sys_info()` (mne-tools#11577)
  Remove legacy plot_psd* funcs/methods in our docs and codebase (mne-tools#11563)
  The order of raw1.info["bads"] should not matter when concatenating with raw0.info["bads"] mne-tools#11501 (mne-tools#11502)
  MAINT: Fixes for matplotlib and pandas (mne-tools#11574)
  Fix Circle [circle deploy]
  Fix export to EDF format with a set physical range smaller than the data range (mne-tools#11569)
  Slightly rework `mne.sys_info()` (mne-tools#11568)
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

Successfully merging this pull request may close these issues.

2 participants