Skip to main content

Interactive N-dimensional numpy array viewer with FFT support

Project description

Python versions PyPI version License Downloads

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')

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).

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

Command Line

ndslice data.npy # Numpy file
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 (pixel array) .dcm pydicom

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

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 
pip install ndslice[video_export] # Include video export dependencies (imageio, Pillow, imageio-ffmpeg)
pip install ndslice[all] # includes all optional dependencies (video export and file formats)

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.8
  • NumPy >= 1.20.0
  • PyQtGraph >= 0.12.0
  • PyQt5 >= 5.15.0
  • h5py >= 3.0.0 (for HDF5 file support in CLI)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndslice-0.5.2.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ndslice-0.5.2-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file ndslice-0.5.2.tar.gz.

File metadata

  • Download URL: ndslice-0.5.2.tar.gz
  • Upload date:
  • Size: 39.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ndslice-0.5.2.tar.gz
Algorithm Hash digest
SHA256 e11515d2781c52561706420b31366305d435842e96a20139685458c7f0d39e2f
MD5 571323d67b848b8b7d0f96b6df36cf14
BLAKE2b-256 ed5837823685b72740b241588a9e4d14164cc0f356ca61c76366bfe9a8beaf8a

See more details on using hashes here.

File details

Details for the file ndslice-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: ndslice-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ndslice-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45dd7c189901f57bcf2a0e0e47a00e6fe107c1ca4baa11ed356a326ca6a3e2da
MD5 d88d9579030b397613b9cb910179f796
BLAKE2b-256 fbdb1a111e66ff862dcab39ae652ac66172f3bbf9dce748de28b05148b9e8d1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page