From a8485f8487301a0ae8973e7959814d4377a55de7 Mon Sep 17 00:00:00 2001 From: Chetan Gohil Date: Sun, 1 Sep 2024 01:46:12 +0100 Subject: [PATCH] Option to pass an mne object to voxel_timeseries. --- osl/source_recon/beamforming.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/osl/source_recon/beamforming.py b/osl/source_recon/beamforming.py index 2e2d2a1..2dcce35 100644 --- a/osl/source_recon/beamforming.py +++ b/osl/source_recon/beamforming.py @@ -1307,15 +1307,19 @@ def voxel_timeseries( Voxel coordinates in MNI space. """ - # Load sensor data - if "raw.fif" in preproc_file: - # Load preprocessed data - data = mne.io.read_raw_fif(preproc_file, preload=True) - elif "epo.fif" in preproc_file: - # Load epoched data - data = mne.read_epochs(preproc_file, preload=True) + if isinstance(preproc_file, str): + # Load sensor data + if "raw.fif" in preproc_file: + # Load preprocessed data + data = mne.io.read_raw_fif(preproc_file, preload=True) + elif "epo.fif" in preproc_file: + # Load epoched data + data = mne.read_epochs(preproc_file, preload=True) + else: + raise ValueError("fif file must end in 'raw.fif' or 'epo.fif'.") else: - raise ValueError("fif file must end in 'raw.fif' or 'epo.fif'.") + # Assume an mne Raw or Epochs object has been passed + data = preproc_file log_or_print(f"using chantypes: {chantypes}") if isinstance(chantypes, str): @@ -1332,10 +1336,10 @@ def voxel_timeseries( bf_data = apply_lcmv(data, filters, reject_by_annotation) # Transform to MNI space - if "epo.fif" in preproc_file: - bf_data = np.transpose([bf.data for bf in bf_data], axes=[1, 2, 0]) - else: + if isinstance(data, mne.io.Raw): bf_data = bf_data.data + else: + bf_data = np.transpose([bf.data for bf in bf_data], axes=[1, 2, 0]) voxel_timeseries, _, voxel_coords, _ = transform_recon_timeseries( subjects_dir=subjects_dir, subject=subject,