neurostats
Neuroimaging statistics for Python on a Rust core: threshold-free cluster enhancement
(TFCE) and TFCE permutation inference for a linear model fitted at every voxel
(tfce_ols, which includes the one-sample test), over masked brain volumes or arbitrary
graphs. It is licensed LGPL-3.0-or-later. The "mne" weighting reproduces MNE-Python
1.12.1 TFCE goldens to a relative tolerance of 1e-12, and the "nilearn" preset
reproduces nilearn 0.14.1 calculate_tfce to the same tolerance on random maps and
masks. Under that preset tfce_ols reproduces the t map and the TFCE map of nilearn
permuted_ols to a relative tolerance of 1e-10.
Install
pip install neurostats
The only runtime dependency is numpy. nilearn is not needed to import or use the package; its maskers and images are taken as they are when you have them.
Documentation
- API guide — every function, parameter, default, and return field.
- neurostats and nilearn —
maskers and images in, images out (
import_from,export_to), what the"nilearn"preset reproduces, andtfce_olsnext topermuted_ols.
Quick start
Enhance a single statistic image, keeping its 3-D shape with zeros outside the mask:
import nibabel as nib, numpy as np, neurostats as ns
from nilearn.image import new_img_like
img, mask_img = nib.load("tstat1.nii.gz"), nib.load("mask.nii.gz")
mask = np.asarray(mask_img.dataobj) > 0
dom = ns.Domain.from_mask(mask, conn=6)
t = np.nan_to_num(np.asarray(img.dataobj, dtype=np.float64))
enh = ns.tfce(t, dom, params="exact", tail="two_sided")
nib.save(new_img_like(img, enh), "tstat1_tfce.nii.gz")
Permutation inference across subjects, with family-wise error correction. A fitted nilearn masker and the subjects' images go in, and the maps come back as images:
from nilearn.maskers import NiftiMasker
masker = NiftiMasker(mask_img="mask.nii.gz").fit()
d = ns.import_from(subject_files, masker) # mask once
# brain ~ age + sex + tiv + intercept, t of age at every voxel
r = ns.tfce_ols(d, tested=age, confounds=np.column_stack([sex, tiv]), n_perm=5000)
ns.export_to(r)["logp_fwe"].to_filename("age_logp_fwe.nii.gz")
# brain ~ intercept: the one-sample test
one = ns.tfce_ols(d, tested="intercept", n_perm=5000)
ns.tfce_ols(subject_files, masker, ...) masks in the same call. Plain arrays work
too: data is then (n_subjects, n_voxels) and space a Domain. Such a result has no
masker to go back through, so the export names one: ns.export_to(r, target=masker).
A result can be saved, loaded, and continued with more draws:
r.save("age.npz")
r = ns.TfceInference.load("age.npz")
r = ns.tfce_ols(d, tested=age, confounds=np.column_stack([sex, tiv]),
n_perm=20000, extend=r) # runs draws 5000 .. 19999 only
Conventions
| Concept | Values | Notes |
|---|---|---|
params |
"exact" (default), "nilearn", or a dict |
A dict has the key weighting and any of e, h, start, step. e and h default to 0.5 and 2.0 |
weighting |
exact, nilearn, mne, smith_nichols, fslmaths |
exact is the closed-form integral from start (default 0) and takes no step; nilearn is 100 equal steps up to the map's maximum with weight h**H and takes neither start nor step; mne = |Δh|**H (MNE-Python), smith_nichols = h**H * step (FSL/PALM/SPM) and fslmaths = h**H need both start and step. fslmaths is for tfce only |
tail |
positive, negative, two_sided (default) |
negative enhances -stat; two_sided is signed, the positive enhancement minus the negative one, and its tested quantity is the absolute value |
conn |
6 (default), 18, 26 |
voxel connectivity of Domain.from_mask and Domain.from_volume, and of the Domain that import_from and tfce_ols build from a masker or a mask image (conn=None there is 6) |
tested (tfce_ols) |
a 1-D array, or "intercept" |
required keyword. An array tests that regressor with an intercept in the model; "intercept" tests the intercept (the one-sample test when there are no confounds). A row whose tested or confound value is NaN is left out, with a warning |
seed (tfce_ols) |
None (default), or an integer in [0, 2**64) |
None draws a fresh seed, which the result stores |
n_perm (tfce_ols) |
default 10000 |
the draw budget, the unpermuted data included. p_fwe and p_unc are never below 1 / n_perm |
n_jobs (tfce_ols) |
1 (default), -1, or a positive integer |
-1 uses every core, k uses exactly k OS threads, 0 or any other negative value raises ValueError. Results are bit-identical for every n_jobs |
Domains
Domain.from_mask(mask, conn=6)— adjacency over the in-mask voxels of a 3-D volume; astatmap may be passed either as a node vector or in the mask's 3-D shape.Domain.from_volume(shape, conn=6)— adjacency over every voxel of a 3-D volume (no mask).Domain.from_adjacency(adj, n=None)— any object with.tocoo()(e.g. a scipy sparse matrix); symmetrised, self-loops dropped, duplicate edges merged.shapeandmaskareNone, so only the 1-D node-vector form oftfceapplies.Domain.from_csr(indptr, indices)— caller-built CSR adjacency; symmetry is the caller's precondition.shapeandmaskareNone, so only the 1-D node-vector form applies.
Node order for a mask-built Domain is C-order over the mask (numpy ravel order), so
stat[mask] is already in node order, and so are the columns a nilearn NiftiMasker
returns.
Not included
Reading and writing image files (nilearn and nibabel do that), surface maskers and surface images, more than one tested regressor per call, cluster size and cluster mass inference, and GLM families other than the linear model.
Build from source
pip install maturin
maturin develop
Paweł Lenartowicz — Freestyler Scientist · GitHub · ORCID
Metadata
Release files for neurostats 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| neurostats-0.2.0.tar.gz | 1.6 MB | With provenance | Details for neurostats-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| neurostats-0.2.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for neurostats-0.2.0-cp311-abi3-win_amd64.whl |
| neurostats-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for neurostats-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| neurostats-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for neurostats-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| neurostats-0.2.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for neurostats-0.2.0-cp311-abi3-macosx_11_0_arm64.whl |
| neurostats-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for neurostats-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 3.8 MB
Release files / neurostats-0.2.0.tar.gz
| Download URL | neurostats-0.2.0.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88f8666f70387682ea9ba547101db37000edca5b0e94a4c1efb86bcce442b2fd
|
|
BLAKE2b-256 checksum How to use checksums |
f9b2d07a4ab10b153856fa69f05cc8994fa332429c5af094fdd6a1a7418bf914
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / neurostats-0.2.0-cp311-abi3-win_amd64.whl
| Download URL | neurostats-0.2.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 308.2 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
63f052d1da640a11c58890177c4cb33d9d36e7c6fd5c716f140f84b2a203f887
|
|
BLAKE2b-256 checksum How to use checksums |
ff378f64fc4436427229b4f95bdfddaa8b978e456c0af7cb29ea276ed73ded38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / neurostats-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | neurostats-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 488.6 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
15bb1badc39a839dc8f07ea3b02d38b508720ddde04b8d1552aed449e155162e
|
|
BLAKE2b-256 checksum How to use checksums |
69ef837cd73b7566eb1121474a2dd0e62b68534cddab1454e4032d92a40e22d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / neurostats-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | neurostats-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 472.8 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
46d4dd291ed3d49792dfce0abd5b3da7aa89b1e712ee1bf17695b18be8610316
|
|
BLAKE2b-256 checksum How to use checksums |
89af644da9cff648408fe91efa0b36f3219f57a0c8d358ec2a9d3a882e7a181b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / neurostats-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | neurostats-0.2.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 429.2 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
73beb7285a11df847406c1ac9b94562b917f45326d122a2ab2cb5748f81f775c
|
|
BLAKE2b-256 checksum How to use checksums |
04f870b0fbda93d7f58fb498bb2d0271c15682db1abce6a8612267b10de7e1bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / neurostats-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | neurostats-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 429.1 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
17ee5fca05fc6b5fbe9e211e27d9585859ec420f330ac9217bed677f9ba2190b
|
|
BLAKE2b-256 checksum How to use checksums |
76268e2369a859173a6a186bdb0d2cc799499890442cc68212d850f56a3a39e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for neurostats 0.2.0
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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for neurostats-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA 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.