Skip to main content

Python versions PyPI version License Downloads SPEC 0 — Minimum Supported Dependencies

ndslice

Quick interactive visualization for N-dimensional NumPy arrays

A python package for browsing slices, applying FFTs, and inspecting data.

Quickly checking multi-dimensional data usually means writing the same matplotlib boilerplate over and over. This tool lets you just call ndslice(data) and interactively explore what you've got.

Usage

from ndslice import ndslice
import numpy as np

# Create some data
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
z = np.linspace(-5, 5, 50)
X, Y, Z = np.meshgrid(x, y, z, indexing='ij')
mag = np.exp(-(X**2 + Y**2 + Z**2) / 10)
pha = np.pi/4 * (X + Y + Z)
complex_data = mag * np.exp(1j * pha)

ndslice(complex_data, title='3D Complex Gaussian')
# Optional dimension labels:
ndslice(data, dim_labels=["X", "Y", "Z"])
# Optional label overlay:
ndslice(data, overlay=overlay_data)

Showcase

Features

Data slicing and dimension selection should be intuitive: click the two dimensions you want to show and slice using the spinboxes.

Centered FFT - Click dimension labels to apply centered 1D FFT transforms. Useful for checking k-space data in MRI reconstructions or analyzing frequency content. FFT

Line plot - See 1D slices through your data. Shift+scroll for Y zoom, Ctrl+scroll for X zoom:

Line plot

Video export Right-clicking a dimension button to export a video or PNG frames along that dimension. The video export functionality is optional, and can be installed with

pip install ndslice[video_export]

Export

Scaling

Log scaling is often good for k-space visualization. Symmetric log scaling is an extension of the log scale which supports negative values.

Colormap Change colormap:

Axis flipping Click arrow icons (⬇️/⬆️ and ⬅️/➡️) next to dimension labels to flip axes. Default orientation is image-style (origin lower-left). Flip the primary axis for matrix-style (origin upper-left).

Overlay Pass overlay= to overlay a label volume on the main image. An overlay may contain up to 255 distinct non-zero, non-negative integer labels. Sparse values are compacted internally for display while their original label values remain visible in pixel and overlay metadata. Label 0 is transparent, opacity is adjustable, and the small color swatch cycles between solid RGBCMY colors and a categorical rainbow palette for the labels present in the overlay.

Non-blocking windows

By default, windows open in separate processes, allowing multiple simultaneous views:

ndslice(data1)
ndslice(data2) # Both windows appear

Use block=True to wait for the window to close before continuing:

ndslice(data1, block=True)  # Script pauses here
ndslice(data2)  # Shown after first closes

If Qt is already initialized in the current process, ndslice(..., block=False) cannot safely fork a child process. In that case:

  • In IPython/Jupyter with %gui qt, ndslice opens inline in the current process (still non-blocking).
  • Without an active Qt event loop, ndslice falls back to blocking mode and emits a warning.

Command Line

ndslice data.npy # Numpy file
ndslice image.nii.gz
ndslice image.nii.gz --overlay overlay.nii.gz
ndslice image.dcm
ndslice some_dicom_dir/ # Automatically attemps to form an nd-array from DICOM the files
ndslice --help   # Show all options

File support ndslice has CLI support and can conveniently display:

Format File suffix Requirement
NumPy .npy, .npz NumPy
MATLAB .mat scipy
HDF5 .h5, .hdf5 h5py
BART .cfl + .hdr —
Philips REC .REC + .xml —
NIfTI .nii, .nii.gz nibabel
DICOM file .dcm pydicom
DICOM directory directory containing .dcm files pydicom, nibabel, dcm2niix on PATH

HDF5 files can be compound complex dtype, or real/imag fields.

For DICOM directories, ndslice does not infer series dimensions itself. It runs dcm2niix, then loads the produced NIfTI volume.

If there are multiple datasets in the file, a selection GUI appears which highlights arrays supported by ndslice (essentially numeric). Double click to open.

Selector

Installation

From PyPI

pip install ndslice
# Or, if you want just the package without pulling in dependencies:
pip install --no-deps ndslice

For DICOM directories you also need the external dcm2niix binary available on PATH. A practical install route is:

conda install -c conda-forge dcm2niix

If dcm2niix is missing or conversion fails, ndslice reports a clear error instead of trying to infer the series layout itself.

From source

git clone https://github.com/henricryden/ndslice.git
cd ndslice

# Use directly without installing
python -m ndslice data.npy

pip install -e .

Requirements

  • Python >= 3.12
  • NumPy >= 2.2.0
  • SciPy >= 1.15.0
  • PyQtGraph >= 0.14.0
  • PyQt6 >= 6.8.0
  • h5py >= 3.0.0
  • pydicom >= 2.4.0
  • nibabel >= 4.0.0
  • imageio >= 2.9.0
  • imageio-ffmpeg >= 0.4.2
  • Pillow >= 8.0.0

Python, NumPy, and SciPy minimum versions follow the rolling SPEC 0 support policy and are refreshed for new releases.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Built with PyQtGraph for high-performance visualization.


Henric Rydén

Karolinska University Hospital

Stockholm, Sweden

Metadata

Release files for ndslice 0.11.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 ndslice 0.11.0
File Size Uploaded Provenance Actions
ndslice-0.11.0.tar.gz 92.2 kB Without provenance Details for ndslice-0.11.0.tar.gz

Built distribution (wheel)

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

Total release size: 186.0 kB

Release files / ndslice-0.11.0.tar.gz

Download URL ndslice-0.11.0.tar.gz
Size 92.2 kB
Tags Source
SHA-256 checksum
How to use checksums
545bd29572e27769c01c897e33898e70d883a291e37c378726a46d817a268ae6
BLAKE2b-256 checksum
How to use checksums
2b6b6360a6e9a366cd35638317074240dbee95b2fb8e14d6b8a905a7a775cd8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / ndslice-0.11.0-py3-none-any.whl

Download URL ndslice-0.11.0-py3-none-any.whl
Size 93.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d10df166a4fb6342910a69351ef429f93d816251ea8d27a3e24cf90547a580bb
BLAKE2b-256 checksum
How to use checksums
3915bd81d517bec79c6a8e3446bf8bc802de60c88725e9196c1a7648fb529a7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for ndslice 0.11.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