Skip to main content

PySearchLight - A simple and customizable implementation of searchlight analysis 🔍

This package provides an easy-to-use implementation of the searchlight analysis by Kriegeskorte et al. (2006). In this analysis method, a spherical "searchlight" is moved across a 4D array (typically brain data) and a user-defined function is applied to the data within the searchlight. This allows for the computation of a measure of interest (e.g., classification accuracy) at each voxel location, based on the data within the sphere centered at that voxel.

Installation

You can install PySearchLight with pip:

pip install pysearchlight

Usage

PySearchlight takes care of moving the sphere across the data and applying the user-defined function to the data within the sphere. The user only needs to provide the data, the function to apply within the searchlight, and the radius of the searchlight sphere. The function should take a single argument, which is the data within the sphere centered at a voxel location. The function can also take additional arguments, which can be passed using functools.partial.

Here is a simple example of how to use PySearchLight to train and evaluate classifier on data within a searchlight:

import numpy as np
from pysearchlight import SearchLight

from sklearn.model_selection import cross_val_score
from sklearn.svm import SVC
from functools import partial

# Create some example data
data = np.random.rand(10, 10, 10, 100)

# Create a binary mask
mask = np.random.randint(0, 2, (10, 10, 10)) 

# Define a function to train a classifier on the data within a searchlight sphere
def train_classifier(data, labels):
    clf = SVC()
    scores = cross_val_score(clf, data, labels)
    return scores.mean()

# Because the searchlight function should only take one argument (the data in the sphere centered 
# at a voxel location), we use partial to pass the labels:
train_classifier_partial = partial(train_classifier, labels=np.random.randint(0, 2, 100))

# Create a SearchLight object
sl = SearchLight(
    data=data, # The 4D data array 
    sl_fn=train_classifier_partial, # The function to apply within the searchlight
    radius=2, # The radius of the searchlight sphere (in voxels)
    mask=mask, # A binary mask indicating which voxels to include in the searchlight
)

# Run the searchlight analysis (this will return a 3D array of results)
results = sl.fit(
    n_jobs=1, # The number of jobs to run in parallel
    n_chunks=10, # The number of chunks to split the data into (to reduce memory usage)
    verbose=1, # Verbosity level
)

Metadata

Release files for pysearchlight 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysearchlight 1.0.1
File Size Uploaded Provenance Actions
pysearchlight-1.0.1.tar.gz 5.3 kB Without provenance Details for pysearchlight-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysearchlight 1.0.1
File Interpreter ABI Platform Actions
pysearchlight-1.0.1-py3-none-any.whl Python 3 none any Details for pysearchlight-1.0.1-py3-none-any.whl

Total release size: 10.8 kB

Release files / pysearchlight-1.0.1.tar.gz

Download URL pysearchlight-1.0.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
39085bb414c471f2029bcc2516df80a64d4cc2a8af0f2aad3a1dae085fd106b5
BLAKE2b-256 checksum
How to use checksums
1ac328f3634c3a772e0d1874ee40d8614a9d747a5e0a114585165a45511f7719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Release files / pysearchlight-1.0.1-py3-none-any.whl

Download URL pysearchlight-1.0.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ae42f2001703e0cf721d9ef7efec31b757884a2c87f949079510aca1d25bb49
BLAKE2b-256 checksum
How to use checksums
f58bd2c8b24367eee452e734aebc6ec6c9e6be0e21696a2bcb67e7625759b633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Security for pysearchlight 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page