BIDS-Aid
A toolkit for creating and managing BIDS-compliant fMRI datasets without original DICOMs. Intended for cases that require custom code and flexibility, such as when NIfTI source files lack consistent naming conventions, organized folder hierarchies, or sidecar metadata. Includes utilities for metadata reconstruction from NIfTI headers, file renaming, neurobehavioral log parsing (for E-Prime and Presentation), and JSON sidecar generation.
Installation
Standard Installation
pip install bidsaid[all]
Development Version
git clone --depth 1 https://github.com/donishadsmith/bidsaid/
cd bidsaid
pip install -e .[all]
Features
-
File renaming: Convert arbitrary filenames to BIDS-compliant naming
-
File creation: Generate
dataset_description.jsonandparticipants.tsv -
Metadata utilities: Extract header metadata (e.g., TR, orientation, scanner info) and generate slice timing for singleband and multiband acquisitions
-
Log parsing: Load Presentation (e.g.,
.log) and E-Prime 3 (e.g,.edat3,.txt) files as DataFrames, or use extractor classes to generate BIDS events for block and event designs:Class Software Design Description PresentationBlockExtractorPresentation Block Extracts block-level timing with mean RT and accuracy PresentationEventExtractorPresentation Event Extracts trial-level timing with individual responses EPrimeBlockExtractorE-Prime 3 Block Extracts block-level timing with mean RT and accuracy EPrimeEventExtractorE-Prime 3 Event Extracts trial-level timing with individual responses -
Auditing: Generate a table of showing the presence or abscence of certain files for each subject and session
-
QC: Creation and computation of certain quality control metrics (e.g., framewise displacement)
Quick Start
Creating BIDS-Compliant Filenames
from bidsaid.bids import create_bids_file
create_bids_file(
src_file="101_mprage.nii.gz",
subj_id="101",
ses_id="01",
desc="T1w",
dst_dir="/data/bids/sub-101/ses-01/anat",
)
Extracting Metadata from NIfTI Headers
from bidsaid.metadata import get_tr, create_slice_timing, get_image_orientation
tr = get_tr("sub-01_bold.nii.gz")
slice_timing = create_slice_timing(
"sub-01_bold.nii.gz",
slice_acquisition_method="interleaved",
multiband_factor=4,
)
orientation_map, orientation = get_image_orientation("sub-01_bold.nii.gz")
Loading Raw Log Files
from bidsaid.parsers import (
load_presentation_log,
load_eprime_log,
convert_edat3_to_txt,
)
presentation_df = load_presentation_log("sub-01_task.log", convert_to_seconds=["Time"])
# E-Prime 3: convert .edat3 to text first, or load .txt directly
eprime_txt_path = convert_edat3_to_txt("sub-01_task.edat3")
eprime_df = load_eprime_log(eprime_txt_path, convert_to_seconds=["Stimulus.OnsetTime"])
Creating BIDS Events from Presentation Logs
from bidsaid.bids import PresentationBlockExtractor
import pandas as pd
extractor = PresentationBlockExtractor(
"sub-01_task-faces.log",
trial_types=("Face", "Place"), # Can use regex ("Fa.*", "Pla.*")
scanner_event_type="Pulse",
scanner_trigger_code="99",
convert_to_seconds=["Time"],
rest_block_codes="crosshair",
rest_code_pattern="fixed",
split_cue_from_block=True,
)
events_df = pd.DataFrame(
{
"onset": extractor.extract_onsets(),
"duration": extractor.extract_durations(),
"trial_type": extractor.extract_trial_types(),
"mean_rt": extractor.extract_mean_reaction_times(),
}
)
Creating BIDS Events from E-Prime Logs
from bidsaid.bids import EPrimeEventExtractor
import pandas as pd
extractor = EPrimeEventExtractor(
"sub-01_task-gonogo.txt",
trial_types="Go|NoGo", # Can also use ("Go", "NoGo")
onset_column_name="Stimulus.OnsetTime",
procedure_column_name="Procedure",
trigger_column_name="ScannerTrigger.RTTime",
convert_to_seconds=[
"Stimulus.OnsetTime",
"Stimulus.OffsetTime",
"ScannerTrigger.RTTime",
],
)
events_df = pd.DataFrame(
{
"onset": extractor.extract_onsets(),
"duration": extractor.extract_durations(
offset_column_name="Stimulus.OffsetTime"
),
"trial_type": extractor.extract_trial_types(),
"reaction_time": extractor.extract_reaction_times(
reaction_time_column_name="Stimulus.RT"
),
}
)
Audit BIDS Dataset
from bidsaid.audit import BIDSAuditor
from bidsaid.simulate import simulate_bids_dataset
bids_root = simulate_bids_dataset()
auditor = BIDSAuditor(bids_root)
auditor.check_raw_nifti_availability()
auditor.check_raw_sidecar_availability()
auditor.check_events_availability()
auditor.check_preprocessed_nifti_availability()
analysis_dir = bids_root / "first_level"
analysis_sub_dir = analysis_dir / "sub-1" / "ses-1"
analysis_sub_dir.mkdir(parents=True, exist_ok=True)
with open(analysis_sub_dir / "sub-1_task-rest_desc-betas.nii.gz", "w") as f:
pass
auditor.check_first_level_availability(analysis_dir=analysis_dir, desc="betas")
Compute QC
from bidsaid.qc import create_censor_mask, compute_consecutive_censor_stats
censor_mask = create_censor_mask(
"confounds.tsv",
column_name="framewise_displacement",
threshold=0.5,
n_dummy_scans=4,
)
consecutive_censor_mean, consecutive_censor_std = compute_consecutive_censor_stats(
censor_mask, n_dummy_scans=4
)
See the API documentation for full parameter details and additional utilities.
Metadata
Release files for bidsaid 0.28.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bidsaid-0.28.0.tar.gz | 82.0 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| bidsaid-0.28.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| bidsaid-0.28.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| bidsaid-0.28.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| bidsaid-0.28.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 1.5 MB
Release files / bidsaid-0.28.0.tar.gz
| Download URL | bidsaid-0.28.0.tar.gz |
|---|---|
| Size | 82.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f25da604d7c50e511c24c16356d036a4b25211b4177e8fe8f66443869289036
|
|
BLAKE2b-256 checksum How to use checksums |
1bd3b51899715c2d261e8f9646247ff515bda6b54ed96239e5a6ad49bef506b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / bidsaid-0.28.0-cp310-abi3-win_amd64.whl
| Download URL | bidsaid-0.28.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 256.8 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e93a9718ce0fbaae8cd31a28e95829c2f46db53ae9971bf7f6157cb7ae63d2f9
|
|
BLAKE2b-256 checksum How to use checksums |
ad206516814fb762a8a2280d9e586369faf325caddaf96fba3ff3faed4ea3556
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / bidsaid-0.28.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | bidsaid-0.28.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 415.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0a9eedefcd0ddabba42bbb9602a831a1b192b28c57d13f3282a7cafed47de077
|
|
BLAKE2b-256 checksum How to use checksums |
3f5f0690b5ab4ca066f69cea127f48ca95754017917e5f92ed5e8ecca19d535b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / bidsaid-0.28.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | bidsaid-0.28.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 364.4 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f49b63ff8db41aad863857aa8bd1856d1a9aec6d7058d1141c609cec3d44376e
|
|
BLAKE2b-256 checksum How to use checksums |
2ecf83fc91aed4692d31c30a351a49ec01e620fa2c58ef7f03ac952325217330
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / bidsaid-0.28.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | bidsaid-0.28.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 367.1 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5cf6503c0574d72515e262e85d609f2e7b66479853d3630567c06ffffe4e4c08
|
|
BLAKE2b-256 checksum How to use checksums |
241a4846186d1747ee640f24fcf493ddd06ef2a0c496cbbc6a07085feb2920c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|