Simple pure-python module for reading and writing nrrd files.
Clone or download
ihnorton and addisonElliott Fix key-value writing: no space after ':=' identifier (#69)
per the NRRD documentation: http://teem.sourceforge.net/nrrd/format.html#general.2

"""
Each of the "<key>:=<value>" lines specifies a key/value pair in the nrrd. These can appear in NRRD0002 (and higher version) files, but not NRRD0001 files. The key and value strings are delimited by the first ":=" to appear on the line: any spaces before or after ":=" are assumed part of the key or value, respectively.
"""
Latest commit eeb4df8 Sep 23, 2018

README.rst

Build Status DOI Python version PyPi version Documentation Status

pynrrd

pynrrd is a pure-Python module for reading and writing NRRD files into and from numpy arrays.

Dependencies

The module's only dependency is numpy.

Installation

Install via pip and PyPi repository (recommended)

pip install pynrrd

Install via pip and GitHub

pip install git+https://github.com/mhe/pynrrd.git

Install from source (recommended for contributing to pynrrd)

For developers that want to contribute to pynrrd, you can clone the pynrrd repository and install it using the following commands:

git clone https://github.com/mhe/pynrrd.git
cd pynrrd
pip install .

or, for the last line, instead use:

pip install -e .

to install in 'develop' or 'editable' mode, where changes can be made to the local working code and Python will use the updated pynrrd code.

Example usage

import numpy as np
import nrrd

# Some sample numpy data
data = np.zeros((5,4,3,2))
filename = 'testdata.nrrd'

# Write to a NRRD file
nrrd.write(filename, data)

# Read the data back from file
readdata, header = nrrd.read(filename)
print(readdata.shape)
print(header)

Tests

Run the following command in the base directory to run the tests:

python -m unittest discover -v nrrd/tests

Next Steps

For more information, see the documentation.

License

See the LICENSE for more information.