Repository: mne-tools/mne-python

Issue:
raw.plot_psd(reject_by_annotation=False) crashes
When I run `raw.plot_psd(reject_by_annotation=False)` on a `raw` object containing annotations, I get the following error:

```
/usr/local/lib/python3.6/site-packages/mne/io/base.py in get_data(self, picks, start, stop, reject_by_annotation, return_times)
    890             data, times = self[picks, start:stop]
    891             return (data, times) if return_times else data
--> 892         if reject_by_annotation.lower() not in ['omit', 'nan']:
    893             raise ValueError("reject_by_annotation must be None, 'omit' or "
    894                              "'NaN'. Got %s." % reject_by_annotation)

AttributeError: 'bool' object has no attribute 'lower'
```

The problem is [here](https://github.com/mne-tools/mne-python/blob/master/mne/time_frequency/psd.py#L55):

    rba = 'NaN' if reject_by_annotation else reject_by_annotation

If `reject_by_annotation` is `False`, it remains `False`, but afterwards the string method is called on this `bool` object and fails.


Discussion:
This indeed seems like bad checking, PR welcome if you have time
I've had that too lately, should be an easy fix. BTW - does `reject_by_annotation=None` work for you?
@mmagnuski yes, `None` works, and so does *any* string (actually, anything that evaluates to `True`).
It seems we only want to accept `True` or `False`. The question is, where should these arguments be checked? We could do this in multiple places.
If we only allow bool in `plot_psd`, do it there. If we do it multiple places, add a helper to `mne/viz/utils.py` or `mne/utils.py` (as appopriate based on where the functions that will use it live) and use it in those places
The call stack is `mne.io.BaseRaw.plot_psd` -> `mne.viz.raw.plot_raw_psd` -> `mne.time_frequency.psd.psd_welch` -> `mne.time_frequency.psd._check_psd_data`. The error occurs in the last function, because here `True` or `False` needs to be converted to `None`, `'omit'` or `'NaN'`. So I guess this line

    rba = 'NaN' if reject_by_annotation else reject_by_annotation

should be changed to

    rba = 'NaN' if reject_by_annotation else None

Correct?
Sounds reasonable to me

Resolving patch:
diff --git a/mne/time_frequency/psd.py b/mne/time_frequency/psd.py
--- a/mne/time_frequency/psd.py
+++ b/mne/time_frequency/psd.py
@@ -52,7 +52,7 @@ def _check_psd_data(inst, tmin, tmax, picks, proj, reject_by_annotation=False):
     sfreq = inst.info['sfreq']
     if isinstance(inst, BaseRaw):
         start, stop = np.where(time_mask)[0][[0, -1]]
-        rba = 'NaN' if reject_by_annotation else reject_by_annotation
+        rba = 'NaN' if reject_by_annotation else None
         data = inst.get_data(picks, start, stop + 1, reject_by_annotation=rba)
     elif isinstance(inst, BaseEpochs):
         data = inst.get_data()[:, picks][:, :, time_mask]


Test patch:
diff --git a/mne/viz/tests/test_raw.py b/mne/viz/tests/test_raw.py
--- a/mne/viz/tests/test_raw.py
+++ b/mne/viz/tests/test_raw.py
@@ -274,6 +274,11 @@ def test_plot_raw_psd():
                                               ('power', 'amplitude')):
             raw.plot_psd(average=True, dB=dB, estimate=estimate)
     assert_equal(len(w), 4)
+    # test reject_by_annotation
+    raw = _get_raw()
+    raw.annotations = Annotations([1, 5], [3, 3], ['test', 'test'])
+    raw.plot_psd(reject_by_annotation=True)
+    raw.plot_psd(reject_by_annotation=False)
 
 
 def test_plot_sensors():