Repository: mne-tools/mne-python

Issue:
Proj example failing on master
From #3119:

```
larsoner@bunk:~/custombuilds/mne-python$ python examples/visualization/plot_ssp_projs_sensitivity_map.py 
==================================
Sensitivity map of SSP projections
==================================

This example shows the sources that have a forward field
similar to the first SSP vector correcting for ECG.

Traceback (most recent call last):
  File "examples/visualization/plot_ssp_projs_sensitivity_map.py", line 31, in <module>
    ssp_ecg_map = sensitivity_map(fwd, ch_type='grad', projs=projs, mode='angle')
  File "/home/larsoner/custombuilds/mne-python/mne/proj.py", line 377, in sensitivity_map
    co = linalg.norm(np.dot(gg[:, 2], U))
ValueError: shapes (204,) and (0,) not aligned: 204 (dim 0) != 0 (dim 0)
```

I'll try to take a look to see what's going on.



Discussion:
I have a fix ready for it. Just a minute.

There needs to be a fix at the `sensitivity_map` level and the example level, I'm working on both. I'll stop if you already have both done...

Okay I'm not sure what's the problem in the sensitivity map. The example fix is just not removing the grad projector.

`projs = projs[3:][::2]  # take only one projection per channel type` ->
`projs = projs[::2]  # take only one projection per channel type`

cool I'll put that in


Resolving patch:
diff --git a/examples/visualization/plot_ssp_projs_sensitivity_map.py b/examples/visualization/plot_ssp_projs_sensitivity_map.py
--- a/examples/visualization/plot_ssp_projs_sensitivity_map.py
+++ b/examples/visualization/plot_ssp_projs_sensitivity_map.py
@@ -25,7 +25,8 @@
 
 fwd = read_forward_solution(fname, surf_ori=True)
 projs = read_proj(ecg_fname)
-projs = projs[3:][::2]  # take only one projection per channel type
+# take only one projection per channel type
+projs = projs[::2]
 
 # Compute sensitivity map
 ssp_ecg_map = sensitivity_map(fwd, ch_type='grad', projs=projs, mode='angle')
diff --git a/mne/proj.py b/mne/proj.py
--- a/mne/proj.py
+++ b/mne/proj.py
@@ -343,15 +343,18 @@ def sensitivity_map(fwd, projs=None, ch_type='grad', mode='fixed', exclude=[],
         projs = eeg_ave if projs is None else projs + eeg_ave
 
     # Construct the projector
+    residual_types = ['angle', 'remaining', 'dampening']
     if projs is not None:
         proj, ncomp, U = make_projector(projs, fwd['sol']['row_names'],
                                         include_active=True)
         # do projection for most types
-        if mode not in ['angle', 'remaining', 'dampening']:
+        if mode not in residual_types:
             gain = np.dot(proj, gain)
-
+        elif ncomp == 0:
+            raise RuntimeError('No valid projectors found for channel type '
+                               '%s, cannot compute %s' % (ch_type, mode))
     # can only run the last couple methods if there are projectors
-    elif mode in ['angle', 'remaining', 'dampening']:
+    elif mode in residual_types:
         raise ValueError('No projectors used, cannot compute %s' % mode)
 
     n_sensors, n_dipoles = gain.shape


Test patch:
diff --git a/mne/tests/test_proj.py b/mne/tests/test_proj.py
--- a/mne/tests/test_proj.py
+++ b/mne/tests/test_proj.py
@@ -109,6 +109,9 @@ def test_sensitivity_maps():
     # test corner case for EEG
     stc = sensitivity_map(fwd, projs=[make_eeg_average_ref_proj(fwd['info'])],
                           ch_type='eeg', exclude='bads')
+    # test corner case for projs being passed but no valid ones (#3135)
+    assert_raises(ValueError, sensitivity_map, fwd, projs=None, mode='angle')
+    assert_raises(RuntimeError, sensitivity_map, fwd, projs=[], mode='angle')
     # test volume source space
     fname = op.join(sample_path, 'sample_audvis_trunc-meg-vol-7-fwd.fif')
     fwd = mne.read_forward_solution(fname)