Repository: mne-tools/mne-bids

Issue:
verbose=False is not propagated to the function that finds events
#### Describe the bug
Calling `write_raw_bids` with `verbose=False` still produces output related to finding events.


#### Steps to reproduce
```python

from tempfile import mkdtemp
from pathlib import Path

import mne
import mne_bids

test_elekta = Path(mne.datasets.testing.data_path(verbose=True)) / 'misc' / 'test_elekta_3ch_raw.fif'
raw = mne.io.read_raw_fif(test_elekta, verbose=False)
bids_root = mkdtemp()
mne_bids.write_raw_bids(raw, 'sub-01_ses-01_run-05', bids_root=bids_root, verbose=False)
```

#### Expected results
Nothing is printed to the console.


#### Actual results
The following is printed to the console:
```
162 events found
Event IDs: [  1   2   4   8  16  32  64 128]
```

#### Additional information
`mne.sys_info()`:
```
Platform:      Windows-10-10.0.18362-SP0
Python:        3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
Executable:    D:\software_windows\miniconda3\envs\syntax_tagging\python.exe
CPU:           Intel64 Family 6 Model 69 Stepping 1, GenuineIntel: 4 cores
Memory:        Unavailable (requires "psutil" package)
mne:           0.19.2
numpy:         1.16.3 {blas=mkl_rt, lapack=mkl_rt}
scipy:         1.2.1
matplotlib:    3.2.1 {backend=Qt5Agg}

sklearn:       0.21.3
numba:         Not found
nibabel:       3.1.0
cupy:          Not found
pandas:        0.25.1
dipy:          1.1.0
mayavi:        4.7.1 {qt_api=pyqt5, PyQt5=5.9.2}
pyvista:       Not found
vtk:           8.2.0
```
`mne_bids.__version__`:
```
'0.4'
```
But the result is the same with the current development version '0.5.dev0'.



Discussion:
you can use

mne.set_log_level

>

But it's true `verbose=False` should be passed to `find_events` [here](https://github.com/mne-tools/mne-bids/blob/a8389c22a0a32ffbbd573fa1494fc1cbf5f069ce/mne_bids/utils.py#L514)

@kalenkovich do you want to make a pull request to fix this?
Sure thing. I’ll do it some time next week.

On Sat, 13 Jun 2020 at 19:37, Mainak Jas <notifications@github.com> wrote:

> But it's true verbose=False should be passed to find_events
>
> @kalenkovich <https://github.com/kalenkovich> do you want to make a pull
> request to fix this?
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/mne-tools/mne-bids/issues/448#issuecomment-643647159>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACGUAWQDC2BO4GSMSSEDREDRWOTMHANCNFSM4N5AVR3Q>
> .
>

Thanks!
I created a new environment as suggested in [`CONTRIBUTING.MD`](https://github.com/mne-tools/mne-bids/blob/master/CONTRIBUTING.md). There, `pip install mne` installed version 0.20 of mne and now I get the following error with the same code I used initially:

```python
Traceback (most recent call last):
  File "<input>", line 10, in <module>
  File "c:\users\evgen\onedrive\projects\mne-bids\mne-bids\mne_bids\write.py", line 1092, in write_raw_bids
    overwrite, verbose)
  File "c:\users\evgen\onedrive\projects\mne-bids\mne-bids\mne_bids\dig.py", line 216, in _coordsystem_json
    coords = _extract_landmarks(dig)
  File "c:\users\evgen\onedrive\projects\mne-bids\mne-bids\mne_bids\utils.py", line 577, in _extract_landmarks
    landmarks = {d['ident']: d for d in dig
TypeError: 'NoneType' object is not iterable
```

I am a bit confused by this, tbh. @jasmainak, should I just downgrade to 0.19 and make sure the code works against that version? Or should I submit an issue about this error? Or both? :man_shrugging:
Do you have this error with the development version of MNE and development version of mne-bids?
I had this error with mne-bids '0.5.dev0' and mne 0.20. I now installed mne 0.21.dev0 and I get the same error.

`mne.sys_info()`:

```sh
Platform:      Windows-10-10.0.18362-SP0
Python:        3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]
Executable:    D:\software_windows\miniconda3\envs\mne-bids\python.exe
CPU:           Intel64 Family 6 Model 69 Stepping 1, GenuineIntel: 4 cores
Memory:        Unavailable (requires "psutil" package)
mne:           0.21.dev0
numpy:         1.18.5 {blas=C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info, lapack=C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info}
scipy:         1.4.1
matplotlib:    Not found
sklearn:       0.23.1
numba:         Not found
nibabel:       3.1.0
cupy:          Not found
pandas:        Not found
dipy:          Not found
mayavi:        Not found
pyvista:       Not found
vtk:           Not found
```

`mne_bids.__version__`:
```'0.5.dev0'```
that's super weird. Can you open an issue and also provide a minimal reproducible script?
Done (#450). 

What should I do with propagating `verbose` in the meantime?
> What should I do with propagating verbose in the meantime?

it looks like you stumbled over two separate issues (thanks for reporting) ... the `verbose` issue can be handled separately, so please feel free to open a PR to fix it!

Resolving patch:
diff --git a/mne_bids/utils.py b/mne_bids/utils.py
--- a/mne_bids/utils.py
+++ b/mne_bids/utils.py
@@ -710,7 +710,7 @@ def _check_key_val(key, val):
     return key, val
 
 
-def _read_events(events_data, event_id, raw, ext):
+def _read_events(events_data, event_id, raw, ext, verbose=None):
     """Read in events data.
 
     Parameters
@@ -726,6 +726,8 @@ def _read_events(events_data, event_id, raw, ext):
         The data as MNE-Python Raw object.
     ext : str
         The extension of the original data file.
+    verbose : bool | str | int | None
+        If not None, override default verbose level (see :func:`mne.verbose`).
 
     Returns
     -------
@@ -737,7 +739,7 @@ def _read_events(events_data, event_id, raw, ext):
 
     """
     if isinstance(events_data, str):
-        events = read_events(events_data).astype(int)
+        events = read_events(events_data, verbose=verbose).astype(int)
     elif isinstance(events_data, np.ndarray):
         if events_data.ndim != 2:
             raise ValueError('Events must have two dimensions, '
@@ -747,9 +749,11 @@ def _read_events(events_data, event_id, raw, ext):
                              'found %s' % events_data.shape[1])
         events = events_data
     elif 'stim' in raw:
-        events = find_events(raw, min_duration=0.001, initial_event=True)
+        events = find_events(raw, min_duration=0.001, initial_event=True,
+                             verbose=verbose)
     elif ext in ['.vhdr', '.set'] and check_version('mne', '0.18'):
-        events, event_id = events_from_annotations(raw, event_id)
+        events, event_id = events_from_annotations(raw, event_id,
+                                                   verbose=verbose)
     else:
         warn('No events found or provided. Please make sure to'
              ' set channel type using raw.set_channel_types'
diff --git a/mne_bids/write.py b/mne_bids/write.py
--- a/mne_bids/write.py
+++ b/mne_bids/write.py
@@ -1107,7 +1107,8 @@ def write_raw_bids(raw, bids_basename, bids_root, events_data=None,
                        'is not supported for kind "{}". '
                        'Skipping ...'.format(kind))
 
-    events, event_id = _read_events(events_data, event_id, raw, ext)
+    events, event_id = _read_events(events_data, event_id, raw, ext,
+                                    verbose=verbose)
     if events is not None and len(events) > 0 and not emptyroom:
         _events_tsv(events, raw, events_fname, event_id, overwrite, verbose)
 


Test patch: