Skip to main content

The Confidence Regions Toolbox

Table of Contents

Background

The crtoolbox is a Python-based software package designed to provide Confidence Regions (CRs) for excursion sets derived from neuroimaging data. At present, the methods provided are those proposed in Sommerfeld, et al. 2017, Bowring, et al. 2021 and Maullin-Sapey, et al. 2022. These methods provide CRs for 2D and 3D regression coefficient images, Cohen's d effect size images, and conjunction or disjunction images. For each approach, estimated inner and outer sets are constructed for an excursion set of interest. These estimated sets, together known as Confidence Regions, are designed to bound the true excursion set with a user-specified level of confidence.

Further detail on CRs, alongside an extensive demonstration of the crtoolbox, can be found in the crtoolbox_demo repository, which originally formed part of the Beyond Blobology course at the Organization for Human Brain Mapping conference 2023. Please Note: The function calls described in this practical have only been tested with the crtoolbox==0.1.6 version. Later versions may not be compatible.

Install

To install the crtoolbox please use pip:

pip install crtoolbox

Usage

At present the crtoolbox consists of several standalone functions, which may be used together to generate CRs. The most relevant of these are detailed below. Full docstrings for each function can be found in the files linked.

File Handling

The following functions can be used for file manipulation and handling:

  • read_image: This function may be used to read 2D or 3D images. Supported formats include; RGB images supported by the Image package, numpy data files and and NIfTI images.
  • addBlockToNifti: This function adds a block of voxels to a pre-existing NIFTI or creates a new NIFTI of specified dimensions if the file does not already exist.
  • remove_files: This function removes lists of files.

These functions may be found in crtoolbox.lib.fileio.

Effect Size images

The following functions can be used for regression and effect size estimation for either 2d or 3d images.

  • regression: This function can be used to perform a standard mass-univariate linear regression and obtain beta coefficient estimates ("raw" effect sizes). Please note that for large analyses, other packages may be more suitable (for instance...).
  • cohens: This function can be used to generate cohen's D images.

Please note that the residuals and standard deviation images output by regression and cohens are not the same; regression outputs regression residuals and the MLE for the standard deviation, whilst cohens outputs transformed residuals (generated according to method 2 of Bowring, et al. 2021) alongside their standard deviation.

These functions may be found in crtoolbox.lib.regression and crtoolbox.lib.cohens, respectively.

Generating CRs

The following function is used to generate confidence regions. It supports both 2d and 3d images.

  • generate_CRs: This function uses the outputs of regression, or cohens, to generate CRs for raw or standardized effect sizes, respectively.

This function may be found in crtoolbox.generate.

Coverage Assessment

The below function may be used to check whether the CRs correctly bound the underlying true excursion set (note this is only useful for simulation settings). It uses both a binary inclusion check and the interpolation methods outlines in Bowring, et al. 2019.

  • check_violations: Given a pair of CRs and a "true" excursion set, this function assesses whether the CRs correctly enclose the excursion set.

This function may be found in crtoolbox.coverage.

Working with Boundaries

The below function may be useful for developing the tool.

  • get_bdry_map_combined: This function produces an image of the boundary of an excursion set. Both 2D and 3D images are supported.

This function may be found in crtoolbox.lib.boundary.

Displaying Volumes

The below functions can be used to display various images in an interactive format.

display_volume, display_crs

  • display_volume: This function can be used to dispay individual 2D or 3D volumes. Masking is supported.
  • display_crs: This function can be used to dispay 2D or 3D CRs. Masking is supported.

These functions may be found in crtoolbox.lib.display.

Data Simulation

The crtoolbox currently contains custom code for generating simulated data which may be useful for testing and demonstration. The below sections provide detail on the available 2D and 3D simulated datasets respectively.

2D Data Simulation

The below classes can be used to generate 2D signals:

  • CircleSignal: This will create a circular signal with user specified radius, center, smoothness and peak magnitude.
  • SquareSignal: This will create a square signal with user specified radius, center, smoothness and peak magnitude.
  • RampSignal: This will create a linear ramp signal with user specified slope and value range.

The above classes will create objects representing each of the signal types. An image of the signal can be viewed using the plot method. Noise can also be generated using the Noise class.

  • Noise: This will create noise with user specified magnitude, smoothness and heterogeniety settings.

To use the above classes to generate data the generate_data_2D function can be used:

  • generate_data_2D: This will take in a signal object and a noise object and return the user's specified number of data instances.

The classes for signal generation and noise generation, as well as the generate_data_2D function, may be found in crtoolbox.tests.generate_2d_data.

3D Data Simulation

The below function can be used to generate 3D simulated data resembling real-world fMRI images.

  • generate_data: This will generate simualted 3D fMRI images according to a mass-univariate linear regression model, with fixed masking.

For further detail on the pipeline used to generate these images, see Maullin-Sapey & Nichols. 2022. The generate_data function may be found in crtoolbox.tests.generate_ni_data.

License

MIT

Metadata

Release files for crtoolbox 0.2.0

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

Source distribution (sdist)

Source distribution for crtoolbox 0.2.0
File Size Uploaded Provenance
crtoolbox-0.2.0.tar.gz 82.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 177.4 kB

Release files / crtoolbox-0.2.0.tar.gz

Download URL crtoolbox-0.2.0.tar.gz
Size 82.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0509b2c0e1c1e6b70fc8e4084e47930656f9a55304deb20ea1fa0226f8970815
BLAKE2b-256 checksum
How to use checksums
88e1abcc5087ea10ad4a064b6468c4b90fe7eb4c24b13e000642cab88ef1ace7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / crtoolbox-0.2.0-py3-none-any.whl

Download URL crtoolbox-0.2.0-py3-none-any.whl
Size 94.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1022900a4cd64079fcfeccff320c68931178510d194728c4532765748dbce8e1
BLAKE2b-256 checksum
How to use checksums
6b1c90a1f47ec4d51dfd477491b58288839f96547a3a4fab65f407aec711457d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for crtoolbox 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.

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.

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