Quickstart
using UnfoldBIDS
using Unfold
using LazyArtifacts
using Main: @artifact_str # this is a workaround for Artifacts used in docs; locally you would `using LazyArtifacts`
Loading data
To load use UnfoldBIDS to find the paths to all subject specific data you can uye the bidsLayout function:
sample_data_path = artifact"sample_BIDS"
layout_df = bids_layout(sample_data_path, derivatives=false)
Row | subject | ses | task | run | file | events |
---|---|---|---|---|---|---|
Any | Any | Any | Any | Any | Any | |
1 | 001 | missing | P3 | missing | /home/runner/.julia/artifacts/6fa05e5d4476b16de1d27962bf672c119fa05c87/sample_ds/sub-001/eeg/sub-001_task-P3_eeg.set | sub-001_task-P3_events.tsv |
2 | 002 | missing | P3 | missing | /home/runner/.julia/artifacts/6fa05e5d4476b16de1d27962bf672c119fa05c87/sample_ds/sub-002/eeg/sub-002_task-P3_eeg.set | sub-002_task-P3_events.tsv |
3 | 003 | missing | P3 | missing | /home/runner/.julia/artifacts/6fa05e5d4476b16de1d27962bf672c119fa05c87/sample_ds/sub-003/eeg/sub-003_task-P3_eeg.set | sub-003_task-P3_events.tsv |
This will give you a DataFrame containing the paths too the eeg files of all subjects plus their accompanying event files
Since we set the derivative keyword to false here UnfoldBIDS will only look for the raw EEG files. However, by default UnfoldBIDS assumes you have preprocessed data in a derivatives folder and try to look for those.
Subsequently, you can load the data of all subjects into memory
data_df = load_bids_eeg_data(layout_df)
Row | subject | ses | task | run | raw | events |
---|---|---|---|---|---|---|
SubStrin… | Missing | SubStrin… | Missing | Py | DataFrame | |
1 | 001 | missing | P3 | missing | <RawEEGLAB | sub-001_task-P3_eeg.fdt, 33 x 478208 (467.0 s), ~41 kB, data not loaded> | 402×6 DataFrame |
2 | 002 | missing | P3 | missing | <RawEEGLAB | sub-002_task-P3_eeg.fdt, 33 x 414720 (405.0 s), ~41 kB, data not loaded> | 402×6 DataFrame |
3 | 003 | missing | P3 | missing | <RawEEGLAB | sub-003_task-P3_eeg.fdt, 33 x 386048 (377.0 s), ~41 kB, data not loaded> | 401×6 DataFrame |
At this point in time, the data is not yet actually loaded into memory, but uses MNE's lazy loading functionality.
As you can see, UnfoldBIDS trys to load events directly into the DataFrame, however if you are missing the event tsv files you will get a warning and no events are loaded. If that happens you have to manually load these events. The following function might help you with this. (The resulting dataframe still needs to be added to data_df!)
events_df = load_events(layout_df)
Run unfold type models
basisfunction = firbasis(τ=(-0.2,.8),sfreq=1024)
f = @formula 0~1
bfDict = ["stimulus"=>(f,basisfunction)]
UnfoldBIDS.rename_to_latency(data_df, :sample) # Unfold expects a :latency collumn in your events; if your event latency is named differently you can use this function as remedy
resultsAll = run_unfold(data_df, bfDict; eventcolumn="trial_type");
33.3%┣██████████████▍ ┫ 1/3 [00:00<Inf:Inf, InfGs/it]
Progress: 6%|██▌ | ETA: 0:00:12
Progress: 100%|█████████████████████████████████████████| Time: 0:00:01
66.7%┣███████████████████████████████▍ ┫ 2/3 [00:12<00:12, 12s/it]
Progress: 58%|███████████████████████▋ | ETA: 0:00:00
Progress: 100%|█████████████████████████████████████████| Time: 0:00:00
100.0%┣███████████████████████████████████████████████┫ 3/3 [00:12<00:00, 6s/it]
Progress: 67%|███████████████████████████▍ | ETA: 0:00:00
Progress: 100%|█████████████████████████████████████████| Time: 0:00:00
This page was generated using Literate.jl.