From de4ebbffce2ce02a9f51957f83e519c38270f20d Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 17 Nov 2023 10:29:11 -0500 Subject: [PATCH] MAINT: 1.6 compat (#366) --- mnefun/_ssp.py | 6 ++++-- mnefun/_sss.py | 11 +++++------ mnefun/_viz.py | 10 +++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/mnefun/_ssp.py b/mnefun/_ssp.py index e4bbb02..65e7af3 100644 --- a/mnefun/_ssp.py +++ b/mnefun/_ssp.py @@ -14,7 +14,10 @@ from mne.io import read_raw_fif from mne.viz import plot_drop_log from mne.utils import _pl - +try: + from mne._fiff.proj import _needs_eeg_average_ref_proj +except ImportError: # MNE < 1.6 + from mne.io.proj import _needs_eeg_average_ref_proj from ._epoching import _raise_bad_epochs from ._paths import get_raw_fnames, get_bad_fname from ._utils import (get_args, _fix_raw_eog_cals, _handle_dict, _safe_remove, @@ -43,7 +46,6 @@ def _raw_LRFCP(raw_names, sfreq, l_freq, h_freq, n_jobs, n_jobs_resample, fir_design='firwin2', pick=True, skip_by_annotation=('bad', 'skip')): """Helper to load, filter, concatenate, then project raw files""" - from mne.io.proj import _needs_eeg_average_ref_proj from ._sss import _read_raw_prebad if isinstance(raw_names, str): raw_names = [raw_names] diff --git a/mnefun/_sss.py b/mnefun/_sss.py index 6acf786..b24c236 100644 --- a/mnefun/_sss.py +++ b/mnefun/_sss.py @@ -22,8 +22,13 @@ except Exception: # <= 0.23 from mne.chpi import _get_hpi_info as get_chpi_info from mne.chpi import read_head_pos, write_head_pos, filter_chpi +from mne.annotations import _handle_meas_date, _annotations_starts_stops from mne.io import BaseRaw, read_info, read_raw_fif, write_info +try: + from mne._fiff.meas_info import _empty_info +except ImportError: # < 1.6 + from mne.io.meas_info import _empty_info from mne.preprocessing import maxwell_filter from mne.transforms import (apply_trans, invert_transform, quat_to_rot, rot_to_quat) @@ -427,8 +432,6 @@ def run_sss_locally(p, subjects, run_indices): -------- mne.preprocessing.maxwell_filter """ - from mne.annotations import _handle_meas_date - from ._ssp import _compute_erm_proj, _proj_nums assert isinstance(p.tsss_dur, float) and p.tsss_dur > 0 st_duration = p.tsss_dur @@ -847,7 +850,6 @@ def _get_fit_data(raw, p=None, prefix=' ', subj=None): def _head_pos_annot(p, subj, raw_fname, prefix=' '): """Locate head position estimation file and do annotations.""" raw = _read_raw_prebad(p, subj, raw_fname, disp=False) - from mne.annotations import _handle_meas_date printed = False if p is not None and p.movecomp is None: fit_data = head_pos = t_window = None @@ -971,7 +973,6 @@ def info_sss_basis(info, origin='auto', int_order=8, ext_order=3, def calc_median_hp(p, subj, out_file, ridx): """Calculate median head position""" print(' Estimating median head position ...') - from mne.io.meas_info import _empty_info raw_files = get_raw_fnames(p, subj, 'raw', False, False, ridx) ts = [] qs = [] @@ -1001,8 +1002,6 @@ def calc_median_hp(p, subj, out_file, ridx): def calc_twa_hp(p, subj, out_file, ridx): """Calculate time-weighted average head position.""" - from mne.annotations import _annotations_starts_stops - from mne.io.meas_info import _empty_info if not p.movecomp: # Eventually we could relax this but probably YAGNI raise RuntimeError('Cannot use time-weighted average head position ' diff --git a/mnefun/_viz.py b/mnefun/_viz.py index 6632d60..5c040f6 100644 --- a/mnefun/_viz.py +++ b/mnefun/_viz.py @@ -9,7 +9,7 @@ from mne import read_proj, read_events, pick_types from mne.utils import verbose, ProgressBar, logger -from mne.viz.utils import tight_layout, plt_show +from mne.viz.utils import plt_show from ._sss import compute_good_coils from ._paths import get_raw_fnames @@ -140,7 +140,7 @@ def plot_reconstruction(evoked, origin=(0., 0., 0.04)): info_to['projs'] = [] op = _map_meg_channels( evoked.info, info_to, mode='accurate', origin=(0., 0., 0.04)) - fig, axs = plt.subplots(3, 2, squeeze=False) + fig, axs = plt.subplots(3, 2, squeeze=False, layout="constrained") titles = dict(grad='Gradiometers (fT/cm)', mag='Magnetometers (fT)') for mi, meg in enumerate(('grad', 'mag')): picks = pick_types(evoked.info, meg=meg) @@ -166,7 +166,6 @@ def plot_reconstruction(evoked, origin=(0., 0., 0.04)): axs[0, 0].set_ylabel('Original') axs[1, 0].set_ylabel('Projection') axs[2, 0].set_ylabel('Reconstruction') - fig.tight_layout() return fig @@ -285,7 +284,7 @@ def plot_chpi_snr_raw(raw, win_length, n_harmonics=None, show=True, *, logger.info('[done]') cfreqs_legend = ['%s Hz' % fre for fre in cfreqs] - fig, axs = plt.subplots(4, 1, sharex=True) + fig, axs = plt.subplots(4, 1, sharex=True, layout="constrained") # SNR plots for gradiometers and magnetometers ax = axs[0] @@ -330,8 +329,6 @@ def plot_chpi_snr_raw(raw, win_length, n_harmonics=None, show=True, *, ax.set_title('Residual (unexplained) variance, all gradiometer channels', fontsize=title_fontsize) ax.tick_params(axis='both', which='major', labelsize=tick_fontsize) - tight_layout(pad=.5, w_pad=.1, h_pad=.2) # from mne.viz - # tight_layout will screw these up ax = axs[0] box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) @@ -400,7 +397,6 @@ def plot_good_coils(raw, t_step=1., t_window=0.2, dist_limit=0.005, ax.fill_between(t, 0, n_coils, where=mask, color=color, edgecolor='none', linewidth=0, zorder=1) ax.grid(True) - fig.tight_layout() plt_show(show) return fig