Skip to content

Commit 1a442f0

Browse files
MAINT: Remove _get_eeg_calibration_info and delegate GCAL scaling to mffpy (#14011)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4fa9c46 commit 1a442f0

3 files changed

Lines changed: 6 additions & 49 deletions

File tree

doc/changes/dev/14011.other.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove ``_get_eeg_calibration_info`` from the EGI MFF reader and delegate per-channel GCAL scaling to ``mffpy``'s native calibration, simplifying EEG channel calibration in :func:`mne.io.read_raw_egi`, by `Pragnya Khandelwal`_.

mne/io/egi/egimff.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,17 @@
2828
_block_r,
2929
_get_blocks,
3030
_get_ep_info,
31-
_get_gains,
3231
_get_signalfname,
3332
)
3433

3534
REFERENCE_NAMES = ("VREF", "Vertex Reference")
35+
CAL_SCALES = {"uV": 1e-6, "V": 1}
3636

3737

3838
def _get_mff_reader(input_fname):
39-
"""Open an mffpy.Reader for the MFF directory, with raw (uncalibrated) EEG.
40-
41-
mffpy applies its own GCAL scaling by default, but MNE's ``cals`` already
42-
incorporate that gain (see ``_get_eeg_calibration_info``), so it is
43-
disabled here to avoid applying it twice.
44-
"""
39+
"""Open an mffpy.Reader for the MFF directory."""
4540
mffpy = _import_mffpy("read EGI MFF data")
46-
mff_reader = mffpy.Reader(input_fname)
47-
mff_reader.set_calibration("EEG", None)
48-
return mff_reader
41+
return mffpy.Reader(input_fname)
4942

5043

5144
def _disk_range_to_epochs(egi_info, disk_start, disk_stop):
@@ -287,21 +280,6 @@ def _read_header(input_fname):
287280
return info
288281

289282

290-
def _get_eeg_calibration_info(filepath, egi_info):
291-
"""Calculate calibration info for EEG channels."""
292-
gains = _get_gains(op.join(filepath, egi_info["info_fname"]))
293-
if egi_info["value_range"] != 0 and egi_info["bits"] != 0:
294-
cals = [egi_info["value_range"] / 2 ** egi_info["bits"]] * len(
295-
egi_info["chan_type"]
296-
)
297-
else:
298-
cal_scales = {"uV": 1e-6, "V": 1}
299-
cals = [cal_scales[t] for t in egi_info["chan_unit"]]
300-
if "gcal" in gains:
301-
cals *= gains["gcal"]
302-
return cals
303-
304-
305283
def _read_locs(filepath, egi_info, channel_naming):
306284
"""Read channel locations."""
307285
_soft_import("mffpy", "reading EGI MFF data")
@@ -441,7 +419,7 @@ def __init__(
441419

442420
logger.info(" Reading events ...")
443421
egi_events, egi_info, mff_events = _read_events(input_fname, egi_info)
444-
cals = _get_eeg_calibration_info(input_fname, egi_info)
422+
cals = np.array([CAL_SCALES[t] for t in egi_info["chan_unit"]])
445423
logger.info(" Assembling measurement info ...")
446424
event_codes = egi_info["event_codes"]
447425
include = _triage_include_exclude(include, exclude, egi_events, egi_info)
@@ -884,9 +862,7 @@ def _read_evoked_mff(fname, condition, channel_naming="E%d", verbose=None):
884862
info["nchan"] = sum(mff.num_channels.values())
885863

886864
# Add individual channel info
887-
# Get calibration info for EEG channels
888-
cals = _get_eeg_calibration_info(fname, egi_info)
889-
# Initialize calibration for PNS channels, will be updated later
865+
cals = np.array([CAL_SCALES[t] for t in egi_info["chan_unit"]])
890866
cals = np.concatenate([cals, np.repeat(1, len(egi_info["pns_names"]))])
891867
ch_coil = FIFF.FIFFV_COIL_EEG
892868
ch_kind = FIFF.FIFFV_EEG_CH

mne/io/egi/general.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@
1111
from ...utils import _pl
1212

1313

14-
def _get_gains(filepath):
15-
"""Parse gains."""
16-
from mffpy.xml_files import XML
17-
18-
obj = XML.from_file(filepath)
19-
cals = obj.get_content().get("calibrations", {})
20-
gains = {}
21-
if "GCAL" in cals:
22-
ch_dict = cals["GCAL"]["channels"]
23-
gains["gcal"] = np.asarray(
24-
[ch_dict[k] for k in sorted(ch_dict)], dtype=np.float64
25-
)
26-
if "ICAL" in cals:
27-
ch_dict = cals["ICAL"]["channels"]
28-
gains["ical"] = np.asarray(
29-
[ch_dict[k] for k in sorted(ch_dict)], dtype=np.float64
30-
)
31-
return gains
32-
33-
3414
def _get_ep_info(filepath):
3515
"""Get epoch info."""
3616
from mffpy.xml_files import XML

0 commit comments

Comments
 (0)