osl icon indicating copy to clipboard operation
osl copied to clipboard

Can have too big rank when beamforming

Open YonatanGideoni opened this issue 8 months ago • 1 comments

Summary: When beamforming, eg. when using beamform_and_parcellate, the given rank can be larger than the covariance matrix' dimensions.

Versions: Ubuntu 20.04 OSL version: 0.6

Expected behaviour: Use covariance mat's rank if given one is too big - this is likely due to numerical issues.

Example logs:

sub-01_ses-1_task-3_meg_preproc_raw : *********************************
sub-01_ses-1_task-3_meg_preproc_raw : * SOURCE RECONSTRUCTION FAILED! *
sub-01_ses-1_task-3_meg_preproc_raw : *********************************
sub-01_ses-1_task-3_meg_preproc_raw : beamform_and_parcellate : <function beamform_and_parcellate at 0x7f76ac9a4f70>
sub-01_ses-1_task-3_meg_preproc_raw : <class 'ValueError'>
sub-01_ses-1_task-3_meg_preproc_raw : Invalid value for the rank parameter (263) given the shape of the input matrix (208 x 208).
  File "/auto/path/code/osl/osl/source_recon/batch.py", line 183, in run_src_chain
    func(src_dir, subject, preproc_file, smri_file, epoch_file, **userargs)
  File "/auto/path/code/osl/osl/source_recon/wrappers.py", line 737, in beamform_and_parcellate
    filters = beamforming.make_lcmv(
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 177, in make_lcmv
    filters = _make_lcmv(
  File "<decorator-gen-603>", line 12, in _make_lcmv
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 735, in _make_lcmv
    W, max_power_ori = _compute_beamformer(
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 843, in _compute_beamformer
    Cm_inv, loading_factor, rank = _reg_pinv(Cm, reg, rank)
  File "path/.conda/envs/pnpl/lib/python3.10/site-packages/mne/utils/numerics.py", line 172, in _reg_pinv
    raise ValueError('Invalid value for the rank parameter (%d) given '

Possible fixes: rank = min(rank, Cm.shape[0])

YonatanGideoni avatar Jun 19 '24 11:06 YonatanGideoni