Skip to content

Instantly share code, notes, and snippets.

View rcassani's full-sized avatar
🦫

Raymundo Cassani rcassani

🦫
View GitHub Profile
@rcassani
rcassani / call_mini_epi_m.m
Created February 5, 2026 19:26
Brainstorm: Example on using Brainstorm from Python
% This Matlab script calls the "mini_epi.m" which is a Brainstorm pipeline
% Call is done unsing Matlab
%
% See also the equivalent Python script: "call_mini_epi_m.py"
%
% More details about "mini_epi.m" in the comments of that function
% Full paths
Brainstorm3Dir = '/home/rcassani/Desktop/brainstorm3';
TutorialDir = '/home/rcassani/Desktop';
@rcassani
rcassani / figure_popup_test.m
Last active February 6, 2026 16:52
Matlab Java JPopupMenu remains open in R2023b and newer when using New Desktop
% Create figure with mouse up callback
fig = figure('WindowButtonUpFcn', @FigureMouseUpCallback);
% Create popup menu on click place on right click
function FigureMouseUpCallback(hFig, ev)
import java.awt.MouseInfo.getPointerInfo
import javax.swing.JPopupMenu
import javax.swing.JMenuItem
if strcmpi(get(hFig, 'SelectionType'), 'alt')
@rcassani
rcassani / save_bst_cnx_coh.m
Created January 6, 2026 02:33
Save coherence spectra as .csv file. If time defined, one csv file per time sample
% 1. Load the contents of the coherence `.mat` file
TfMat = in_bst_timefreq('Subject01/Simulation/timefreq_connectn_cohere_260105_1544.mat');
% 2. Get the coherence spectra for each pair of signals: [nSignalA*nSignalB, nTime, nFreq]
R_3d = process_compress_sym('Expand', TfMat.TF, length(TfMat.RowNames));
[~, nTime, nFreq] = size(R_3d);
% Handle the case of one time sample
if nTime == 1 && length(TfMat.Time) == 2
TfMat.Time = mean(TfMat.Time);
end
@rcassani
rcassani / add_locs_cytoview24_for_bst.m
Created August 11, 2025 18:48
Brainstorm: Add locations to electrodes in Axion CYTOVIEW MEA 24
% Script to add locations to electrodes in Axion CYTOVIEW MEA 24 for Brainstorm
%
% Simone Doad, 2025
% Raymundo Cassani, 2025
%
% MEA channel names are composed of 4 characters that give the location information:
% 1st char: WellRow = 1st index in 4D array, 'A', 'B',... = 1, 2,...
% 2nd char: WellColumn = 2nd index in 4D array, '1', '2',... = 1, 2,...
% 3rd char: ElectrodeColumn = 3rd index in 4D array, '1', '2',... = 1, 2,...
% 4th char: ElectrodeRow = 4th index in 4D array, '1', '2',... = 1, 2,...
@rcassani
rcassani / test_bst_tf_2_data.m
Created June 6, 2025 10:51
Brainstorm: cast TF file to a Data file
% Brainstorm script
% Cast a TimeFrequency file to a Data recording
% TimeFreq file MUST have size [nChannels, nSamples, nFreqs] with nFreqs = 1
% This size can be obtained:
% - From a TimeFreq file with the process Extract > Extract values
% - Computing the TimeFreq file for only one frequency band
% Input TimeFreq file
timeFreqFile = 'Subject01/S01_AEF_20131218_01_600Hz_notch/timefreq_psd_231117_1140.mat';
@rcassani
rcassani / ica_var_explained.m
Created June 6, 2025 10:50
ICA, explained variance per IC
% ICA variance explained
%% Signals
% Sound
load chirp.mat
nSamples = length(y);
y = y';
% Create 10 signals
y_noise = 0.4 * randn([9, nSamples]);
F = [y; y_noise + repmat(y, 9, 1)];
@rcassani
rcassani / aggregate_volume_parcellations.m
Last active July 7, 2025 15:46
Brainstorm, aggregate volume values per anatomical parcellation
% Brainstorm script to obtain the mean value for a Volume (PET or Neuromap)
% for each of the parcellations in an anatomical parcellation (e.g. Desikan-Killiany)
%% PARAMETERS
% FileName for the Volume to use (Subject/VolFile)
volFileName = 'sub-MTL0002/subjectimage_sub-MTL0002_ses-01_trc-18Fflortaucipir_pet_spm_reslice_volpet.mat';
% Anatomical parcellation
volAtlasName = 'Desikan-Killiany';
%% COMPUTATION
@rcassani
rcassani / fooof_parameters_brainstorm.m
Created March 27, 2025 14:26
Understanding FOOOF parameters in Brainstorm
%% Understanding FOOOF parameters in Brainstorm, using one channel as example
% This is based on the files from the FOOOF tutorial
% https://neuroimage.usc.edu/brainstorm/Tutorials/Fooof
%
% Raymundo Cassani, 2025
%% FIND PSD AND FOOOF FILES
% Process: Select timefreq files in: Subject01/@rawS01_AEF_20131218_01_600Hz_notch
sFiles = bst_process('CallProcess', 'process_select_files_timefreq', [], [], ...
'subjectname', 'Subject01', ...
@rcassani
rcassani / example_sqlite_coalesce_bst_db.m
Created March 21, 2025 16:42
SQLite COALESCE in Brainstorm DB
%% SQLite queries to Brainstorm database can be faster by using JOIN on tables
% The existence of Raw and NoRaw Subjects complicates the JOIN as for
% NoRaw subjects it is needed to copy some fields from the DefaultAnatomy
% and this is done with the function COALESCE
% However, using COALESCE, we must write down all the fields, as '*' is not supported
%
% See examples below
%% Non-raw Subject
% Keep only SQLite fields
@rcassani
rcassani / project_eeg_sensors_on_scalp.m
Created November 14, 2024 20:56
Brainstorm: Project EEG sensors on scalp for registered EEG caps and default anatomies
% Script for Brainstorm
% For the provided anatomies ('testAnatomies'), find their already registered EEG caps
% and adjust the location of the EEG sensor if request (isReplaceLocs) and if
% one or more EEG sensors were moved more than ('distThreshold') millimeters
%
% Raymundo Cassani, 2024
%% ===== PARAMETERS =====
testAnatomies = {'Colin27_2016', 'ICBM152_2023b'};
isReplaceLocs = 1;