Skip to content

Commit

Permalink
only copy BTI headshape file if present (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff committed Aug 1, 2023
1 parent fd61827 commit d483a61
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions doc/whats_new.rst
Expand Up @@ -65,6 +65,7 @@ Detailed list of changes
- Improve compatibility with latest MNE-Python, by `Eric Larson`_ (:gh:`1128`)
- Working with :class:`~mne_bids.BIDSPath` would sometimes inadvertently create new directories, contaminating the BIDS dataset, by `Richard Höchenberger`_ (:gh:`1139`)
- Fix thrown error if the ``BIDSVersion`` defined in ``dataset_description.json`` file does not match the MNE-BIDS compliant ``BIDSVersion``, ensuring backwards compatibility across BIDS complient tools, by `Ford McDonald`_ (:gh:`1147`)
- Copying BTI files without a headshape file will no longer raise an error, the file will simply be copied, and the missing headshape file will be ignored, by `Stefan Appelhoff`_ (:gh:`1158`)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
10 changes: 5 additions & 5 deletions mne_bids/copyfiles.py
Expand Up @@ -22,7 +22,6 @@

from scipy.io import loadmat, savemat

import mne
from mne.io import read_raw_brainvision, read_raw_edf, read_raw_bdf, anonymize_info
from mne.utils import logger, verbose

Expand Down Expand Up @@ -539,9 +538,6 @@ def copyfile_eeglab(src, dest):
copyfile_kit
"""
if not mne.utils.check_version("scipy", "1.5.0"): # pragma: no cover
raise ImportError("SciPy >=1.5.0 is required handling EEGLAB data.")

# Get extension of the EEGLAB file
_, ext_src = _parse_ext(src)
fname_dest, ext_dest = _parse_ext(dest)
Expand Down Expand Up @@ -625,4 +621,8 @@ def copyfile_bti(raw, dest):
pdf_fname = "c,rf%0.1fHz" % raw.info["highpass"]
sh.copyfile(raw._init_kwargs["pdf_fname"], op.join(dest, pdf_fname))
sh.copyfile(raw._init_kwargs["config_fname"], op.join(dest, "config"))
sh.copyfile(raw._init_kwargs["head_shape_fname"], op.join(dest, "hs_file"))

# If no headshape file present, cannot copy it
hs_file = raw._init_kwargs.get("head_shape_fname")
if hs_file is not None: # pragma: no cover
sh.copyfile(hs_file, op.join(dest, "hs_file"))
20 changes: 4 additions & 16 deletions mne_bids/inspect.py
Expand Up @@ -11,17 +11,8 @@
import mne

from mne.utils import logger, verbose
from mne.fixes import _compare_version
from mne.viz import use_browser_backend

if _compare_version(mne.__version__, "<", "1.0.dev0"): # pragma: no cover
from mne.preprocessing import annotate_flat

_annotate_flat_func = annotate_flat
else:
from mne.preprocessing import annotate_amplitude

_annotate_flat_func = annotate_amplitude
from mne.preprocessing import annotate_amplitude

from mne_bids import read_raw_bids, mark_channels
from mne_bids.read import _from_tsv, _read_events
Expand Down Expand Up @@ -151,12 +142,9 @@ def _inspect_raw(*, bids_path, l_freq, h_freq, find_flat, show_annotations):

if find_flat:
raw.load_data() # Speeds up processing dramatically
if _annotate_flat_func.__name__ == "annotate_amplitude":
flat_annot, flat_chans = annotate_amplitude(
raw=raw, flat=0, min_duration=0.05, bad_percent=5
)
else: # pragma: no cover
flat_annot, flat_chans = annotate_flat(raw=raw, min_duration=0.05)
flat_annot, flat_chans = annotate_amplitude(
raw=raw, flat=0, min_duration=0.05, bad_percent=5
)
new_annot = raw.annotations + flat_annot
raw.set_annotations(new_annot)
raw.info["bads"] = list(set(raw.info["bads"] + flat_chans))
Expand Down

0 comments on commit d483a61

Please sign in to comment.