Repository: mne-tools/mne-python

Issue:
API/BUG make_inverse_operator with depth=None
The logic of `make_inverse_operator` is a bit broken, we can't automatically use it with `loose > 0` and `depth=None` if the forward is not `surf_orig=True`

e.g.

```python
inv = make_inverse_operator(epochs.info, fwd, cov, loose=0.2, depth=.8)  # works
inv = make_inverse_operator(epochs.info, fwd, cov, loose=0.2, depth=None)  # does not work
```

The error mentions the issue with `loose` although the only change is in `depth`.

Instead, we need to do this first (although with different options, this is done automatically by make_inverse_operator in other cases)
```python
from mne.forward import convert_forward_solution
fwd = convert_forward_solution(fwd, surf_ori=True)
```

Sorry for the message brievity, I m not on my computer

JR


Discussion:

Resolving patch:
diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py
--- a/mne/minimum_norm/inverse.py
+++ b/mne/minimum_norm/inverse.py
@@ -1326,18 +1326,18 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8,
             raise ValueError('You need a free-orientation, surface-oriented '
                              'forward solution to do depth weighting even '
                              'when calculating a fixed-orientation inverse.')
-        if not forward['surf_ori']:
-            forward = convert_forward_solution(forward, surf_ori=True)
-        assert forward['surf_ori']
     if loose is not None:
         if not (0 <= loose <= 1):
             raise ValueError('loose value should be smaller than 1 and bigger '
                              'than 0, or None for not loose orientations.')
-        if loose < 1 and not forward['surf_ori']:
-            raise ValueError('Forward operator is not oriented in surface '
-                             'coordinates. A loose inverse operator requires '
-                             'a surface-based, free orientation forward '
-                             'operator.')
+
+    if (depth is not None or loose is not None):
+        if not forward['surf_ori']:
+            forward = convert_forward_solution(forward, surf_ori=True,
+                                               copy=True)
+            logger.info('Forward does not have surf_ori=True. Automatically '
+                        'convert forward solution')
+        assert forward['surf_ori']
 
     #
     # 1. Read the bad channels


Test patch:
diff --git a/mne/minimum_norm/tests/test_inverse.py b/mne/minimum_norm/tests/test_inverse.py
--- a/mne/minimum_norm/tests/test_inverse.py
+++ b/mne/minimum_norm/tests/test_inverse.py
@@ -389,10 +389,13 @@ def test_make_inverse_operator_vector():
     inv_2 = make_inverse_operator(evoked.info, fwd_surf, noise_cov, depth=None)
     inv_3 = make_inverse_operator(evoked.info, fwd_surf, noise_cov, fixed=True,
                                   loose=None)
+    inv_4 = make_inverse_operator(evoked.info, fwd_fixed, noise_cov,
+                                  loose=.2, depth=None)
 
     # Apply the inverse operators and check the result
-    for inv in [inv_1, inv_2]:
-        for method in ['MNE', 'dSPM', 'sLORETA']:
+    for ii, inv in enumerate((inv_1, inv_2, inv_4)):
+        methods = ['MNE', 'dSPM', 'sLORETA'] if ii < 2 else ['MNE']
+        for method in methods:
             stc = apply_inverse(evoked, inv, method=method)
             stc_vec = apply_inverse(evoked, inv, pick_ori='vector',
                                     method=method)