Skip to content

Commit

Permalink
ENH: Add Loose to repr (mne-tools#11048)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Aug 19, 2022
1 parent e0df20d commit f855987
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Enhancements
~~~~~~~~~~~~
- EEGLAB files (saved as MAT versions less than v7.3) can now be imported with :func:`mne.io.read_raw_eeglab` without the optional dependency ``pymatreader`` (:gh:`11006` by `Clemens Brunner`_)
- Add :func:`mne.time_frequency.csd_tfr` to compute cross-spectral density from :class:`mne.time_frequency.EpochsTFR` (:gh:`10986` by `Alex Rockhill`_)
- Improve ``repr()`` for :class:`mne.minimum_norm.InverseOperator` when loose orientation is used (:gh:`11048` by `Eric Larson`_)
- :meth:`mne.Epochs.plot_psd_topomap` now suppresses redundant colorbars when ``vlim='joint'`` (:gh:`11051` by `Daniel McCloy`_)
- Add ``starting_affine`` keyword argument to :func:`mne.transforms.compute_volume_registration` to initialize an alignment with an affine (:gh:`11020` by `Alex Rockhill`_)

Expand Down
6 changes: 6 additions & 0 deletions mne/minimum_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def _get_chs_and_src_info_for_repr(self):
FIFF.FIFFV_MNE_FREE_ORI: 'Free'
}
src_ori = src_ori_fiff_to_name_map[self['source_ori']]
if src_ori == 'Free': # we need to do some investigation
prior = self['orient_prior']
if prior is not None:
prior = prior['data']
if not np.allclose(prior, 1.):
src_ori = f'Loose ({np.min(prior)})'
return n_chs_meg, n_chs_eeg, src_space_descr, src_ori

def __repr__(self): # noqa: D105
Expand Down
4 changes: 4 additions & 0 deletions mne/minimum_norm/tests/test_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def test_make_inverse_operator_loose(evoked, tmp_path):
log = log.getvalue()
assert 'MEG: rank 302 computed' in log
assert 'limit = 1/%d' % fwd_op['nsource'] in log
assert 'Loose (0.2)' in repr(my_inv_op)
_compare_io(my_inv_op, tempdir=str(tmp_path))
assert_equal(inverse_operator['units'], 'Am')
_compare_inverses_approx(my_inv_op, inverse_operator, evoked,
Expand Down Expand Up @@ -685,6 +686,7 @@ def test_make_inverse_operator_fixed(evoked, noise_cov):
assert 'MEG: rank 302 computed from 305' in log
assert 'EEG channels: 0' in repr(inv_op)
assert 'MEG channels: 305' in repr(inv_op)
assert 'Fixed' in repr(inv_op)
del fwd_fixed
inverse_operator_nodepth = read_inverse_operator(fname_inv_fixed_nodepth)
# XXX We should have this but we don't (MNE-C doesn't restrict info):
Expand Down Expand Up @@ -725,6 +727,8 @@ def test_make_inverse_operator_free(evoked, noise_cov):
depth=None, loose=1.)
inv = make_inverse_operator(evoked.info, fwd, noise_cov,
depth=None, loose=1.)
assert 'Free' in repr(inv_surf)
assert 'Free' in repr(inv)
_compare_inverses_approx(inv, inv_surf, evoked, rtol=1e-5, atol=1e-8,
check_nn=False, check_K=False)
for pick_ori in (None, 'vector', 'normal'):
Expand Down

0 comments on commit f855987

Please sign in to comment.