# Bug encountered when computing LCMV spatial filter with a Label

**URL:** <https://mne.discourse.group/t/bug-encountered-when-computing-lcmv-spatial-filter-with-a-label/6965>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization\
**Created:** [May 25, 2023, 5:03pm UTC](https://mne.discourse.group/t/bug-encountered-when-computing-lcmv-spatial-filter-with-a-label/6965 "2023-05-25T17:03:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgekenefati](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@georgekenefati](https://mne.discourse.group/u/georgekenefati)\
**Post date:** [May 25, 2023, 5:03pm UTC](https://mne.discourse.group/t/bug-encountered-when-computing-lcmv-spatial-filter-with-a-label/6965/1 "2023-05-25T17:03:25Z")

</div>

mne.beamformer.make\_lcmv works without any label chosen but crashes when a Label instance is chosen with the label= argument.

Please help! Thank you 🙂

**OS details:**

- MNE version: 1.3.0
- operating system: Ubuntu 20.04

**Code snippet:**

```python
one_label = mne.read_labels_from_annot(subject, regexp='rostralanteriorcingulate-lh', subjects_dir=subjects_dir)[0]
one_label

# LCMV
filters_tmp = make_lcmv(
info=raw.info,
forward=fwd_vol,
data_cov=data_cov,
reg=0.05,
noise_cov=noise_cov,
label=one_label,
pick_ori="max-power",
weight_norm="unit-noise-gain",
rank=None,
)
# You can save the filter for later use with:
# filters.save('filters-lcmv.h5')
stc_LCMV_tmp = apply_lcmv_raw(raw, filters_tmp)
stc_LCMV_tmp.save(save_dir+sub_dir_name+f"{selected_labels[i].name[:-3]}_LCMV",overwrite=True)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[17], line 5
      2 one_label
      4 # LCMV
----> 5 filters_tmp = make_lcmv(
      6 info=raw.info,
      7 forward=fwd_vol,
      8 data_cov=data_cov,
      9 reg=0.05,
     10 noise_cov=noise_cov,
     11 label=one_label,
     12 pick_ori="max-power",
     13 weight_norm="unit-noise-gain",
     14 rank=None,
     15 )
     16 # You can save the filter for later use with:
     17 # filters.save('filters-lcmv.h5')
     18 stc_LCMV_tmp = apply_lcmv_raw(raw, filters_tmp)

File <decorator-gen-484>:12, in make_lcmv(info, forward, data_cov, reg, noise_cov, label, pick_ori, rank, weight_norm, reduce_rank, depth, inversion, verbose)

File ~/anaconda3/envs/eegenv/lib/python3.9/site-packages/mne/beamformer/_lcmv.py:162, in make_lcmv(info, forward, data_cov, reg, noise_cov, label, pick_ori, rank, weight_norm, reduce_rank, depth, inversion, verbose)
    158 if inversion == 'single':
    159 depth['combine_xyz'] = False
    161 is_free_ori, info, proj, vertno, G, whitener, nn, orient_std = \
--> 162 _prepare_beamformer_input(
    163 info, forward, label, pick_ori, noise_cov=noise_cov, rank=rank,
    164 pca=False, **depth)
    165 ch_names = list(info['ch_names'])
    167 data_cov = pick_channels_cov(data_cov, include=ch_names)

File ~/anaconda3/envs/eegenv/lib/python3.9/site-packages/mne/beamformer/_compute_beamformer.py:54, in _prepare_beamformer_input(info, forward, label, pick_ori, noise_cov, rank, pca, loose, combine_xyz, exp, limit, allow_fixed_depth, limit_depth_chs)
     52 # Restrict forward solution to selected vertices
     53 if label is not None:
---> 54 _, src_sel = label_src_vertno_sel(label, forward['src'])
     55 forward = _restrict_forward_to_src_sel(forward, src_sel)
     57 if loose is None:

TypeError: cannot unpack non-iterable Exception object

```

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [May 25, 2023, 10:42pm UTC](https://mne.discourse.group/t/bug-encountered-when-computing-lcmv-spatial-filter-with-a-label/6965/2 "2023-05-25T22:42:34Z")

</div>

Could you use the MNE sample data and open an issue on the GitHub with a minimally reproducible example please?

Well probably actually `mne.read_labels_from_annot` results a list and so you just want the first element of that list `one_label[0]`. In general, a pro tip is to pay attention to the plurality as in read\_label **s** \_from\_annot which will tell you that it probably returns multiple things in a list and if you only want one thing, you need to grab the first element from that list.

---

<div class="post-metadata">

**Author:** ![georgekenefati](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@georgekenefati](https://mne.discourse.group/u/georgekenefati)\
**Post date:** [May 26, 2023, 7:38pm UTC](https://mne.discourse.group/t/bug-encountered-when-computing-lcmv-spatial-filter-with-a-label/6965/3 "2023-05-26T19:38:39Z")

</div>

Thanks for your response!

Calling `one_label` results in the following output  
`<Label | sample, 'rostralanteriorcingulate-lh', lh : 1864 vertices>`.

I believe this is the correct format for a single Label object.

I will go ahead and open the issue on GH.
