Utilities package

This package gathers different utility function.

Utilities modules

  • Atlas utilities: extract information from standard templates, electrode arrangement and so on.

  • BIDS: includes functions to manipulated filenames and directories in BIDS format.

  • Dataset: includes functions to cope with pymvpa dataset format.

  • Files: general filesystem operations.

  • Image: basic operations on nibabel images.

  • Math: math functions.

  • Matrix: matrix based operations.

  • Time: simple time utilities.

Module contents

sekupy.utils.enable_logging()[source]

Enable logging for sekupy with formatted output.

This function sets up logging for the sekupy package with a detailed formatter that includes file, line number, and function information for debugging purposes.

Returns:

Root logger instance configured for sekupy

Return type:

logging.Logger

sekupy.utils.get_id()[source]

Generate a unique identifier string.

This function creates a unique identifier by using the last 8 characters of a temporary directory name, with special characters replaced by ‘0’ to ensure compatibility.

Returns:

8-character unique identifier string

Return type:

str

sekupy.utils.load_test_dataset(task='fmri', n_subjects=1)[source]

Load a test dataset for development and testing purposes.

This function loads sample datasets included with sekupy for testing and development. It supports different neuroimaging modalities including fMRI and MEG data.

Parameters:
  • task (str, optional) – Type of data to load (‘fmri’, ‘meg’), by default ‘fmri’

  • n_subjects (int, optional) – Number of subjects to load, by default 1

Returns:

Loaded test dataset with preprocessing applied

Return type:

Dataset

sekupy.utils.make_dict_product(as_filter=True, **kwargs)[source]

Create a list of dictionaries from Cartesian product of parameters.

This function generates all possible combinations of parameters, useful for parameter grid search in neuroimaging analyses.

Parameters:
  • as_filter (bool, optional) – If True, wrap each parameter value in a list, by default True

  • **kwargs (dict) – Parameter names and their possible values

Returns:

List of dictionaries, each representing one parameter combination

Return type:

list

Examples

>>> make_dict_product(C=[1, 10], kernel=['linear', 'rbf'])
[{'C': [1], 'kernel': ['linear']}, {'C': [1], 'kernel': ['rbf']}, ...]
sekupy.utils.setup_analysis(path, analysis, participants_fname=None, **configuration)[source]

Set up analysis directory structure and configuration files.

This function creates the necessary directory structure and configuration files for a neuroimaging analysis following BIDS conventions.

Parameters:
  • path (str) – Base path where the analysis directory will be created

  • analysis (str) – Name of the analysis (used for directory and config file naming)

  • participants_fname (str, optional) – Name of the participants file, by default None (uses ‘participants.csv’)

  • **configuration (dict) – Additional configuration parameters to include in the config file

Returns:

Path to the created configuration file

Return type:

str