spectralbrain.utils.helpers#
Miscellaneous utilities: timing, reproducibility, I/O helpers.
Small tools used across SpectralBrain that don’t belong in any specific subpackage.
Functions
|
List subject IDs in a BIDS directory. |
|
Create directory if it doesn't exist. |
|
Compute hash of a file. |
|
Glob for files in a directory. |
|
One-line summary of an array. |
Collect version info for reproducibility metadata. |
|
|
Extract BIDS entities from a filename. |
|
Pretty-print a dict with Rich (fallback to plain). |
|
Set random seeds for NumPy, Python, and optional frameworks. |
|
Context manager that logs elapsed time. |
Classes
|
Reusable timer with lap support. |
- class spectralbrain.utils.helpers.Timer[source]#
Bases:
objectReusable timer with lap support.
Examples
>>> t = Timer() >>> t.start() >>> process_a() >>> t.lap("step A") >>> process_b() >>> t.lap("step B") >>> t.report()
- spectralbrain.utils.helpers.collect_subjects(bids_dir, pattern='sub-*')[source]#
List subject IDs in a BIDS directory.
- spectralbrain.utils.helpers.ensure_dir(path)[source]#
Create directory if it doesn’t exist. Returns the Path.
- spectralbrain.utils.helpers.find_files(directory, pattern='*', recursive=True)[source]#
Glob for files in a directory.
- spectralbrain.utils.helpers.format_array_summary(arr, name='array')[source]#
One-line summary of an array.
- spectralbrain.utils.helpers.get_reproducibility_info()[source]#
Collect version info for reproducibility metadata.
- spectralbrain.utils.helpers.parse_bids_filename(filename)[source]#
Extract BIDS entities from a filename.
- spectralbrain.utils.helpers.print_dict(d, *, title=None, indent=2)[source]#
Pretty-print a dict with Rich (fallback to plain).
- spectralbrain.utils.helpers.seed_everything(seed=42)[source]#
Set random seeds for NumPy, Python, and optional frameworks.
- Parameters:
seed (int)
- Return type:
None