Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: 1.6 compat #366

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mnefun/_ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
11 changes: 5 additions & 6 deletions mnefun/_sss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 '
Expand Down
10 changes: 3 additions & 7 deletions mnefun/_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down